public MemberShipService()
        {
            _membershipSection = (MembershipSection)ConfigurationManager.GetSection("system.web/membership");

            _memberShipSettingsProvider = _membershipSection.Providers[_membershipSection.DefaultProvider];
            _roleManagerSection = (RoleManagerSection)ConfigurationManager.GetSection("system.web/roleManager");
            _roleProviderSettings = _roleManagerSection.Providers[_roleManagerSection.DefaultProvider];

            _membershipParameters = _memberShipSettingsProvider.Parameters;
            _rolemanagerParameters = _roleProviderSettings.Parameters;
        }
Example #2
0
 public static void SetRoleSettings(System.Web.Configuration.RoleManagerSection roleManagerSection
                                    , string connectionStringName)
 {
     roleManagerSection.Enabled         = true;
     roleManagerSection.DefaultProvider = ProviderName;
     if (roleManagerSection.Providers[ProviderName] == null)
     {
         ProviderSettings p = new ProviderSettings(ProviderName, "System.Web.Security.SqlRoleProvider");
         p.Parameters["connectionStringName"] = connectionStringName;
         p.Parameters["applicationName"]      = "/";
         roleManagerSection.Providers.Add(p);
     }
 }
		// It test all existing (as of r61933) configuration
		// sections that use PropertyHelper.NonEmptyStringValidator.
		public void NullableStringProperties ()
		{
			new AnonymousIdentificationSection ().CookieName = null;
			new AnonymousIdentificationSection ().CookiePath = null;
			new AssemblyInfo (null);
			new BufferModeSettings (null, 0x10000, 0x1000, 10,
			TimeSpan.FromMinutes (1),
			TimeSpan.FromSeconds (30), 10);
			new BuildProvider (null, null);
			new ClientTarget (null, null);
			new CodeSubDirectory (null);
			new EventMappingSettings (null, null);
			new ExpressionBuilder (null, null);
			FormsAuthenticationConfiguration fac =
			new FormsAuthenticationConfiguration ();
			// I don't like this test though.
			fac.DefaultUrl = null;
			fac.LoginUrl = null;
			fac.Name = null;
			fac.Path = null;
			new HttpHandlerAction (null, null, null);
			new HttpModuleAction (null, null);
			MachineKeySection mks = new MachineKeySection ();
			// algorithms are limited
			// mks.Decryption = null;
			mks.DecryptionKey = null;
			mks.ValidationKey = null;
			new MembershipSection ().DefaultProvider = null;
			new NamespaceInfo (null);
			new OutputCacheProfile (null);
			new ProfileSettings (null);
			RoleManagerSection rms = new RoleManagerSection ();
			rms.CookieName = null;
			rms.CookiePath = null;
			rms.DefaultProvider = null;
			new RuleSettings (null, null, null);
			new SqlCacheDependencyDatabase (null, null);
			new TagMapInfo (null, null);
			new TagPrefixInfo (null, null, null, null, null);
			new TransformerInfo (null, null);
			new TrustLevel (null, null);
			new TrustSection ().Level = null;
			new UrlMapping (null, null);
			// WebControlsSection.ClientScriptsLocation is not settable
			new WebPartsPersonalization ().DefaultProvider = null;
		}
Example #4
0
		public void Init (HttpApplication app)
		{
			_config = (RoleManagerSection) WebConfigurationManager.GetSection ("system.web/roleManager");

			app.PostAuthenticateRequest += OnPostAuthenticateRequest;
			app.EndRequest += OnEndRequest;
		}
		void ProcessReplace (RoleManagerSection section, SettingsMappingWhatContents how)
		{
			string name, type;
			if (!GetCommonAttributes (how, out name, out type))
				return;

			ProviderSettings provider = section.Providers [name];
			if (provider != null)
				SetProviderProperties (how, provider);
		}
		void ProcessClear (RoleManagerSection section, SettingsMappingWhatContents how)
		{
			section.Providers.Clear ();
		}
		void ProcessRemove (RoleManagerSection section, SettingsMappingWhatContents how)
		{
			string name, type;
			if (!GetCommonAttributes (how, out name, out type))
				return;

			ProviderSettingsCollection providers = section.Providers;
			ProviderSettings provider = providers [name];
			if (provider != null) {
				if (provider.Type != type)
					return;
				providers.Remove (name);
			}
		}
		void ProcessAdd (RoleManagerSection section, SettingsMappingWhatContents how)
		{
			string name, type;
			if (!GetCommonAttributes (how, out name, out type))
				return;

			ProviderSettingsCollection providers = section.Providers;
			ProviderSettings provider = providers [name];
			if (provider != null)
				return;

			ProviderSettings prov = new ProviderSettings (name, type);
			SetProviderProperties (how, prov);
			
			providers.Add (prov);
		}
        private static void InitializeDefaultProvider(RoleManagerSection settings) {
            bool canInitializeDefaultProvider = (!HostingEnvironment.IsHosted || BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);
            if (!s_InitializedDefaultProvider && canInitializeDefaultProvider) {
                Debug.Assert(s_Providers != null);
                s_Providers.SetReadOnly();

                if (settings.DefaultProvider == null) {
                    s_InitializeException = new ProviderException(SR.GetString(SR.Def_role_provider_not_specified));
                }
                else {
                    try {
                        s_Provider = s_Providers[settings.DefaultProvider];
                    }
                    catch { }
                }

                if (s_Provider == null) {
                    s_InitializeException = new ConfigurationErrorsException(SR.GetString(SR.Def_role_provider_not_found), settings.ElementInformation.Properties["defaultProvider"].Source, settings.ElementInformation.Properties["defaultProvider"].LineNumber);
                }

                s_InitializedDefaultProvider = true;
            }
        }
        private static void InitializeSettings(RoleManagerSection settings) {
            if (!s_Initialized) {
                s_Providers = new RoleProviderCollection();

                if (HostingEnvironment.IsHosted) {
                    ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(RoleProvider));
                }
                else {
                    foreach (ProviderSettings ps in settings.Providers) {
                        Type t = Type.GetType(ps.Type, true, true);
                        if (!typeof(RoleProvider).IsAssignableFrom(t))
                            throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(RoleProvider).ToString()));
                        RoleProvider provider = (RoleProvider)Activator.CreateInstance(t);
                        NameValueCollection pars = ps.Parameters;
                        NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal);
                        foreach (string key in pars)
                            cloneParams[key] = pars[key];
                        provider.Initialize(ps.Name, cloneParams);
                        s_Providers.Add(provider);
                    }
                }
            }
        }
 private static void InitializeSettings(RoleManagerSection settings)
 {
     if (!s_Initialized)
     {
         s_Providers = new RoleProviderCollection();
         if (HostingEnvironment.IsHosted)
         {
             ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(RoleProvider));
         }
         else
         {
             foreach (ProviderSettings settings2 in settings.Providers)
             {
                 Type c = Type.GetType(settings2.Type, true, true);
                 if (!typeof(RoleProvider).IsAssignableFrom(c))
                 {
                     throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { typeof(RoleProvider).ToString() }));
                 }
                 RoleProvider provider = (RoleProvider) Activator.CreateInstance(c);
                 NameValueCollection parameters = settings2.Parameters;
                 NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal);
                 foreach (string str in parameters)
                 {
                     config[str] = parameters[str];
                 }
                 provider.Initialize(settings2.Name, config);
                 s_Providers.Add(provider);
             }
         }
     }
 }
Example #12
0
        private ConfigurationRoleManagerModel ProcessRoleManager(RoleManagerSection roleManagerSection)
        {
            if (roleManagerSection == null)
            {
                return null;
            }

            var result = new ConfigurationRoleManagerModel();
            result.CacheRolesInCookie = roleManagerSection.CacheRolesInCookie;
            result.CookieName = roleManagerSection.CookieName;
            result.CookiePath = roleManagerSection.CookiePath;
            result.CookieProtection = roleManagerSection.CookieProtection.ToString();
            result.CookieRequireSSL = roleManagerSection.CookieRequireSSL;
            result.CookieSlidingExpiration = roleManagerSection.CookieSlidingExpiration;
            result.CookieTimeout = roleManagerSection.CookieTimeout;
            result.CreatePersistentCookie = roleManagerSection.CreatePersistentCookie;
            result.DefaultProvider = roleManagerSection.DefaultProvider;
            result.Domain = roleManagerSection.Domain;
            result.Enabled = roleManagerSection.Enabled;
            result.MaxCachedResults = roleManagerSection.MaxCachedResults;

            var providerSection = roleManagerSection.Providers;
            if (providerSection != null)
            {
                var resultProviders = new List<ConfigurationRoleManagerProviderSettingsModel>();
                foreach (ProviderSettings provider in providerSection)
                {
                    var resultProvider = new ConfigurationRoleManagerProviderSettingsModel();
                    resultProvider.Name = provider.Name;
                    resultProvider.Type = provider.Type;
                    resultProvider.Parameters = provider.Parameters.ToDictionary();

                    resultProviders.Add(resultProvider);
                }

                result.Providers = resultProviders;
            }

            return result;
        }
Example #13
0
		static Roles ()
		{
			config = (RoleManagerSection)WebConfigurationManager.GetSection ("system.web/roleManager");
		}
Example #14
0
 public static void SetRoleSettings(System.Web.Configuration.RoleManagerSection roleManagerSection)
 {
     SetRoleSettings(roleManagerSection, Unicorn.Data.ConnectionManager.ConnectionStringName);
 }