예제 #1
0
 /// <summary>
 /// <para>Adds an <see cref="SecurityCacheProviderData"/> into the collection.</para>
 /// </summary>
 /// <param name="providerData">
 /// <para>The <see cref="SecurityCacheProviderData"/> to add. The value can not be a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// </param>
 /// <remarks>
 /// <para>If a reference already exists in the collection by <seealso cref="ProviderData.Name"/>, it will be replaced with the new reference.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">
 /// <para><paramref name="providerData"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// <para>- or -</para>
 /// <para><seealso cref="ProviderData.Name"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// </exception>
 public void Add(SecurityCacheProviderData providerData)
 {
     AddProvider(providerData);
 }
        public void SecurityCacheProviderWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(SecurityCacheProviderData), registeredProvider);
            provider = new SecuritySettingsManageabilityProvider(subProviders);

            SecurityCacheProviderData securityCacheProvider1Data = new SecurityCacheProviderData("securityCacheProvider1", typeof(Object));
            section.SecurityCacheProviders.Add(securityCacheProvider1Data);
            SecurityCacheProviderData securityCacheProvider2Data = new SecurityCacheProviderData("securityCacheProvider2", typeof(Object));
            section.SecurityCacheProviders.Add(securityCacheProvider2Data);

            MockRegistryKey machineSecurityCacheProvidersKey = new MockRegistryKey(false);
            machineKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, machineSecurityCacheProvidersKey);
            MockRegistryKey machineSecurityCacheProvider2Key = new MockRegistryKey(false);
            machineSecurityCacheProvidersKey.AddSubKey("securityCacheProvider2", machineSecurityCacheProvider2Key);
            machineSecurityCacheProvider2Key.AddBooleanValue(SecuritySettingsManageabilityProvider.PolicyValueName, false);

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

            Assert.AreEqual(2, section.SecurityCacheProviders.Count);
            Assert.IsNotNull(section.SecurityCacheProviders.Get("securityCacheProvider1"));
            Assert.IsNotNull(section.SecurityCacheProviders.Get("securityCacheProvider2"));

            Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineSecurityCacheProvidersKey, machineSecurityCacheProvider2Key));
        }
        public void ManageabilityProviderGeneratesProperAdmContent()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(SecuritySettings.SectionName, section);

            AuthorizationProviderData authorization = new AuthorizationProviderData("authorization", typeof(object));
            SecurityCacheProviderData security = new SecurityCacheProviderData("security", typeof(object));
            section.AuthorizationProviders.Add(authorization);
            section.SecurityCacheProviders.Add(security);

            MockConfigurationElementManageabilityProvider subProvider = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(AuthorizationProviderData), subProvider);
            subProviders.Add(typeof(SecurityCacheProviderData), subProvider);
            provider = new SecuritySettingsManageabilityProvider(subProviders);

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            provider.AddAdministrativeTemplateDirectives(contentBuilder, section, configurationSource, "TestApp");

            Assert.AreEqual(2, subProvider.configurationObjects.Count);
            Assert.AreSame(authorization, subProvider.configurationObjects[0]);
            Assert.AreSame(security, subProvider.configurationObjects[1]);
            MockAdmContent content = contentBuilder.GetMockContent();
            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            Assert.IsTrue(categoriesEnumerator.MoveNext());
            IEnumerator<AdmCategory> subCategoriesEnumerator = categoriesEnumerator.Current.Categories.GetEnumerator();
            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            Assert.IsTrue(subCategoriesEnumerator.MoveNext());
            Assert.IsFalse(subCategoriesEnumerator.MoveNext());
            IEnumerator<AdmPolicy> sectionPoliciesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();
            Assert.IsTrue(sectionPoliciesEnumerator.MoveNext());
            IEnumerator<AdmPart> sectionPartsEnumerator = sectionPoliciesEnumerator.Current.Parts.GetEnumerator();
            Assert.IsTrue(sectionPartsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), sectionPartsEnumerator.Current.GetType());
            Assert.AreEqual(SecuritySettingsManageabilityProvider.DefaultAuthorizationProviderPropertyName,
                            ((AdmDropDownListPart)sectionPartsEnumerator.Current).ValueName);
            Assert.IsTrue(sectionPartsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), sectionPartsEnumerator.Current.GetType());
            Assert.AreEqual(SecuritySettingsManageabilityProvider.DefaultSecurityCacheProviderPropertyName,
                            ((AdmDropDownListPart)sectionPartsEnumerator.Current).ValueName);
            Assert.IsFalse(sectionPartsEnumerator.MoveNext());
            Assert.IsFalse(sectionPoliciesEnumerator.MoveNext());
            Assert.IsFalse(categoriesEnumerator.MoveNext());
        }
 /// <summary>
 /// <para>Adds an <see cref="SecurityCacheProviderData"/> into the collection.</para>
 /// </summary>
 /// <param name="providerData">
 /// <para>The <see cref="SecurityCacheProviderData"/> to add. The value can not be a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// </param>
 /// <remarks>
 /// <para>If a reference already exists in the collection by <seealso cref="ProviderData.Name"/>, it will be replaced with the new reference.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">
 /// <para><paramref name="providerData"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// <para>- or -</para>
 /// <para><seealso cref="ProviderData.Name"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
 /// </exception>
 public void Add(SecurityCacheProviderData providerData)
 {
     AddProvider(providerData);
 }