Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 private void SocketClient_ExceptionEvent(object sender, ProviderException e)
 {
     if (e.InnerException is SocketException)
     {
         Reconnection();
         number++;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call
        /// <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider
        /// has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
        public override void Initialize(string name, NameValueCollection config)
        {
            // Initialize base provider class
            base.Initialize(name, config);

            _enablePasswordRetrieval              = config.GetValue("enablePasswordRetrieval", false);
            _enablePasswordReset                  = config.GetValue("enablePasswordReset", true);
            _requiresQuestionAndAnswer            = config.GetValue("requiresQuestionAndAnswer", false);
            _requiresUniqueEmail                  = config.GetValue("requiresUniqueEmail", true);
            _maxInvalidPasswordAttempts           = GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0);
            _passwordAttemptWindow                = GetIntValue(config, "passwordAttemptWindow", 10, false, 0);
            _minRequiredPasswordLength            = GetIntValue(config, "minRequiredPasswordLength", DefaultMinPasswordLength, true, 0x80);
            _minRequiredNonAlphanumericCharacters = GetIntValue(config, "minRequiredNonalphanumericCharacters", DefaultMinNonAlphanumericChars, true, 0x80);
            _passwordStrengthRegularExpression    = config["passwordStrengthRegularExpression"];

            _applicationName = config["applicationName"];
            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = GetDefaultAppName();
            }

            //by default we will continue using the legacy encoding.
            UseLegacyEncoding = config.GetValue("useLegacyEncoding", DefaultUseLegacyEncoding);

            // make sure password format is Hashed by default.
            string str = config["passwordFormat"] ?? "Hashed";

            switch (str.ToLower())
            {
            case "clear":
                _passwordFormat = MembershipPasswordFormat.Clear;
                break;

            case "encrypted":
                _passwordFormat = MembershipPasswordFormat.Encrypted;
                break;

            case "hashed":
                _passwordFormat = MembershipPasswordFormat.Hashed;
                break;

            default:
                throw new ProviderException("Provider bad password format");
            }

            if ((PasswordFormat == MembershipPasswordFormat.Hashed) && EnablePasswordRetrieval)
            {
                var ex = new ProviderException("Provider can not retrieve a hashed password");
                Current.Logger.Error <MembershipProviderBase>(ex, "Cannot specify a Hashed password format with the enabledPasswordRetrieval option set to true");
                throw ex;
            }

            _customHashAlgorithmType = config.GetValue("hashAlgorithmType", string.Empty);
        }
Ejemplo n.º 4
0
 void Photos_OnError(ProviderException ex)
 {
     Console.Error.WriteLine(ex.Message);
     Assert.Fail(ex.StackTrace);
 }
Ejemplo n.º 5
0
 void Comments_OnError(ProviderException ex)
 {
     Console.Out.WriteLine(ex.Message);
     Assert.Fail(ex.StackTrace);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call
        /// <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider
        /// has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (string.IsNullOrEmpty(name))
            {
                name = ProviderName;
            }

            // Initialize base provider class
            base.Initialize(name, config);

            _applicationName = string.IsNullOrEmpty(config["applicationName"]) ? GetDefaultAppName() : config["applicationName"];

            _enablePasswordRetrieval              = GetBooleanValue(config, "enablePasswordRetrieval", false);
            _enablePasswordReset                  = GetBooleanValue(config, "enablePasswordReset", false);
            _requiresQuestionAndAnswer            = GetBooleanValue(config, "requiresQuestionAndAnswer", false);
            _requiresUniqueEmail                  = GetBooleanValue(config, "requiresUniqueEmail", true);
            _maxInvalidPasswordAttempts           = GetIntValue(config, "maxInvalidPasswordAttempts", 5, false, 0);
            _passwordAttemptWindow                = GetIntValue(config, "passwordAttemptWindow", 10, false, 0);
            _minRequiredPasswordLength            = GetIntValue(config, "minRequiredPasswordLength", 7, true, 0x80);
            _minRequiredNonAlphanumericCharacters = GetIntValue(config, "minRequiredNonalphanumericCharacters", 1, true, 0x80);
            _passwordStrengthRegularExpression    = config["passwordStrengthRegularExpression"];

            // make sure password format is Hashed by default.
            var str = config["passwordFormat"] ?? "Hashed";

            LogHelper.Debug <MembersMembershipProvider>("Loaded membership provider properties");
            LogHelper.Debug <MembersMembershipProvider>(ToString());

            switch (str.ToLower())
            {
            case "clear":
                _passwordFormat = MembershipPasswordFormat.Clear;
                break;

            case "encrypted":
                _passwordFormat = MembershipPasswordFormat.Encrypted;
                break;

            case "hashed":
                _passwordFormat = MembershipPasswordFormat.Hashed;
                break;

            default:
                var e = new ProviderException("Provider bad password format");
                LogHelper.Error <MembersMembershipProvider>(e.Message, e);
                throw e;
            }

            if ((PasswordFormat == MembershipPasswordFormat.Hashed) && EnablePasswordRetrieval)
            {
                var e = new ProviderException("Provider can not retrieve hashed password");
                LogHelper.Error <MembersMembershipProvider>(e.Message, e);
                throw e;
            }

            // TODO: rationalise what happens when no member alias is specified....
            DefaultMemberTypeAlias = config["defaultMemberTypeAlias"];

            LogHelper.Debug <MembersMembershipProvider>("Finished initialising member ship provider " + GetType().FullName);
        }
Ejemplo n.º 7
0
 void Photos_OnError(ProviderException providerException)
 {
     Logging.Logger.Error(providerException.Message, providerException);
 }
    public override void Initialize(String name, NameValueCollection config)
    {
        // if the parameter name is empty, use the default name
        if (name == null || name.Trim() == String.Empty)
        {
            name = _name;
        }

        // if no configuration attributes found, throw an exception
        if (config == null)
        {
            throw new ArgumentNullException("config", "There are no configuration attributes in web.config!");
        }

        // if no 'description' attribute in the configuration, use the default
        String cfg_description = config["description"];
        if (cfg_description == null || cfg_description.Trim() == "")
        {
            config.Remove("description");
            config.Add("description", _description);
        }

        // if there is no 'connectionStringName' in the configuration, throw an exception
        // otherwise extract the connection string from the web.config
        // and test it, if it is not working throw an exception
        String cfg_connectionStringName = config["connectionStringName"];
        if (cfg_connectionStringName == null || cfg_connectionStringName.Trim() == "")
        {
            throw new ProviderException("Provider configuration attribute 'connectionStringName' in web.config is missing or blank!");
        }
        else
        {
            // get the entry refrenced by the 'connectionStringName'
            ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[cfg_connectionStringName];

            // if you can't find the entry defined by the 'connectionStringName' or it is empty, throw an exception
            if (connObj != null && connObj.ConnectionString != null && connObj.ConnectionString.Trim() != "")
            {
                try
                {
                    // try testing the connection
                    using (SqlConnection conn = new SqlConnection(connObj.ConnectionString))
                    {
                        conn.Open();
                        _connectionStringName = connObj.ConnectionString;
                    }
                }
                catch (Exception e)
                {
                    // if anything wrong happened, throw an exception showing what happened
                    ProviderException pException = new ProviderException(
                        String.Format("Connection string '{0}' in web.config is not usable!", cfg_connectionStringName), e);

                    throw pException;
                }
            }
            else
            {
                throw new ProviderException(String.Format("Connection string '{0}' in web.config is missing or blank!",
                    cfg_connectionStringName));
            }
        }

        // if there is no 'commandTimeout' attribute in the configuration, use the default
        // otherwise try to get it, if errors ocurred, throw an exception
        String cfg_commandTimeout = config["commandTimeout"];
        if (cfg_commandTimeout == null || cfg_commandTimeout.Trim() == String.Empty)
        {

        }
        else
        {
            Int32 _ct;

            if (Int32.TryParse(cfg_commandTimeout, out _ct) && _ct >= 0)
            {
                _commandTimeout = _ct;
            }
            else
            {
                throw new ProviderException("Provider property 'commandTimeout' in web.config is not valid!");
            }
        }

        // initialize the SqlProfileProvider with the current parameters
        base.Initialize(name, config);

        // throw an exception if unrecognized attributes remain
        if (config.Count > 0)
        {
            String strAttributes = "";

            for (int i = 0; i < config.Count; i++)
            {
                strAttributes += config.GetKey(i);

                if (i < config.Count - 1)
                {
                    strAttributes += ", ";
                }
            }

            throw new ProviderException(String.Format("Unrecognized attribute(s): {0}", strAttributes));
        }
    }
Ejemplo n.º 9
0
 void Photos_OnError(ProviderException providerException)
 {
     throw new NotImplementedException();
 }