justin.fisher:
What I'm finding in CSLA is that authorization is associated with a class of objects and not an instance of an object. Authorization has turned out to be the most difficult part of a new system I am implementing. Compounding the difficulty is the fact that there is very little guidance out there that goes beyond securing access to an entire table or class of objects with role assignments.
CSLA .NET 3.5 supports two types of authorization
- Class level
- Property level
The Class level authorization is not per-instance, because it is at the class level. It is intended to allow the UI developer to enable/disable various UI elements based on the type of class that would be affected. Can the user create objects of type X? Edit them? Etc? These rules are available to the UI developer, and are used by the data portal.
The Property level authorization is either per-type or per-instance, though per-type is much faster and requires less memory - obviously the per-instance implementation means rules are stored and checked on a per-instance basis which requires more resources. Property level authorization is intended to allow the UI developer to enable/disable various UI elements based on whether the user is allowed to read or write to specific properties.
There's similar Method level authorization (CanExecuteMethod()) that works the same as the Property level authorization.
The Property level authorization is documented in the CSLA .NET Version 2.1 Handbook. Unfortunately the Class level authorization is new to CSLA 3.5 and so there's no documentation yet.
It sounds like you want to create an instance of an object and then decide whether the user is allowed to perform coarse-grained operations like insert/update/delete (obviously they were already able to do a create/fetch or you wouldn't have an instance).
You can do this by overriding Save() and checking the rules there, preventing the operation if it isn't legal by throwing a SecurityException.
If you want the UI to have access to this information as well, I'd recommend overriding IsSavable. IsSavable already checks the Class level authorization rules, but you could easily check your instance level rules first and only delegate to the base implementation if your rules pass. This way your UI code can always use this interface to find out if an object can be saved by using the standard IsSavable property (which is automatically handled for you by the CslaDataProvider in WPF for instance).
Rocky