예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbAuthenticationProvider"/> class
        /// </summary>
        /// <exception cref="AuthConfigurationException">Missing or invalid configuration at .config</exception>
        public DbAuthenticationProvider()
        {
            AuthUtils.ValidateConfig(ConfigManager.Instance.Config.DBAuth, this.GetType());
            AuthUtils.ValidateConfig(ConfigManager.Instance.Config.DBAuth.Authentication, this.GetType());
            string connectionStringName = ConfigManager.Instance.Config.DBAuth.Authentication.ConnectionStringName;

            if (string.IsNullOrEmpty(connectionStringName))
            {
                throw new AuthConfigurationException(Errors.DbAuthMissingConnectionStringName);
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionStringName];

            if (connectionStringSettings == null)
            {
                throw new AuthConfigurationException(Errors.DbAuthMissingConnectionStringName);
            }

            if (!AuthUtils.ValidateContains(this._selectQuery, DbConstants.UserMacro))
            {
                string invalidQuery = string.Format(
                    CultureInfo.CurrentCulture, Errors.DbAuthenticationInvalidSqlQuery, DbConstants.UserMacro);
                throw new AuthConfigurationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Errors.DbAuthInvalidSqlQuery,
                              this.GetType().Name,
                              invalidQuery));
            }

            this._database = new Database(connectionStringSettings);
            string userParam = this._database.BuildParameterName(DbConstants.UserParamName);

            this._query = this._selectQuery.Replace(DbConstants.UserMacro, userParam);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbAuthorizationProvider"/> class.
        /// Initialize a new instance of the <see cref="DbAuthorizationProvider"/> class
        /// </summary>
        public DbAuthorizationProvider()
        {
            // check configuration
            AuthUtils.ValidateConfig(ConfigManager.Instance.Config.DBAuth, this.GetType());
            AuthUtils.ValidateConfig(ConfigManager.Instance.Config.DBAuth.Authorization, this.GetType());

            string connectionStringName = ConfigManager.Instance.Config.DBAuth.Authorization.ConnectionStringName;

            if (string.IsNullOrEmpty(connectionStringName))
            {
                connectionStringName = ConfigManager.Instance.Config.DBAuth.Authentication != null
                                           ? ConfigManager.Instance.Config.DBAuth.Authentication.ConnectionStringName
                                           : null;
            }

            if (string.IsNullOrEmpty(connectionStringName))
            {
                throw new AuthConfigurationException(Errors.DbAuthMissingConnectionStringName);
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionStringName];

            if (connectionStringSettings == null)
            {
                throw new AuthConfigurationException(Errors.DbAuthMissingConnectionStringName);
            }

            this._selectQuery = ConfigManager.Instance.Config.DBAuth.Authorization.Sql;
            if (
                !AuthUtils.ValidateContains(
                    this._selectQuery,
                    DbConstants.UserMacro,
                    DbConstants.DataflowIdMacro,
                    DbConstants.DataflowVersionMacro,
                    DbConstants.DataflowAgencyIdMacro))
            {
                string missingMessage = string.Format(
                    CultureInfo.CurrentCulture,
                    Errors.DbAuthMissingConnectionStringName,
                    DbConstants.DataflowIdMacro,
                    DbConstants.DataflowVersionMacro,
                    DbConstants.DataflowAgencyIdMacro,
                    DbConstants.UserMacro);
                throw new AuthConfigurationException(
                          string.Format(
                              CultureInfo.CurrentCulture, Errors.DbAuthInvalidSqlQuery, this.GetType().Name, missingMessage));
            }

            this._database = new Database(connectionStringSettings);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NsiAuthModule"/> class.
        /// Create a new instance of the <see cref="NsiAuthModule"/> class
        /// </summary>
        public NsiAuthModule()
        {
            _log.Debug("Starting SRI Authentication and dataflow authorization module.");
            AuthUtils.ValidateConfig(ConfigManager.Instance.Config, this.GetType());
            this._userCred = UserCredentialsFactory.Instance.CreateUserCredentials();

            this._authentication = AuthenticationProviderFactory.Instance.CreateAuthenticationProvider();

            this._realm = ConfigManager.Instance.Config.Realm;

            string anonUser = ConfigManager.Instance.Config.AnonymousUser;

            if (!string.IsNullOrEmpty(anonUser))
            {
                this._anonUser = UserFactory.Instance.CreateUser(this._realm);
                if (this._anonUser != null)
                {
                    this._anonUser.UserName = anonUser;
                }
            }
        }