To secure an application, you should start with securing your domain model. An application that simply hides stuff on the UI based on the user's permissions is not a secure application if the data model is left wide open. This is called security through obscurity. True security starts at the server and the domain model. DevForce has a flexible authorization model to secure your back-end. See the following link as a start.
Once your domain model is properly secured, you automatically get error messages if a user tries to do something that they don't have permission to. If you look at the latest TempHire code you see the beginnings of how to secure a data model. In TempHire you have to to be an authenticated user before you can save or query. This is accomplished through the RequiresAuthenticationAttribute on EntityBase, from which each entity in the domain model extends. It doesn't do anything with roles or specific permissions yet.
[ProvideEntityAspect]
[DataContract(IsReference = true)]
[RequiresAuthentication]
public abstract class EntityBase
{
private EntityFacts _entityFacts;
[NotMapped]
public EntityFacts EntityFacts
{
get { return _entityFacts ?? (_entityFacts = new EntityFacts(this)); }
}
[DataMember]
[ConcurrencyCheck]
[ConcurrencyStrategy(ConcurrencyStrategy.AutoIncrement)]
public int RowVersion { get; internal set; }
public virtual void Validate(VerifierResultCollection validationErrors)
{
}
}
Once you have your domain model secured, the rest is cosmetics on the UI. Disabling buttons if the user doesn't have permission can easily be done by adding corresponding CanXXX properties for your actions in the VM so that the buttons are disabled or you can bind the visibility attribute so that the controls are not visible if the user doesn't have permission.
Edited by mgood - 08-May-2012 at 4:58pm