Caliburn Micro Wpf rolebased security.

Topics: Actions & Coroutines, Bugs, Getting Started
Jan 18, 2012 at 11:27 PM
Edited Jan 18, 2012 at 11:33 PM
I have encountered a problem trying to implement rolebased security for a WPF application.
Tough out my GUI i have several buttons that i wish to disable based on the user acceslevel/role.
So far i had no problem, and all controls updates as intended according to acces, when the user puts in his information and request a login tough the gui.
Now my problem is that i need to add a default login or autologin that sets a default role when no user is logged. here is a short code examble
public LoginViewModel()
	// Setup Here.


public void SetRole()
		// create the generic identity GenericIdentity
	Identity = new GenericIdentity("Administrator");

	// define the roles to associate with the generic principal
	string[] Roles = new string[2] { "Manager", "Architect" };

	// create the generic principal
	GenericPrincipal MyPrincipal = new GenericPrincipal(Identity,Roles);

	// bind the generic principal to the thread
	Thread.CurrentPrincipal = MyPrincipal;	
	NotifyOnPropertyChange(() => CanExecute)

Public Bool CanExecute
			// Create a Principal to check for permission. 
			IPrincipal myprincipal = new principal( Administrator, Architect);
			// Deman acces, will throw security exception if fail. 
			return true.		
			return false
<Button x:Name="SetRole" /> 
<Button x:Name ="ActiveItem" IsEnabled="{binding CanExecute}" />
My problem is, When i use login, or call SetRole as a action related to a button everything works fine. 
but if i place the call in the constructor or try calling it any other way then by a userinput the Demand() will fail every time.
Im fairly new to caliburn, but this is the only time i have encountered this, and i dont know what to do.
Jan 19, 2012 at 4:17 AM

Hmm. I haven't used this type of security model in a long time, so I'm no expert. Would it be possible for you to create a simple reproduction of the issue in a small solution? If you can do that and send it to me or create a ticket and upload it as an attachment, I can take a look at it and see if it has anything to do with Caliburn.Micro or not.