public void CanDeserializeSerializedConfiguration()
		{
			SecuritySettings settings = new SecuritySettings();

			AuthorizationRuleProviderData authorizationData1 = new AuthorizationRuleProviderData(authorizationName1);
			authorizationData1.Rules.Add(new AuthorizationRuleData(ruleName11, expression11));
			authorizationData1.Rules.Add(new AuthorizationRuleData(ruleName12, expression12));

			CustomAuthorizationProviderData authorizationData2 = new CustomAuthorizationProviderData(authorizationName2, typeof(MockCustomAuthorizationProvider));

			settings.AuthorizationProviders.Add(authorizationData1);
			settings.AuthorizationProviders.Add(authorizationData2);
			settings.DefaultAuthorizationProviderName = authorizationName1;

			IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
			sections[SecuritySettings.SectionName] = settings;
			IConfigurationSource configurationSource
				= ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

			SecuritySettings roSettigs = (SecuritySettings)configurationSource.GetSection(SecuritySettings.SectionName);

			Assert.IsNotNull(roSettigs);
			Assert.AreEqual(2, roSettigs.AuthorizationProviders.Count);

			Assert.IsNotNull(roSettigs.AuthorizationProviders.Get(authorizationName1));
			Assert.AreSame(typeof(AuthorizationRuleProviderData), roSettigs.AuthorizationProviders.Get(authorizationName1).GetType());
			Assert.AreEqual(2, ((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Count);
			Assert.IsNotNull(((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Get(ruleName11));
			Assert.AreEqual(expression11, ((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Get(ruleName11).Expression);

			Assert.IsNotNull(roSettigs.AuthorizationProviders.Get(authorizationName2));
			Assert.AreSame(typeof(CustomAuthorizationProviderData), roSettigs.AuthorizationProviders.Get(authorizationName2).GetType());
			Assert.AreSame(typeof(MockCustomAuthorizationProvider), ((CustomAuthorizationProviderData)roSettigs.AuthorizationProviders.Get(authorizationName2)).Type);
		}
 public void SetUp()
 {
     provider = new AuthorizationRuleProviderDataManageabilityProvider();
     machineKey = new MockRegistryKey(true);
     userKey = new MockRegistryKey(true);
     configurationObject = new AuthorizationRuleProviderData();
 }
Ejemplo n.º 3
0
        private static SecuritySettings GenerateSecuritySettings()
        {
            SecuritySettings settings = new SecuritySettings();

            settings.DefaultAuthorizationProviderName  = "Authorization Provider";
            settings.DefaultAuthenticationProviderName = "Authentication Provider";
            settings.DefaultProfileProviderName        = "Profile Provider";
            settings.DefaultRolesProviderName          = "Roles Provider";
            settings.DefaultSecurityCacheProviderName  = "Security Cache Provider1";

            AuthorizationRuleProviderData providerData = new AuthorizationRuleProviderData("RuleProvider");

            providerData.Rules.Add(new AuthorizationRuleData("Rule1", "I:TestUser OR R:Admin"));
            settings.AuthorizationProviders.Add(providerData);

            settings.AuthorizationProviders.Add(new CustomAuthorizationProviderData("Authorization Provider", typeof(MockAuthorizationProvider).AssemblyQualifiedName));
            settings.AuthorizationProviders.Add(new CustomAuthorizationProviderData("provider1", typeof(MockAuthorizationProvider).AssemblyQualifiedName));
            settings.AuthorizationProviders.Add(new CustomAuthorizationProviderData("provider2", typeof(Mock2AuthorizationProvider).AssemblyQualifiedName));

            settings.AuthenticationProviders.Add(new CustomAuthenticationProviderData("Authentiction Provider", typeof(MockAuthenticationProvider).AssemblyQualifiedName));

            settings.RolesProviders.Add(new CustomRolesProviderData("Roles Provider", typeof(MockRolesProvider).AssemblyQualifiedName));

            settings.ProfileProviders.Add(new CustomProfileProviderData("Profile Provider", typeof(MockProfileProvider).AssemblyQualifiedName));

            settings.SecurityCacheProviders.Add(new CustomSecurityCacheProviderData("Security Cache Provider1", typeof(MockSecurityCacheProvider).AssemblyQualifiedName));

            return(settings);
        }
Ejemplo n.º 4
0
 public void SetUp()
 {
     provider            = new AuthorizationRuleProviderDataManageabilityProvider();
     machineKey          = new MockRegistryKey(true);
     userKey             = new MockRegistryKey(true);
     configurationObject = new AuthorizationRuleProviderData();
 }
Ejemplo n.º 5
0
 private void BuildAuthorizationRules()
 {
     foreach (AuthorizationRuleNode ruleNode in hierarchy.FindNodesByType(typeof(AuthorizationRuleNode)))
     {
         AuthorizationRuleProviderData data = (AuthorizationRuleProviderData)securityConfiguration.AuthorizationProviders.Get(ruleNode.Parent.Name);
         data.Rules.Add(ruleNode.AuthorizationRuleData);
     }
 }
 /// <summary>
 /// Initialize a new instance of the <see cref="AuthorizationRuleProviderNode"/> class with an <see cref="AuthorizationRuleProviderData"/> instance.
 /// </summary>
 /// <param name="data">An <see cref="AuthorizationRuleProviderData"/> instance</param>
 public AuthorizationRuleProviderNode(AuthorizationRuleProviderData data)
     : base()
 {
     if (null == data)
     {
         throw new ArgumentNullException("data");
     }
     Rename(data.Name);
 }
            public AuthorizeRuleBasedBuilder(IConfigureSecuritySettings context, string ruleBasedProviderName)
                : base(context)
            {
                ruleAuthZProvider = new AuthorizationRuleProviderData
                {
                    Name = ruleBasedProviderName
                };

                base.SecuritySettings.AuthorizationProviders.Add(ruleAuthZProvider);
            }
Ejemplo n.º 8
0
        private AuthorizationRuleDataCollection GetAuthorizationRules()
        {
            AuthorizationProviderData authorizationProviderData = securityConfigurationView.GetAuthorizationProviderData(ConfigurationName);

            ArgumentValidation.CheckExpectedType(authorizationProviderData, typeof(AuthorizationRuleProviderData));

            AuthorizationRuleProviderData authorizationRuleProviderData = (AuthorizationRuleProviderData)authorizationProviderData;

            return(authorizationRuleProviderData.Rules);
        }
        public void Setup()
        {
            AuthorizationRuleProviderData ruleProvider = new AuthorizationRuleProviderData();

            ruleProvider.Name = "Rule Provider";

            SecuritySettings settings = new SecuritySettings();

            settings.AuthorizationProviders.Add(ruleProvider);

            registrations = settings.GetRegistrations(null);
        }
Ejemplo n.º 10
0
        private static Rule GetRule(string ruleName, ConfigurationSourceSection section)
        {
            SqlConfigurationSource source = GetSelectedConfigurationSource(section);
            //get selected source
            SqlConfigurationSource selectedSource = GetSelectedConfigurationSource(section);

            SecurityConfigurationView     securityConfigurationView = new SecurityConfigurationView(selectedSource);
            AuthorizationRuleProviderData authorizationProviderData = GetAuthorizationProviderData(securityConfigurationView, source, section);

            AuthorizationRuleData authorizationRuleData = authorizationProviderData.Rules.Get(ruleName);

            return(new Rule(authorizationRuleData.Name, authorizationRuleData.Expression));
        }
Ejemplo n.º 11
0
        public void FixtureSetup()
        {
            data          = new AuthorizationRuleProviderData("foo");
            data.TypeName = typeof(AuthorizationRuleProviderData).AssemblyQualifiedName;

            data.Rules.Add(new AuthorizationRuleData(testRuleName, "I:*"));

            provider = new AuthorizationRuleProvider();
            provider.ConfigurationName = data.Name;
            provider.Initialize(new TestAuthorizationRuleProviderView(data, context));

            principal = new GenericPrincipal(new GenericIdentity("user1"), new string[] { "Admin", "Manager" });
        }
Ejemplo n.º 12
0
        protected override void Arrange()
        {
            updatableConfigurationSource = new ConfigurationSourceUpdatable();

            ruleProvider      = new AuthorizationRuleProviderData();
            ruleProvider.Name = "ruleProvider";

            settings = new SecuritySettings();
            settings.AuthorizationProviders.Add(ruleProvider);

            updatableConfigurationSource.Add(SecuritySettings.SectionName, settings);

            container             = new UnityContainer();
            containerConfigurator = new UnityContainerConfigurator(container);
            EnterpriseLibraryContainer.ConfigureContainer(containerConfigurator, updatableConfigurationSource);
        }
Ejemplo n.º 13
0
        public void RegisteredAuthorizationProviderDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(AuthorizationRuleProviderData), registeredProvider);
            provider = new ConfigurationSectionManageabilityProviderWrapper(
                new SecuritySettingsManageabilityProvider(subProviders));

            AuthorizationRuleProviderData authorizationProviderData = new AuthorizationRuleProviderData("authorizationProvider1");

            section.AuthorizationProviders.Add(authorizationProviderData);

            MockRegistryKey machineauthorizationProvidersKey = new MockRegistryKey(false);

            machineKey.AddSubKey(SecuritySettingsManageabilityProvider.AuthorizationProvidersKeyName, machineauthorizationProvidersKey);
            MockRegistryKey machineauthorizationProviderKey = new MockRegistryKey(false);

            machineauthorizationProvidersKey.AddSubKey("authorizationProvider1", machineauthorizationProviderKey);
            MockRegistryKey machineOtherauthorizationProviderKey = new MockRegistryKey(false);

            machineauthorizationProvidersKey.AddSubKey("authorizationProvider2", machineOtherauthorizationProviderKey);

            MockRegistryKey userauthorizationProvidersKey = new MockRegistryKey(false);

            userKey.AddSubKey(SecuritySettingsManageabilityProvider.AuthorizationProvidersKeyName, userauthorizationProvidersKey);
            MockRegistryKey userauthorizationProviderKey = new MockRegistryKey(false);

            userauthorizationProvidersKey.AddSubKey("authorizationProvider1", userauthorizationProviderKey);
            MockRegistryKey userOtherauthorizationProviderKey = new MockRegistryKey(false);

            userauthorizationProvidersKey.AddSubKey("authorizationProvider2", userOtherauthorizationProviderKey);

            provider.InvokeOverrideWithGroupPoliciesAndGenerateWmiObjects(section, true, machineKey, userKey, true, wmiSettings);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(authorizationProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreSame(machineauthorizationProviderKey, registeredProvider.machineKey);
            Assert.AreSame(userauthorizationProviderKey, registeredProvider.userKey);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machineauthorizationProvidersKey, machineauthorizationProviderKey, machineOtherauthorizationProviderKey,
                                               userauthorizationProvidersKey, userauthorizationProviderKey, userOtherauthorizationProviderKey));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets all rules.
        /// </summary>
        /// <returns></returns>
        public static List <Rule> GetAllRules()
        {
            ConfigurationSourceSection section = GetConfigurationSourceSection();
            SqlConfigurationSource     source  = GetSelectedConfigurationSource(section);
            //get selected source
            SqlConfigurationSource        selectedSource            = GetSelectedConfigurationSource(section);
            SecurityConfigurationView     securityConfigurationView = new SecurityConfigurationView(selectedSource);
            AuthorizationRuleProviderData authorizationProviderData = GetAuthorizationProviderData(securityConfigurationView, source, section);

            List <Rule> rules = new List <Rule>();

            //loop through all the rules
            authorizationProviderData.Rules.ForEach(delegate(AuthorizationRuleData currentRule)
            {
                rules.Add(new Rule(currentRule.Name, currentRule.Expression));
            });

            return(rules);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Updates a rule.
        /// </summary>
        /// <param name="rule">The rule.</param>
        public static void UpdateRule(Rule rule)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                ConfigurationSourceSection section = GetConfigurationSourceSection();
                //get selected source
                SqlConfigurationSource selectedSource = GetSelectedConfigurationSource(section);
                //get authorization Provider
                SecurityConfigurationView     securityConfigurationView = new SecurityConfigurationView(selectedSource);
                SecuritySettings              securitySettings          = securityConfigurationView.GetSecuritySettings();
                AuthorizationRuleProviderData authorizationProviderData = securitySettings.AuthorizationProviders.Get(
                    securityConfigurationView.GetDefaultAuthorizationProviderName()) as AuthorizationRuleProviderData;
                //add the new rule to the collection
                authorizationProviderData.Rules.Get(rule.Name).Expression = rule.Expression;

                SqlConfigurationSourceElement element = GetElement(section.SelectedSource, section.Sources);
                selectedSource.Save(element.ConnectionString, element.SetStoredProcedure, "securityConfiguration", securitySettings);
                scope.Complete();
            }
        }
Ejemplo n.º 16
0
        public void RegisteredAuthorizationProviderDataProviderIsCalledWithNoOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary <Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary <Type, ConfigurationElementManageabilityProvider>();

            subProviders.Add(typeof(AuthorizationRuleProviderData), registeredProvider);
            provider = new SecuritySettingsManageabilityProvider(subProviders);

            AuthorizationRuleProviderData authorizationProviderData = new AuthorizationRuleProviderData("authorizationProvider1");

            section.AuthorizationProviders.Add(authorizationProviderData);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(authorizationProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(null, registeredProvider.machineKey);
            Assert.AreEqual(null, registeredProvider.userKey);
        }
Ejemplo n.º 17
0
        private void BuildAuthorizationProviders(AuthorizationProviderData authorizationProviderData)
        {
            ConfigurationNode authorizationProviderNode = NodeCreationService.CreateNodeByDataType(authorizationProviderData.GetType(), new object[] { authorizationProviderData });

            if (null == authorizationProviderNode)
            {
                LogNodeMapError(authorizationProviderCollectionNode_, authorizationProviderData.GetType());
                return;
            }
            if (typeof(AuthorizationRuleProviderData) == authorizationProviderData.GetType())
            {
                AuthorizationRuleProviderData authorizationRuleProviderData = (AuthorizationRuleProviderData)authorizationProviderData;
                this.authorizationRuleProviderNode = (AuthorizationRuleProviderNode)authorizationProviderNode;

                authorizationRuleProviderData.Rules.ForEach(new Action <AuthorizationRuleData>(BuildAuthorizationRule));
            }
            if (authorizationProviderNode.Name == settings.DefaultAuthorizationProviderName)
            {
                defaultAuthorizationNode = (AuthorizationProviderNode)authorizationProviderNode;
            }
            authorizationProviderCollectionNode_.AddNode(authorizationProviderNode);
        }
        public void CanDeserializeSerializedConfiguration()
        {
            SecuritySettings settings = new SecuritySettings();

            AuthorizationRuleProviderData authorizationData1 = new AuthorizationRuleProviderData(authorizationName1);

            authorizationData1.Rules.Add(new AuthorizationRuleData(ruleName11, expression11));
            authorizationData1.Rules.Add(new AuthorizationRuleData(ruleName12, expression12));

            CustomAuthorizationProviderData authorizationData2 = new CustomAuthorizationProviderData(authorizationName2, typeof(MockCustomAuthorizationProvider));

            settings.AuthorizationProviders.Add(authorizationData1);
            settings.AuthorizationProviders.Add(authorizationData2);
            settings.DefaultAuthorizationProviderName = authorizationName1;

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[SecuritySettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            SecuritySettings roSettigs = (SecuritySettings)configurationSource.GetSection(SecuritySettings.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(2, roSettigs.AuthorizationProviders.Count);

            Assert.IsNotNull(roSettigs.AuthorizationProviders.Get(authorizationName1));
            Assert.AreSame(typeof(AuthorizationRuleProviderData), roSettigs.AuthorizationProviders.Get(authorizationName1).GetType());
            Assert.AreEqual(2, ((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Count);
            Assert.IsNotNull(((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Get(ruleName11));
            Assert.AreEqual(expression11, ((AuthorizationRuleProviderData)roSettigs.AuthorizationProviders.Get(authorizationName1)).Rules.Get(ruleName11).Expression);

            Assert.IsNotNull(roSettigs.AuthorizationProviders.Get(authorizationName2));
            Assert.AreSame(typeof(CustomAuthorizationProviderData), roSettigs.AuthorizationProviders.Get(authorizationName2).GetType());
            Assert.AreSame(typeof(MockCustomAuthorizationProvider), ((CustomAuthorizationProviderData)roSettigs.AuthorizationProviders.Get(authorizationName2)).Type);
        }
		/// <summary>
		/// Initialize a new instance of the <see cref="AuthorizationRuleProviderNode"/> class with an <see cref="AuthorizationRuleProviderData"/> instance.
		/// </summary>
		/// <param name="data">An <see cref="AuthorizationRuleProviderData"/> instance</param>
		public AuthorizationRuleProviderNode(AuthorizationRuleProviderData data)
			: base()
        {
			if (null == data) throw new ArgumentNullException("data");
			Rename(data.Name);
        }
 /// <summary>
 /// Initializes a new instance of this node from existing configuration data.
 /// </summary>
 /// <param name="data">Configuration data.</param>
 public AuthorizationRuleProviderNode(AuthorizationRuleProviderData data)
     : base(data)
 {
     this.authorizationRuleProviderData = data;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of this node from existing configuration data.
 /// </summary>
 /// <param name="data">Configuration data.</param>
 public AuthorizationRuleProviderNode(AuthorizationRuleProviderData data) : base(data)
 {
     this.authorizationRuleProviderData = data;
 }
Ejemplo n.º 22
0
 public TestAuthorizationRuleProviderView(AuthorizationRuleProviderData data, ConfigurationContext context) : base(context)
 {
     this.data = data;
 }