I am working on a Winforms project (.NET 4), which is based on MVVM freely. For security, the application authenticates itself in Active Directory, and then uses role-based security to determine access rights to various parts of the program. In most cases, security is implemented using the PrincipalPermissionAttribute principle:
<PrincipalPermissionAttribute(SecurityAction.Demand, Role:="Managers")> _ Public Sub Save() Implements IProductsViewModel.Save mUOW.Commit() End Sub
As you can probably tell from the interface implementation, this particular Sub is in the ViewModel. The PrincipalPermissionAttribute function checks whether the current user (Thread.CurrentPrincipal) is in the Manager role.
Which leads to my question: should security checks (e.g. above) be performed in the domain model?
I have two conflicting opinions when I think about it myself:
1) Do not let the domain model ignore as many problems as you can reduce complexity and dependency. (Keep safe, possibly implemented in ViewModel).
2) The domain model is, in a way, a place where "the dollar stops here." If I implement security in a domain model, then I know that even if security in another slot fails, the domain model must catch it.
So what can I say, security in the domain model or not?
source share