get Rules for Each Role [RESOLVED]

Topics: Security Application Block
Aug 25, 2010 at 3:18 AM

hi everyone..

is there a way that we can get all Rules in App.config for each Role?

right now we must use Authorize method in RuleProvider and it only accept single Rule at a time

i need to do this so i can display all Rule for specific Role so user can checked / unchecked them

any insight?

thanks,

erick

 

Aug 25, 2010 at 5:08 AM

There's no direct way to enumerate the roles but you can retrieve all the rules for each authorization provider:

IConfigurationSource configSource = ConfigurationSourceFactory.Create();
SecuritySettings settings = (SecuritySettings)configSource.GetSection(SecuritySettings.SectionName);
foreach (var provider in settings.AuthorizationProviders)
{
            AuthorizationRuleProviderData ruleProvider = (AuthorizationRuleProviderData)provider;
            if (ruleProvider != null)
                {
                 foreach (var rule in ruleProvider.Rules)
                 {
                    //get the role from rule.Expression
                 }
            }
}

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Aug 25, 2010 at 7:24 AM

thx for the reply Sarah

ok i can populate all Rules now..can continue from here now..

 

thx again :D

Aug 25, 2010 at 7:40 AM

sorry for late response..

is there a way to write/rewrite the Rule without using Entlib Config.NET application?

Aug 25, 2010 at 7:43 AM

You mean modify the rule expression during runtime?  What do you mean EntLib Config.NET application?

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 25, 2010 at 7:50 AM

You mean modify the rule expression during runtime?  -> yes..

my intention is to display all Rules i have to Admin User with check box wether the user Authorized for that Rule or not..

so the Admin User can update the Rule for certain Role

i hope it make sense

 

What do you mean EntLib Config.NET application? -> it's the one that used to edit all Enterprise Library Block (Enterprise Library V5 Configuration Console)

Aug 25, 2010 at 8:26 AM

I see.  EntLib 5.0 has a new feature called Fluent Configuration API which you can use.

However, the UpdateConfigurationWithReplace method of the ConfigurationSourceBuilder class will replace the entire section which you configured.  For example, in the sample code here for configuring the security block,  if your original config contains 5 Authorization Providers, the call to builder.UpdateConfiguratioinWithReplace will replace the entire securityConfiguration section and thus will only contain 1 Authorization Rule Provider named "MyRules".  

Thus, your way around this would be to recreate the config with every change the user makes.  Even if he is only modifying an expression, your fluent configuration code will reconfigure the entire security configuration.

Let me know if anything is unclear.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

Aug 26, 2010 at 1:44 AM

sorry again for late reply...

ok, i'll try and inform back what i got :D

 

thx again Sarah

Aug 26, 2010 at 2:16 AM

not a wise option to use Fluent Configuration API :D, troublesome 

i will find other way :D

 

thx again Sarah