Exemple #1
0
        /// <summary>
        /// Loads the default security policy
        /// </summary>
        private void LoadDefaultSecurityPolicy(IIpSecurityPolicy policy)
        {
            var helper = new IpSettingsFactory().GetSettingsHelper((IIpConfigurationSettingsHelper)null);
            var providerFullyQualifiedType = helper.GetSetting(IpArgument.GetConfigAppSetting("AuthProvider")).ToString();

            try
            {
                var providerType = Type.GetType(providerFullyQualifiedType);
                policy.Provider = (OAuthAuthorizationServerProvider)Activator.CreateInstance(providerType);
            }
            catch
            {
                //load the default provider
                policy.Provider = new IpAuthorizationServerProvider();
            }

            //Load values from configuration
            policy.PasswordComplexityRegex         = helper.GetSetting(IpArgument.GetConfigAppSetting("PasswordComplexityRegex")).ToString();
            policy.AuthenticationEndpoint          = helper.GetSetting(IpArgument.GetConfigAppSetting("AuthenticationEndpoint")).ToString();
            policy.MinimumPasswordLength           = helper.GetSetting(IpArgument.GetConfigAppSetting("MinimumPasswordLength")).ChangeType <int>();
            policy.MaximumPasswordLength           = helper.GetSetting(IpArgument.GetConfigAppSetting("MaximumPasswordLength")).ChangeType <int>();
            policy.PasswordExpirationInDays        = helper.GetSetting(IpArgument.GetConfigAppSetting("PasswordExpirationInDays")).ChangeType <int>();
            policy.AuthTokenExpirationMinutes      = helper.GetSetting(IpArgument.GetConfigAppSetting("AuthTokenExpirationMinutes")).ChangeType <int>();
            policy.LockoutAttemptCount             = helper.GetSetting(IpArgument.GetConfigAppSetting("LockoutAttemptCount")).ChangeType <int>();
            policy.RequireRegistrationConfirmation = helper.GetSetting(IpArgument.GetConfigAppSetting("RequireRegistrationConfirmation")).ToBool();
            policy.UseTwoFactorAuthentication      = helper.GetSetting(IpArgument.GetConfigAppSetting("UseTwoFactorAuthentication")).ToBool();
            policy.UseSecurityQuestions            = helper.GetSetting(IpArgument.GetConfigAppSetting("UseSecurityQuestions")).ToBool();
            policy.AllowInsecureHttp = helper.GetSetting(IpArgument.GetConfigAppSetting("AllowInsecureHttp")).ToBool();
            policy.AllowCors         = helper.GetSetting(IpArgument.GetConfigAppSetting("AllowCors")).ToBool();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var configHelper = new IpSettingsFactory().GetSettingsHelper(null);
            var connString   = (ConnectionStringSettings)configHelper.GetSetting(IpArgument.GetConfigConnString("Connection"));
            var allowCors    = configHelper.GetSetting(IpArgument.GetConfigAppSetting("AllowCors"));

            Console.WriteLine(connString.ConnectionString);
            Console.WriteLine(allowCors);
            Console.ReadKey();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connectionString">The Connection String</param>
        /// <param name="provider">The Provider for the connection</param>
        protected IpBaseDataLayer(string connectionString, string provider)
        {
            ConnectionString = connectionString;
            ProviderFactory  = DbProviderFactories.GetFactory(provider);
            DatabaseProvider = provider;

            var configHelper = new IpSettingsFactory().GetSettingsHelper((IIpConfigurationSettingsHelper)null);

            QueryTimeout = configHelper.GetSetting(IpArgument.GetConfigAppSetting("QueryTimeoutInSeconds")).ChangeType <int>();
        }
        /// <summary>
        /// Gets the datalayer using the connection string from the config file
        /// </summary>
        /// <param name="connectionStringName">The connection string name</param>
        /// <param name="useDefault">If not provided, should it use the default provider name</param>
        /// <returns>An instantiated data layer of the provider type from the connection string</returns>
        public virtual IIpBaseDataLayer GetDataLayer(string connectionStringName, bool useDefault = false)
        {
            #region Validations
            var exceptions = IpValidationHelper.Validate(new List <IIpValidator> {
                new IpRequiredStringValidator(connectionStringName)
            });


            if (exceptions.Any())
            {
                throw new IpDataAccessException(string.Join(" | ", exceptions));
            }
            #endregion

            var configHelper = new IpSettingsFactory().GetSettingsHelper((IIpConfigurationSettingsHelper)null);
            var connString   = (ConnectionStringSettings)configHelper.GetSetting(IpArgument.GetConfigConnString(connectionStringName));

            return(GetDataLayerByProvider(connString.ConnectionString, connString.ProviderName, useDefault));
        }
        /// <summary>
        /// Gets the datalayer from the database provider
        /// </summary>
        /// <param name="connectionString">The connection string</param>
        /// <param name="providerName">The provider name</param>
        /// <param name="useDefault">If not provided, should it use the default provider name</param>
        /// <returns>An instantiated data layer of the provider type</returns>
        public IIpBaseDataLayer GetDataLayerByProvider(string connectionString, string providerName, bool useDefault = false)
        {
            if (string.IsNullOrWhiteSpace(providerName) && useDefault)
            {
                var configHelper    = new IpSettingsFactory().GetSettingsHelper((IIpConfigurationSettingsHelper)null);
                var defaultProvider = configHelper.GetSetting(IpArgument.GetConfigAppSetting("DefaultDatabaseProvider")).ToString();

                providerName = defaultProvider;
            }

            if (providerName.Equals("MySql.Data.MySqlClient", StringComparison.OrdinalIgnoreCase))
            {
                return(GetDataLayer(connectionString, (IpMySqlDataLayer)null));
            }

            if (providerName.Equals("System.Data.SqlClient", StringComparison.OrdinalIgnoreCase))
            {
                return(GetDataLayer(connectionString, (IpMsSqlDataLayer)null));
            }

            return(GetExtendedDataLayerByProvider(connectionString, providerName));
        }