private void AddProvider() { var adConfig = CustomConfiguration.Settings.ActiveDirectoryData(); var provider = new ActiveDirectoryProvider(); var config = new NameValueCollection { ["name"] = CalmoProviderName, ["connectionStringName"] = adConfig.ConnectionStringName, ["connectionUsername"] = adConfig.UserName, ["connectionPassword"] = adConfig.Password, ["attributeMapUsername"] = "******" }; provider.Initialize(CalmoProviderName, config); var membershipProviders = new MembershipProviderCollection { provider }; membershipProviders.SetReadOnly(); var bindingFlags = BindingFlags.NonPublic | BindingFlags.Static; var membershipType = typeof(Membership); membershipType.GetField("s_Initialized", bindingFlags)?.SetValue(null, true); membershipType.GetField("s_InitializeException", bindingFlags)?.SetValue(null, null); membershipType.GetField("s_Provider", bindingFlags)?.SetValue(null, provider); membershipType.GetField("s_Providers", bindingFlags)?.SetValue(null, membershipProviders); }
private void RegisterProviders(IUnityContainer container) { // 身份 MembershipProviderCollection mProviders = new MembershipProviderCollection(); MembershipSection mSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership"); foreach (ProviderSettings settings in mSection.Providers) { if (settings.Parameters["connectionStringName"] != null) { settings.Parameters["connectionStringName"] = D.NamedSection.DataConnection; } } ProvidersHelper.InstantiateProviders( mSection.Providers, mProviders, typeof(MembershipProvider)); MembershipProvider mProvider = mProviders[mSection.DefaultProvider]; // 角色 RoleProviderCollection rProviders = new RoleProviderCollection(); RoleManagerSection rSection = (RoleManagerSection)WebConfigurationManager.GetSection("system.web/roleManager"); foreach (ProviderSettings settings in rSection.Providers) { if (settings.Parameters["connectionStringName"] != null) { settings.Parameters["connectionStringName"] = D.NamedSection.DataConnection; } } ProvidersHelper.InstantiateProviders( rSection.Providers, rProviders, typeof(RoleProvider)); RoleProvider rProvider = rProviders[rSection.DefaultProvider]; // 配置 ProfileProviderCollection pProviders = new ProfileProviderCollection(); ProfileSection pSection = (ProfileSection)WebConfigurationManager.GetSection("system.web/profile"); foreach (ProviderSettings settings in pSection.Providers) { if (settings.Parameters["connectionStringName"] != null) { settings.Parameters["connectionStringName"] = D.NamedSection.DataConnection; } } ProvidersHelper.InstantiateProviders( pSection.Providers, pProviders, typeof(ProfileProvider)); ProfileProvider pProvider = pProviders[pSection.DefaultProvider]; container.RegisterInstance <MembershipProvider>(mProvider); container.RegisterInstance <RoleProvider>(rProvider); container.RegisterInstance <ProfileProvider>(pProvider); }
public void UnexistingProvider() { MembershipProviderCollection mpc = new MembershipProviderCollection(); Assert.IsNull(mpc["uho"]); // but this will throw an HttpException if we're using an unknown provider // in an ASP.NET control (like Login) }
internal BetterRoleProvider( WebSecurityFacade webSecurityFacade, MembershipProviderCollection membershipProviders) { Condition.Requires(webSecurityFacade, "webSecurityFacade").IsNotNull(); Condition.Requires(membershipProviders, "membershipProviders").IsNotNull(); this.webSecurityFacade = webSecurityFacade; this.membershipProviders = membershipProviders; }
public void Add_ProviderBase() { TestProviderBase pb = new TestProviderBase(); MembershipProviderCollection mpc = new MembershipProviderCollection(); mpc.Add(pb); // Add accept ProviderBase but docs says it throws // an exception if it's not a MembershipProvider }
public void ProvidersTest() { try { MembershipProviderCollection providers = Membership.Providers; Assert.AreEqual(providers.Count, 1); } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); Assert.Fail("Error retrieving Providers property", ex); } }
public static IEnumerable <MembershipProvider> ToList(this MembershipProviderCollection collection) { var providers = new List <MembershipProvider>(); foreach (MembershipProvider provider in collection) { providers.Add(provider); } return(providers); }
/// <summary> /// Get the default mocked Membership Static Proxy /// </summary> /// <returns></returns> public static Mock <IMembershipProxy> Create(MembershipProvider provider) { var mockMembership = new Mock <IMembershipProxy>(MockBehavior.Strict); var providers = new MembershipProviderCollection { provider }; mockMembership.SetupGet(m => m.Provider).Returns(provider); mockMembership.SetupGet(m => m.Providers).Returns(providers); return(mockMembership); }
internal BetterProfileProvider( Func <string, IDatabase> databaseFactory, Func <string, string, string, string, string, ISqlQueryBuilder> sqlQueryBuilderFactory, MembershipProviderCollection membershipProviders) { Condition.Requires(databaseFactory, "databaseFctory").IsNotNull(); Condition.Requires(sqlQueryBuilderFactory, "sqlQueryBuilderFactory").IsNotNull(); Condition.Requires(membershipProviders, "membershipProviders").IsNotNull(); this.databaseFactory = databaseFactory; this.sqlQueryBuilderFactory = sqlQueryBuilderFactory; this.membershipProviders = membershipProviders; }
public Provider() { try { SqlMembershipProvider sqlMembershipProvider = new SqlMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "myConnection"); config.Add("enablePasswordRetrieval", "false"); config.Add("enablePasswordReset", "true"); config.Add("requiresQuestionAndAnswer", "false"); config.Add("applicationName", "MyApp"); config.Add("requiresUniqueEmail", "true"); config.Add("maxInvalidPasswordAttempts", "3"); config.Add("passwordAttemptWindow", "5"); config.Add("commandTimeout", "30"); config.Add("name", "AspNetSqlMembershipProvider"); config.Add("minRequiredPasswordLength", "9"); config.Add("minRequiredNonalphanumericCharacters", "1"); sqlMembershipProvider.Initialize(config["name"], config); MembershipProviderCollection membershipProviders = new MembershipProviderCollection(); membershipProviders.Add(sqlMembershipProvider); membershipProviders.SetReadOnly(); BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static; Type membershipType = typeof(Membership); membershipType.GetField("s_Initialized", bindingFlags).SetValue(null, true); membershipType.GetField("s_InitializeException", bindingFlags).SetValue(null, null); membershipType.GetField("s_HashAlgorithmType", bindingFlags).SetValue(null, "SHA-512"); membershipType.GetField("s_HashAlgorithmFromConfig", bindingFlags).SetValue(null, false); membershipType.GetField("s_UserIsOnlineTimeWindow", bindingFlags).SetValue(null, 15); membershipType.GetField("s_Provider", bindingFlags).SetValue(null, sqlMembershipProvider); membershipType.GetField("s_Providers", bindingFlags).SetValue(null, membershipProviders); var connectionString = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic); if (connectionString != null) { connectionString.SetValue(Membership.Provider, DBCommands._Connection); } NewPasswordNeeded(); } catch (Exception ex) { DBCommands.RecordError(ex); } }
public void InjectMembershipImplementation(IEnumerable <KeyValuePair <string, string> > simulatedAppConfigSettings) { if (MembershipIsInitialized) { _originalProvider = MembershipProvider; } else { _originalProvider = null; } _injectedProvider = GetProvider(); InitializeMembershipProviderFromConfigEntry(_injectedProvider, simulatedAppConfigSettings); PostInitializeUpdate(_injectedProvider); MembershipProvider = _injectedProvider; MembershipIsInitialized = true; MembershipProviders = new MembershipProviderCollection(); MembershipProviders.Add(_injectedProvider); MembershipProviders.SetReadOnly(); }
public void Add_Null() { MembershipProviderCollection mpc = new MembershipProviderCollection(); mpc.Add(null); }
public static bool IsUsingDefaultBackOfficeMembershipProvider(this MembershipProviderCollection providers) { var provider = providers.GetBackOfficeMembershipProvider(); return(provider.IsDefaultBackOfficeMembershipProvider()); }
public static MembershipProvider GetBackOfficeMembershipProvider(this MembershipProviderCollection providers) { return(providers["BackOfficeMembershipProvider"]); }
public static bool IsUsingDefaultUsersMembershipProvider(this MembershipProviderCollection providers) { var provider = providers.GetUsersMembershipProvider(); return(provider.IsHiveMembershipProvider()); }
public static MembershipProvider GetMembersMembershipProvider(this MembershipProviderCollection providers) { return(providers["MembersMembershipProvider"]); }
public MembershipDriveInfo(PSDriveInfo driveInfo, DriveParameters parameters) : base(driveInfo) { var connectionStrings = ConfigurationManager.ConnectionStrings; var fi = typeof(ConfigurationElementCollection) .GetField("bReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); fi.SetValue(connectionStrings, false); var connectionString = String.Format( "data source={0};Integrated Security=SSPI;Initial Catalog={1}", parameters.Server, parameters.Catalog ); var moniker = Guid.NewGuid().ToString("N"); var connectionStringName = moniker; var providerName = "AspNetSqlMembershipProvider"; connectionStrings.Add( new ConnectionStringSettings( connectionStringName, connectionString ) ); provider = new SqlMembershipProvider(); var nvc = new System.Collections.Specialized.NameValueCollection { { "connectionStringName", connectionStringName }, { "enablePasswordRetrieval", parameters.EnablePasswordRetrieval.ToString() }, { "enablePasswordReset", parameters.EnablePasswordReset.ToString() }, { "requiresQuestionAndAnswer", parameters.RequiresQuestionAndAnswer.ToString() }, { "requiresUniqueEmail", parameters.RequiresUniqueEmail.ToString() }, { "passwordFormat", parameters.PasswordFormat.ToString() }, { "maxInvalidPasswordAttempts", parameters.MaxInvalidPasswordAttempts.ToString() }, { "minRequiredPasswordLength", parameters.MinRequiredPasswordLength.ToString() }, { "minRequiredNonalphanumericCharacters", parameters.MinRequiredNonalphanumericCharacters.ToString() }, { "passwordAttemptWindow", parameters.PasswordAttemptWindow.ToString() }, { "passwordStrengthRegularExpression", parameters.PasswordStrengthRegularExpression }, { "applicationName", parameters.ApplicationName }, }; provider.Initialize(providerName, nvc); // set up private members of the Membership type // this allows us to work with MembershipUser objects directly (e.g., calling MembershipUser.ResetPassword fi = typeof(Membership) .GetField("s_Provider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); fi.SetValue(null, provider); MembershipProviderCollection coll = new MembershipProviderCollection { provider }; fi = typeof(Membership) .GetField("s_Providers", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); fi.SetValue(null, coll); fi = typeof(Membership) .GetField("s_Initialized", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); fi.SetValue(null, true); fi = typeof(Membership) .GetField("s_HashAlgorithmType", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); fi.SetValue(null, "SHA1"); fi = typeof(Membership) .GetField("s_HashAlgorithmFromConfig", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); fi.SetValue(null, false); }