jeffreygg wrote:
Omar, as it seems that the CanRead and CanWrite methods are orthogonal to the logic within the methods (properties), I think AOP is well applied here, if you're willing to deal with the complexity.
I agree with u that the CanRead/CanWrite method calls seem immaterial to the properties' logic. But I tried to shoe-horn the reasoning by looking at authorization security as just another kind of business rules.
My pick on using attributes is that I have to build an AOP based framework and force all property access through this layer of reflection. Although the performance penalty might be acceptable (as all reflection code is done at the UI) but the code becomes un-natural because everything has to be routed through this accessability layer.
Another architecture I have been banging in my head for the last two days is one modeled after LLBL's validation. LLBL's documentation categories validation into 3 types; Field, Entity and multiEntity. It seemed that Authorization can also be categoriezed into the same 3 categories. Where applying the latter two seems natural at the BL layer, the problem arizes in implementing the field security.
Steeling a page from LLBL's design, I thought of doing the following:
1- Define IAuthorizer/AuthorizerBase classes that exposes OnBeforePropertySet/OnBeforePropertyGet/OnBeforeSave/OnBeforeDelete
2- Add an (Authorizer) property to each entity (by using the CommonBaseClass template)
3- Extend the adapter class in my BL to override the Save/Delete entities actions and inspect if the entity in question has an IAuthorizer property and accordingly call its appropiate Onxx method.
This architecure can also be applied for Auditing where an entity can have an Auditor property.
The real problem with this architecture is the place to house the IAuthorizer/AuthorizerBase classes which I only found 2 possibilities:
1- the LLBL's DLL which is something I always make a point to avoid
2- If I Extend each DAL entity class in the BL class, I can add the Authorizer property in each entity and then define the IAuthorizer/AuthorizerBase classes in the BL itself.
I find extending 100 entities in the BL is an over-kill and hoping to find a better approach.
I see this architecture (modeled after LLBL's validation) as felxible and natural. I just wish I can resolve the issue of where to find a home for the IAuthorizer/AuthorizerBase classes in a pracical way.