How to check Authorization Rules across objects?

How to check Authorization Rules across objects?

Old forum URL:

CrikeyMoses posted on Thursday, March 29, 2012

Hi we are using CSLA 4.2 for Silverlight,

We have a tab control with tabs for various objects. So lets say the first Tab is "Employee", which displays general information about an "Employee" (object), the second tab is "Cash" (object).

So we have an Authorization Rule that checks if you can "Get" the Cash object applied like this
BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(AuthorizationActions.GetObject, new List<string> { "CashView" }));

I want to hide the Cash tab if your Authorization rules don't allow you to see it, but unfortunately when you first come into the Employee tab, the Cash object has not yet been created, thus that rules have not yet been applied. I check the rule as follows:
Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.GetObject, typeof(Cash))
How is it possible for me to check the rule on another object before that object has been initialized?

I can check to see if the current user IsInRole like this:
I just dont think this is the way to go... 

Hopefully someone understands what i'm trying to do here... Any help will be appreciated, thanks in advance

RockfordLhotka replied on Thursday, March 29, 2012

The per-type rules (like GetObject) don't need an object instance because they are static.

Notice that Csla.Rules.BusinessRules.HasPermission accepts a typeof() parameter - not an object instance, just an object type.

Also notice that the method that establishes per-type rules in your business class is static. That method is invoked automatically by the business rules engine if the rules for the type aren't already known.

CrikeyMoses replied on Friday, March 30, 2012

Ahhh, i missed the "Using AddObjectAuthorizationRules" chapter in CSLA 4.2 Object e-book.

Thanks mate.

Copyright (c) Marimer LLC