Ejemplo n.º 1
0
        public ProviderSettings GetMembershipProviderSettings()
        {
            MembershipSection section  = GetMembershipProviderSection();
            ProviderSettings  settings = section.Providers[section.DefaultProvider];

            return(settings);
        }
Ejemplo n.º 2
0
        public SessionStateConfig()
            : base()
        {
            typeName    = "MySqlSessionStateStoreProvider";
            sectionName = "sessionState";

            Configuration     machineConfig = ConfigurationManager.OpenMachineConfiguration();
            MembershipSection section       = (MembershipSection)machineConfig.SectionGroups["system.web"].Sections["membership"];

            foreach (ProviderSettings p in section.Providers)
            {
                if (p.Type != null)
                {
                    if (p.Type.Contains("MySql"))
                    {
                        ProviderType = p.Type;
                    }

                    if (ProviderType != null)
                    {
                        ProviderType = ProviderType.Replace("MySql.Web.Security.MySQLMembershipProvider",
                                                            "MySql.Web.SessionState.MySqlSessionStateStore");
                    }
                }
            }
        }
        public void InitializeMembershipProviderFromConfigEntry(MembershipProvider result,
                                                                IEnumerable <KeyValuePair <string, string> > simulatedAppConfigSettings)
        {
            NameValueCollection nameValueCollection = null;

            MembershipSection membership = ConfigurationManager.GetSection("system.web/membership") as MembershipSection;

            foreach (ProviderSettings settings in membership.Providers)
            {
                if (settings.Name == FixtureConstants.NameOfConfiguredMembershipProvider)
                {
                    nameValueCollection = new NameValueCollection(settings.Parameters);
                    break;
                }
            }

            if (nameValueCollection == null)
            {
                throw new Exception("Configuration not found for membership provider RavenDBMembership.");
            }

            nameValueCollection["connectionStringName"] = "StubConnectionString";

            foreach (var kvp in simulatedAppConfigSettings)
            {
                ValidateConfigurationValue(kvp.Key, kvp.Value);
                nameValueCollection.Set(kvp.Key, kvp.Value);
            }

            result.Initialize(FixtureConstants.NameOfConfiguredMembershipProvider, nameValueCollection);
        }
        static WCFMembershipConfigurationManager()
        {
            MembershipSection membershipSection =
                (MembershipSection)ConfigurationManager.GetSection("system.web/membership");

            if (membershipSection == null)
            {
                return;
            }
            string           providerName = membershipSection.DefaultProvider;
            ProviderSettings providerItem = membershipSection.Providers[providerName];

            if (providerItem == null)
            {
                return;
            }

            Type type = Type.GetType(providerItem.Type);

            if (type == null || !(Activator.CreateInstance(type) is WCFTenantMembershipProvider))
            {
                return;
            }

            _enablePasswordReset = string.IsNullOrEmpty(providerItem.Parameters["enablePasswordReset"]) ? true :
                                   Convert.ToBoolean(providerItem.Parameters["enablePasswordReset"]);
            _minRequiredNonAlphanumericCharacters = Convert.ToInt32(providerItem.Parameters["minRequiredNonAlphanumericCharacters"]);
            _minRequiredPasswordLength            = Convert.ToInt32(providerItem.Parameters["minRequiredPasswordLength"]);
            _passwordStrengthRegularExpression    = providerItem.Parameters["passwordStrengthRegularExpression"];
            if (_passwordStrengthRegularExpression == null)
            {
                _passwordStrengthRegularExpression = string.Empty;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the connection string for the provider.
        /// </summary>
        /// <param name="providerName">The name of the provider.</param>
        /// <returns>The connection string.</returns>
        private string GetConnectionString(string providerName)
        {
            string connStr = string.Empty;

            try
            {
                MembershipSection configSection = (MembershipSection)HttpContext.Current.GetSection("system.web/membership");

                ProviderSettings providerItem = configSection.Providers[providerName];
                if (providerItem != null)
                {
                    string connStrName = providerItem.Parameters["connectionStringName"];
                    if (!string.IsNullOrEmpty(connStrName))
                    {
                        connStr = WebConfigurationManager.ConnectionStrings[connStrName].ConnectionString;
                    }
                }
            }
            catch (Exception e)
            {
                ULS.LogError("SQLSiteMembershipProvider.GetConnectionString", "No Connection String Retrieved for provider name: " + providerName + "\n" + e.ToString(), "Membership");
                throw new ProviderException(e.ToString());
            }

            return(connStr);
        }
Ejemplo n.º 6
0
        public static void _DefaultProvider(Page p)
        {
            MembershipSection section = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");

            Assert.AreEqual(section.DefaultProvider, "FakeProvider", "section.DefaultProvider");
            Assert.AreEqual(Membership.Provider.GetType(), typeof(FakeMembershipProvider), "Membership.Provider.GetType ()");
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public static ProviderSettings GetMembershipProvider(string providerName)
        {
            Configuration              config      = WebConfigurationManager.OpenWebConfiguration("~/");
            MembershipSection          section     = (MembershipSection)config.GetSection("system.web/membership");
            ProviderSettingsCollection settingsCol = section.Providers;

            return(settingsCol[providerName]);
        }
Ejemplo n.º 9
0
        public virtual void Setup()
        {
            // run the testsetupscript...
            this.ConnectionString = ConfigurationManager.ConnectionStrings["WorkmateDatabase"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open(); // this will throw an exception if we can't connect
            }

            string path = Path.Combine(this.ApplicationPath, @"DataAccess\SqlProvider\SetupScript.sql");
            string sql  = File.ReadAllText(path);

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open(); // this will throw an exception if we can't connect

                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = sql;
                    command.CommandType = System.Data.CommandType.Text;

                    command.ExecuteNonQuery();
                }
            }

            _SqlServerDataStore   = new SqlServerDataStore(this.ConnectionString);
            this.DummyDataManager = new DummyDataManager(Path.Combine(this.ApplicationPath, @"DataAccess\DummyData.xml"));

            this.DefaultUpdateTestIterations = 10;
            this.Random = new Random();

            ApplicationSettings applicationSettings = new ApplicationSettings(
                ConfigurationManager.AppSettings
                , ConfigurationManager.ConnectionStrings);

            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            MembershipSection configSection           = (MembershipSection)config.GetSection("system.web/membership");

            IMembershipSettings membershipSettings = new MembershipSettings(
                (NameValueCollection)configSection.Providers[configSection.DefaultProvider].Parameters);

            InstanceContainer.Initialize(_SqlServerDataStore, applicationSettings, membershipSettings);

            Workmate.Components.ApplicationManager applicationManger = new Workmate.Components.ApplicationManager(this.DataStore);
            this.Application = applicationManger.GetApplication("debug_test_setup");
            if (this.Application == null)
            {
                this.Application = new Workmate.Components.Entities.Application("debug_test_setup", "Auto generated at " + DateTime.UtcNow.ToString() + " (UTC)");

                var report = applicationManger.Create(this.Application);
                if (report.Status != DataRepositoryActionStatus.Success)
                {
                    throw new ApplicationException("Unable to create debug test setup");
                }
            }
        }
Ejemplo n.º 10
0
        static MembershipTests()
        {
            _emails = File.ReadAllLines("emails.txt").ToList();
            var list = new TestList();

            _membership = list.Membership;
            var deleteTask = _membership.UnsubscribeAllAsync();

            Task.WaitAll(deleteTask);
        }
Ejemplo n.º 11
0
        protected override void LoadStaticConfiguration()
        {
            base.LoadStaticConfiguration();

            ConnectionStringSettings css = new ConnectionStringSettings();

            css.ConnectionString = String.Format(
                "server={0};uid={1};password={2};database={3};pooling=false",
                BaseTest.host, BaseTest.user, BaseTest.password, BaseTest.database0);
            css.Name = "LocalMySqlServer";
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.ConnectionStrings.ConnectionStrings.Add(css);

            MembershipSection ms = (MembershipSection)config.SectionGroups["system.web"].Sections["membership"];

            ms.DefaultProvider = "MySQLMembershipProvider";
            ProviderSettings ps = new ProviderSettings();

            ps.Name = "MySQLMembershipProvider";
            Assembly a = Assembly.GetAssembly(typeof(MySQLMembershipProvider));

            ps.Type = "MySql.Web.Security.MySQLMembershipProvider, " + a.FullName;
            ps.Parameters.Add("connectionStringName", "LocalMySqlServer");
            ps.Parameters.Add("enablePasswordRetrieval", "false");
            ps.Parameters.Add("enablePasswordReset", "true");
            ps.Parameters.Add("requiresQuestionAndAnswer", "true");
            ps.Parameters.Add("applicationName", "/");
            ps.Parameters.Add("requiresUniqueEmail", "false");
            ps.Parameters.Add("passwordFormat", "Hashed");
            ps.Parameters.Add("maxInvalidPasswordAttempts", "5");
            ps.Parameters.Add("minRequiredPasswordLength", "7");
            ps.Parameters.Add("minRequiredNonalphanumericCharacters", "1");
            ps.Parameters.Add("passwordAttemptWindow", "10");
            ps.Parameters.Add("passwordStrengthRegularExpression", "");
            ms.Providers.Add(ps);

            RoleManagerSection rs = (RoleManagerSection)config.SectionGroups["system.web"].Sections["roleManager"];

            rs.DefaultProvider = "MySQLRoleProvider";
            rs.Enabled         = true;
            ps      = new ProviderSettings();
            ps.Name = "MySQLRoleProvider";
            a       = Assembly.GetAssembly(typeof(MySQLRoleProvider));
            ps.Type = "MySql.Web.Security.MySQLRoleProvider, " + a.FullName;
            ps.Parameters.Add("connectionStringName", "LocalMySqlServer");
            ps.Parameters.Add("applicationName", "/");
            rs.Providers.Add(ps);

            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");
            ConfigurationManager.RefreshSection("system.web/membership");
            ConfigurationManager.RefreshSection("system.web/roleManager");
        }
Ejemplo n.º 12
0
        public void get_default_provider_from_membership_section()
        {
            // Arrange
            MembershipSection membershipSection = _configSection.GetSection("system.web/membership") as MembershipSection;

            // Act
            string defaultProvider = membershipSection.DefaultProvider;

            // Assert
            Assert.AreEqual("AspNetSqlMembershipProvider", defaultProvider);
        }
Ejemplo n.º 13
0
        public static string GetApplicationName()
        {
            MembershipSection section = ConfigurationManager.GetSection("system.web/membership") as MembershipSection;

            //section.Providers.CurrentConfiguration.Sections.
            if (section != null)
            {
                return(section.Providers["SqlMembershipProvider"].Parameters["applicationName"]);
            }
            return(string.Empty);
        }
Ejemplo n.º 14
0
        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;
        }
Ejemplo n.º 15
0
        public void get_the_minRequiredNonalphanumericCharacters_from_the_membership_section()
        {
            // Arrange
            MembershipSection membershipSection = _configSection.GetSection("system.web/membership") as MembershipSection;

            // Act
            string           defaultProvider = membershipSection.DefaultProvider;
            ProviderSettings settings        = membershipSection.Providers[defaultProvider];
            int actual = Convert.ToInt32(settings.Parameters["minRequiredNonalphanumericCharacters"]);

            // Assert
            Assert.AreEqual(3, actual);
        }
Ejemplo n.º 16
0
 private static void Initialize()
 {
     if (!s_Initialized || !s_InitializedDefaultProvider)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
         if (HostingEnvironment.IsHosted)
         {
             HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
         }
         lock (s_lock)
         {
             if (!s_Initialized || !s_InitializedDefaultProvider)
             {
                 if (s_InitializeException != null)
                 {
                     throw s_InitializeException;
                 }
                 bool initializeGeneralSettings = !s_Initialized;
                 bool initializeDefaultProvider = !s_InitializedDefaultProvider && (!HostingEnvironment.IsHosted || (BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit));
                 if (initializeDefaultProvider || initializeGeneralSettings)
                 {
                     bool flag3;
                     bool flag4 = false;
                     try
                     {
                         RuntimeConfig     appConfig  = RuntimeConfig.GetAppConfig();
                         MembershipSection membership = appConfig.Membership;
                         flag3 = InitializeSettings(initializeGeneralSettings, appConfig, membership);
                         flag4 = InitializeDefaultProvider(initializeDefaultProvider, membership);
                     }
                     catch (Exception exception)
                     {
                         s_InitializeException = exception;
                         throw;
                     }
                     if (flag3)
                     {
                         s_Initialized = true;
                     }
                     if (flag4)
                     {
                         s_InitializedDefaultProvider = true;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
        protected override ProviderSettings GetMachineSettings()
        {
            Configuration     machineConfig = ConfigurationManager.OpenMachineConfiguration();
            MembershipSection section       = (MembershipSection)machineConfig.SectionGroups["system.web"].Sections[sectionName];

            foreach (ProviderSettings p in section.Providers)
            {
                if (p.Type.Contains(typeName))
                {
                    return(p);
                }
            }
            return(null);
        }
Ejemplo n.º 18
0
        protected void EnsureApplicationNameSpecified(out string appName)
        {
            string mem   = null;
            string roles = null;

            // Membership
            try
            {
                MembershipSection section          = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
                string            defaultProvider  = section.DefaultProvider;
                ProviderSettings  providerSettings = section.Providers[defaultProvider];
                mem = providerSettings.Parameters["applicationName"];
            }
            catch (Exception)
            {
                throw new Exception(Membership_missing_application_name);
            }
            if (null == mem)
            {
                throw new Exception(Membership_missing_application_name);
            }


            // Roles
            try
            {
                RoleManagerSection section          = (RoleManagerSection)WebConfigurationManager.GetSection("system.web/roleManager");
                string             defaultProvider  = section.DefaultProvider;
                ProviderSettings   providerSettings = section.Providers[defaultProvider];
                roles = providerSettings.Parameters["applicationName"];
            }
            catch (Exception)
            {
                throw new Exception(Roles_missing_application_name);
            }
            if (null == roles)
            {
                throw new Exception(Roles_missing_application_name);
            }


            // match?
            if (roles != mem)
            {
                throw new Exception(Application_names_must_match);
            }

            appName = mem;
        }
Ejemplo n.º 19
0
        public void TestInitialize()
        {
            base.Initialize();

            HttpContext.Current = (new MockHttpContext(false)).Context;
            HttpContext.Current.Session["org"] = "sugarcreek";

            _provider = new LiftMembershipProvider();

            MembershipSection          section          = (MembershipSection)ConfigurationManager.GetSection("system.web/membership");
            ProviderSettingsCollection settings         = section.Providers;
            NameValueCollection        membershipParams = settings[section.DefaultProvider].Parameters;

            _provider.Initialize(section.DefaultProvider, membershipParams);
        }
Ejemplo n.º 20
0
        void ProcessReplace(MembershipSection 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);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Determines whether the simple membership provider is configured for the current application.
        /// </summary>
        /// <param name="configurationfile">The full path to the configuration file.</param>
        /// <returns>
        ///   <c>true</c> if the application is using simple membership; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsSimpleMembershipProviderConfigured(string configurationfile)
        {
            if (BaseApplication.simpleMembership.HasValue)
            {
                return(BaseApplication.simpleMembership.Value);
            }
            bool enabled;

            // check the appsettings value first
            Boolean.TryParse(!string.IsNullOrEmpty(ConfigurationManager.AppSettings[WebSecurity.EnableSimpleMembershipKey]) ?
                             ConfigurationManager.AppSettings[WebSecurity.EnableSimpleMembershipKey] : "false", out enabled);
            if (!enabled)
            {
                BaseApplication.simpleMembership = false;
                return(BaseApplication.simpleMembership.Value);
            }

            // next get the configuration and check for the provider
            System.Configuration.Configuration configuration = null;
            if (configurationfile.ToLower().EndsWith("web.config"))
            {
                configuration = WebConfigurationManager.OpenWebConfiguration(configurationfile);
            }
            else
            {
                configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            }

            if (configuration != null)
            {
                MembershipSection membershipSection = configuration.GetSection("system.web/membership") as MembershipSection;
                if (membershipSection != null)
                {
                    string defaultprovider = membershipSection.DefaultProvider;
                    foreach (ProviderSettings provider in membershipSection.Providers)
                    {
                        if (provider.Name == defaultprovider && provider.Type.Contains("WebMatrix.WebData.SimpleMembershipProvider"))
                        {
                            BaseApplication.simpleMembership = true;
                            return(BaseApplication.simpleMembership.Value);
                        }
                    }
                }
            }
            BaseApplication.simpleMembership = false;
            return(BaseApplication.simpleMembership.Value);
        }
Ejemplo n.º 22
0
        private string EncodePassword(string password, MembershipPasswordFormat passwordFormat, string salt)
        {
            byte [] password_bytes;
            byte [] salt_bytes;

            switch (passwordFormat)
            {
            case MembershipPasswordFormat.Clear:
                return(password);

            case MembershipPasswordFormat.Hashed:
                password_bytes = Encoding.Unicode.GetBytes(password);
                salt_bytes     = Convert.FromBase64String(salt);

                byte [] hashBytes = new byte [salt_bytes.Length + password_bytes.Length];

                Buffer.BlockCopy(salt_bytes, 0, hashBytes, 0, salt_bytes.Length);
                Buffer.BlockCopy(password_bytes, 0, hashBytes, salt_bytes.Length, password_bytes.Length);

                MembershipSection section  = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
                string            alg_type = section.HashAlgorithmType;
                if (alg_type == "")
                {
                    MachineKeySection keysection = (MachineKeySection)WebConfigurationManager.GetSection("system.web/machineKey");
                    alg_type = keysection.Validation.ToString();
                }
                using (HashAlgorithm hash = HashAlgorithm.Create(alg_type)) {
                    hash.TransformFinalBlock(hashBytes, 0, hashBytes.Length);
                    return(Convert.ToBase64String(hash.Hash));
                }

            case MembershipPasswordFormat.Encrypted:
                password_bytes = Encoding.Unicode.GetBytes(password);
                salt_bytes     = Convert.FromBase64String(salt);

                byte [] buf = new byte [password_bytes.Length + salt_bytes.Length];

                Array.Copy(salt_bytes, 0, buf, 0, salt_bytes.Length);
                Array.Copy(password_bytes, 0, buf, salt_bytes.Length, password_bytes.Length);

                return(Convert.ToBase64String(EncryptPassword(buf)));

            default:
                /* not reached.. */
                return(null);
            }
        }
Ejemplo n.º 23
0
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (config == null)
            {
                string                     configPath      = "~/web.config";
                Configuration              newConfig       = WebConfigurationManager.OpenWebConfiguration(configPath);
                MembershipSection          mbershipSection = (MembershipSection)newConfig.GetSection("system.web/membership");
                ProviderSettingsCollection setting         = mbershipSection.Providers;
                NameValueCollection        mbershipParams  = setting[mbershipSection.DefaultProvider].Parameters;
                config = mbershipParams;
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "CustomMembershipProvider";
            }

            base.Initialize(name, config);
        }
Ejemplo n.º 24
0
    protected void ChangeButton_Click(object sender, EventArgs e)
    {
        MembershipSection section = (MembershipSection)ConfigurationManager.GetSection("system.web/membership");

        DL_WEB.BLL.DLMembershipProvider MembershipProvider = new DL_WEB.BLL.DLMembershipProvider();
        MembershipProvider.Initialize(Login.Text, section.Providers[section.DefaultProvider].Parameters);
        bool Result = MembershipProvider.ChangePassword(Login.Text, null, NewPassword.Text);

        if (Result)
        {
            Response.Redirect("UserList.aspx");
        }
        else
        {
            ErrorLabel.Visible = true;
            ErrorLabel.Text    = string.Format(ErrorLabel.Text, MembershipProvider.MinRequiredPasswordLength, MembershipProvider.MinRequiredNonAlphanumericCharacters);
        }
    }
Ejemplo n.º 25
0
        public object MapSection(object _section, List <SettingsMappingWhat> whats)
        {
            MembershipSection section = _section as MembershipSection;

            if (section == null)
            {
                return(_section);
            }

            List <SettingsMappingWhatContents> contents;

            foreach (SettingsMappingWhat what in whats)
            {
                contents = what.Contents;
                if (contents == null || contents.Count == 0)
                {
                    continue;
                }

                foreach (SettingsMappingWhatContents item in contents)
                {
                    switch (item.Operation)
                    {
                    case SettingsMappingWhatOperation.Add:
                        ProcessAdd(section, item);
                        break;

                    case SettingsMappingWhatOperation.Clear:
                        ProcessClear(section, item);
                        break;

                    case SettingsMappingWhatOperation.Replace:
                        ProcessReplace(section, item);
                        break;

                    case SettingsMappingWhatOperation.Remove:
                        ProcessRemove(section, item);
                        break;
                    }
                }
            }

            return(section);
        }
Ejemplo n.º 26
0
        internal static void SetPrividerSettings(MembershipSection membershipSection, string connectionStringName)
        {
            membershipSection.DefaultProvider = ProviderName;
            ProviderSettings providerSettings = membershipSection.Providers[ProviderName];

            if (providerSettings == null)
            {
                providerSettings = new ProviderSettings(ProviderName, "Unicorn.Web.Security.UniMembershipProvider");                  //this.GetType().Name
                providerSettings.Parameters["enablePasswordRetrieval"]              = "false";
                providerSettings.Parameters["connectionStringName"]                 = connectionStringName;
                providerSettings.Parameters["enablePasswordReset"]                  = "true";
                providerSettings.Parameters["requiresQuestionAndAnswer"]            = "true";
                providerSettings.Parameters["requiresUniqueEmail"]                  = "true";
                providerSettings.Parameters["passwordFormat"]                       = "Clear";
                providerSettings.Parameters["minRequiredNonalphanumericCharacters"] = "0";
                providerSettings.Parameters["minRequiredPasswordLength"]            = "4";
                providerSettings.Parameters["applicationName"]                      = "/";
                membershipSection.Providers.Add(providerSettings);
            }
        }
Ejemplo n.º 27
0
        void ProcessRemove(MembershipSection 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);
            }
        }
Ejemplo n.º 28
0
        public static string GetApplicationName()
        {
            Configuration     conf     = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            MembershipSection mSection = new MembershipSection();

            mSection = (MembershipSection)conf.GetSection("system.web/membership");

            string appName = mSection.Providers[mSection.DefaultProvider].Parameters["applicationName"];

            if (string.IsNullOrEmpty(appName))
            {
                appName = System.Web.HttpContext.Current.Request.Url.Host;

                if (System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath != "/")
                {
                    appName += System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
                }
            }

            return(appName);
        }
Ejemplo n.º 29
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static DispatcherInfo RetriveDispatcherInfo()
        {
            DispatcherInfo dispatcherInfo = new DispatcherInfo();

            try
            {
                dispatcherInfo.MachineIp = Fwk.HelperFunctions.EnvironmentFunctions.GetMachineIp();
            }
            catch (Exception e)
            {
                dispatcherInfo.MachineIp = e.Message;
            }
            List <MetadataProvider> list = new List <MetadataProvider>();

            foreach (ServiceProviderElement providerElement in ServiceMetadata.ProviderSection.Providers)
            {
                list.Add(new MetadataProvider(providerElement));
            }
            dispatcherInfo.MetadataProviders = list;


            dispatcherInfo.ServiceDispatcherConnection = System.Configuration.ConfigurationManager.AppSettings["ServiceDispatcherConnection"];
            dispatcherInfo.ServiceDispatcherName       = System.Configuration.ConfigurationManager.AppSettings["ServiceDispatcherName"];

            foreach (string key in System.Configuration.ConfigurationManager.AppSettings)
            {
                dispatcherInfo.AppSettings.Add(key, System.Configuration.ConfigurationManager.AppSettings[key.ToString()].ToString());
            }

            foreach (System.Configuration.ConnectionStringSettings cnnStringSetting in System.Configuration.ConfigurationManager.ConnectionStrings)
            {
                dispatcherInfo.CnnStringSettings.Add(cnnStringSetting.Name, cnnStringSetting.ConnectionString);
            }

            MembershipSection wMembershipSection = (MembershipSection)System.Configuration.ConfigurationManager.GetSection("system.web/membership");


            return(dispatcherInfo);
        }
Ejemplo n.º 30
0
 // VSO #265267 we want to log a warning in the event log, whenever detect using clear password or encrypted password formats settings in Membership provider
 // VSO #433626 In order to minimize the behavior change, we are going to read the password format from the config settings only instead of getting from the provider class
 private static void CheckedPasswordFormat(MembershipSection settings)
 {
     //VSO #294931 Since this is an optional feature, we want to prevent any corner cases that were not able to return the password format. In those cases, we will just do nothing and not log any warnings.
     try {
         if (settings != null && settings.Providers != null)
         {
             foreach (ProviderSettings ps in settings.Providers)
             {
                 if (ps != null && ps.Parameters != null)
                 {
                     string passwordFormat = ps.Parameters["passwordFormat"];
                     if (StringUtil.EqualsIgnoreCase(passwordFormat, "Clear") || StringUtil.EqualsIgnoreCase(passwordFormat, "Encrypted"))
                     {
                         string providerName = ps.Name ?? string.Empty;
                         WebBaseEvent.RaiseRuntimeError(new ConfigurationErrorsException(SR.GetString(SR.MembershipPasswordFormat_Obsoleted, providerName, passwordFormat)), typeof(MembershipProvider));
                     }
                 }
             }
         }
     }
     catch { }
 }