CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

How to check Authorization Rules across objects?

rated by 0 users
Answered (Verified) This post has 1 verified answer | 2 Replies | 2 Followers

Top 500 Contributor
17 Posts
CrikeyMoses posted on Thu, Mar 29 2012 7:11 AM

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:
Csla.ApplicationContext.User.IsInRole("CashView")
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

Answered (Verified) Verified Answer

Top 10 Contributor
9,270 Posts
Verified by CrikeyMoses

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.

Rocky

All Replies

Top 10 Contributor
9,270 Posts
Verified by CrikeyMoses

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.

Rocky

Top 500 Contributor
17 Posts

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

Thanks mate.

Page 1 of 1 (3 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems