Delete role for rules

Topics: Security Application Block
Aug 11, 2011 at 5:40 PM

Hi all

does anyone has an idea how to delete role for rules from code?

I am able to turn each rule's expression into BooleanExpression, but i could not figure out how to remove a role from it. Seems like it is a complicate task to do.


Aug 12, 2011 at 6:49 AM

You can use the Fluent Configuration API to modify the Rule Expression itself at runtime. Here is a sample code snippet:

            var source = new FileConfigurationSource(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            ConfigurationSourceBuilder configBuilder = new ConfigurationSourceBuilder();

            SecuritySettings securityConfigSection = (SecuritySettings)source.GetSection("securityConfiguration");
            AuthorizationRuleProviderData provider = (AuthorizationRuleProviderData)securityConfigSection.AuthorizationProviders.Get("Authorization Rule Provider");
            AuthorizationRuleData myRule = provider.Rules.Get("Authorization Rule");

            //Modify the Rule Expression
            myRule.Expression = "MyNewExpression";

            configBuilder.AddSection("loggingConfiguration", securityConfigSection);

            //Required code to update the EntLib Configuration with settings set above.
            var configSource = new DictionaryConfigurationSource();

            //Set the Enterprise Library Container for the inner workings of EntLib to use when logging
            EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us