public void Bootstrap(TypeNameReference configSource, ConfigurationProviderBase initialConfig)
 {
     lock (this.syncRoot)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             this.State = RunState.Bootstrapping;
             if (configSource != null)
             {
                 this.initialProv = initialConfig;
                 ConfigurationFactoryBase configFinal = NameReflectionUtils.CreateInstance <ConfigurationFactoryBase>(configSource);
                 if (configFinal != null)
                 {
                     if (configFinal.Initialize())
                     {
                         this.provider = configFinal;
                         this.State    = RunState.Bootstrapped;
                         return;
                     }
                     else
                     {
                         this.provider = null;
                     }
                 }
             }
             this.State = RunState.FailedBootstrapping;
         }
     }
 }
Esempio n. 2
0
        public void Initialize(TypeNameReference providerFactory)
        {
            lock (instance)
            {
                if (RuntimeUtils.Initializable(this.State) || this.State == RunState.Initializing)
                {
                    this.State = RunState.Initializing;
                    string meth = "Initialize";
                    if (this.logger == null)                     //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(InstrumentManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (providerFactory != null)
                    {
                        this.factory = NameReflectionUtils.CreateInstance <InstrumentProviderFactoryBase>(providerFactory);
                        if (this.factory != null)
                        {
                            if (this.factory.Initialize())
                            {
                                this.factory.LocalContext = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Initialized;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to initialize provider factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to create permission factory instance");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No typename provided");
                    }
                    this.State = RunState.FailedInitializing;
                }
            }
        }
Esempio n. 3
0
 public void Bootstrap(TypeNameReference logfactory)
 {
     lock (this.syncRoot)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             this.State = RunState.Bootstrapping;
             if (logfactory != null)
             {
                 this.provider = new MemoryLoggerFactory();
                 this.provider.Initialize();
                 if (!logfactory.Equals(TypeNameReference.Create(typeof(MemoryLoggerFactory)))) //confirm we're not just using memory logger
                 {
                     LogProviderFactory configFinal = NameReflectionUtils.CreateInstance <LogProviderFactory>(logfactory);
                     if (configFinal != null)
                     {
                         if (configFinal.Initialize())
                         {
                             this.provider = configFinal; //for the time being
                             foreach (LogItem cur in MemoryLoggerFactory.Items)
                             {
                                 LogProviderBase log = this.provider.GetLogger(NameReflectionUtils.GetType(cur.TypeName));
                                 if (log != null)
                                 {
                                     log.Log(cur.Severity, cur.Message);
                                 }
                             }
                             MemoryLoggerFactory.Items.Clear();
                             this.State = RunState.Bootstrapped;
                             return;
                         }
                     }
                 }
                 else //permanent logger is memory logger, so do nothing else
                 {
                     this.State = RunState.Bootstrapped;
                     return;
                 }
             }
             this.provider = null;
             this.State    = RunState.FailedBootstrapping;
         }
     }
 }
Esempio n. 4
0
        public void Bootstrap(TypeNameReference authFactoryType, TypeNameReference credFactoryType)
        {
            lock (instance)
            {
                if (this.State == RunState.Created || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(AuthenticationManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (authFactoryType != null && credFactoryType != null)
                    {
                        this.credFactory = NameReflectionUtils.CreateInstance <CredentialStoreFactory>(credFactoryType);
                        if (this.credFactory != null)
                        {
                            this.authFactory = NameReflectionUtils.CreateInstance <AuthenticationProviderFactory>(authFactoryType);
                            if (this.authFactory != null)
                            {
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Bootstrapped;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create authentication factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to create credential factory instance");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No typename provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
Esempio n. 5
0
        public void Bootstrap(IdentityConfiguration config)
        {
            lock (instance)
            {
                if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(IdentityManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (config != null)
                    {
                        TypeNameReference typ = config.FactoryTypeName;
                        if (typ != null)
                        {
                            this.factory = NameReflectionUtils.CreateInstance <IdentityProviderFactory>(typ);
                            if (this.factory != null)
                            {
                                Log(meth, LogLevel.Info, "Succeeded");
                                this.State = RunState.Bootstrapped;
                                return;
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to extract typename");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No config provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
Esempio n. 6
0
 public void Bootstrap(TypeNameReference factoryType, uint sessionDuration)
 {
     lock (instance)
     {
         if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
         {
             if (factoryType != null)
             {
                 SessionProviderFactory fact = NameReflectionUtils.CreateInstance <SessionProviderFactory>(factoryType);
                 if (fact != null)
                 {
                     this.factory         = fact;
                     this.SessionDuration = sessionDuration;
                     this.State           = RunState.Bootstrapped;
                     return;
                 }
             }
             this.State = RunState.FailedBootstrapping;
         }
     }
 }
Esempio n. 7
0
 public bool Initialize(UserPasswordConfig config)
 {
     lock (this)
     {
         if (config != null && !this.initialized)
         {
             if (config.HistoryProvider != null)
             {
                 this.HistoryProvider = this.HistoryProvider = NameReflectionUtils.CreateInstance <UserPasswordHistoryProviderFactory>(config.HistoryProvider);
                 if (this.HistoryProvider != null)
                 {
                     if (this.HistoryProvider.Initialize())
                     {
                         this.MaxHistory = config.MaxHistory;
                         if (config.MinChar < config.MaxChar)
                         {
                             try
                             {
                                 this.Shaker = new SaltShaker((char)config.MinChar, (char)config.MaxChar, config.HashLength, SaltCreationModel.Repeatable, SaltEmbeddingModel.Randomized, -1);
                                 foreach (PasswordComplexityRule curRule in config.Rules)
                                 {
                                     if (curRule != null)
                                     {
                                         this.ComplexityChecker.Rules.Add(curRule);
                                     }
                                 }
                                 this.initialized = true;
                                 return(true);
                             }
                             catch
                             { }
                         }
                     }
                 }
             }
         }
     }
     return(false);
 }
        public void Bootstrap(AuthorizationConfiguration config)
        {
            lock (instance)
            {
                if (RuntimeUtils.Bootstrappable(this.State) || this.State == RunState.Bootstrapping)
                {
                    this.State = RunState.Bootstrapping;
                    string meth = "Bootstrap";
                    if (this.logger == null) //in case we're directly bootstrapping
                    {
                        this.logger = LogManager.Instance.GetProvider(typeof(AuthorizationManager));
                        Log(meth, LogLevel.Info, "Called");
                    }

                    if (config != null)
                    {
                        TypeNameReference typ = config.PermissionFactoryTypeName;
                        if (typ != null)
                        {
                            this.permissionFactory = NameReflectionUtils.CreateInstance <PermissionProviderFactory>(typ);
                            if (this.permissionFactory != null)
                            {
                                typ = config.RoleFactoryTypeName;
                                if (typ != null)
                                {
                                    this.roleFactory = NameReflectionUtils.CreateInstance <RoleProviderFactory>(typ);
                                    if (this.roleFactory != null)
                                    {
                                        this.roleFactory.LocalContext       = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                        this.permissionFactory.LocalContext = new UserSecurityContext(new LocalSystemUser(user.Uid, user.Name, user.UserState));
                                        Log(meth, LogLevel.Info, "Succeeded");
                                        this.State = RunState.Bootstrapped;
                                        return;
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create role factory instance");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to extract role typename");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to create permission factory instance");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to extract permission typename");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "No config provided");
                    }
                    this.State = RunState.FailedBootstrapping;
                }
            }
        }
Esempio n. 9
0
        protected override bool Initialize()
        {
            lock (instance)
            {
                if (!this.initialized)
                {
                    string meth = "Initialize";
                    this.logger = LogManager.Instance.GetProvider(typeof(CachingRoleProviderFactory));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(CachingRoleProviderFactory), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    innerFact = NameReflectionUtils.CreateInstance <RoleProviderFactory>(typeName);
                                    if (innerFact != null)
                                    {
                                        if (InitializeOther(innerFact))
                                        {
                                            //ok preload the cache
                                            LocalSystemUser u    = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
                                            IRoleProvider   prov = this.GetProviderOther(this.innerFact, new UserSecurityContext(u));
                                            if (prov != null)
                                            {
                                                if (RoleMemorySet.Reset(prov))
                                                {
                                                    if (RoleMembershipMemorySet.Reset(prov))
                                                    {
                                                        this.initialized = true;
                                                        scavengeTimer    = new Timer(this.Scavenge, null, 0, 300000); //5 minutes
                                                        return(true);
                                                    }
                                                    else
                                                    {
                                                        Log(meth, LogLevel.Error, "Failed to initialize caching");
                                                    }
                                                }
                                                else
                                                {
                                                    Log(meth, LogLevel.Error, "Failed to initialize caching");
                                                }
                                            }
                                            else
                                            {
                                                Log(meth, LogLevel.Error, "Failed to get inner provider for preload");
                                            }
                                        }
                                        else
                                        {
                                            Log(meth, LogLevel.Error, "Failed to initialize inner provider");
                                        }
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create inner provider factory");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse permission provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get permission provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }
                }
            }
            return(false);
        }
        protected override bool Initialize()
        {
            lock (instance)
            {
                if (!this.initialized)
                {
                    string meth = "Initialize";
                    this.logger = LogManager.Instance.GetProvider(typeof(CachingPermissionProviderFactory));
                    Log(meth, LogLevel.Info, "Called");

                    ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider();
                    if (config != null)
                    {
                        ConfigurationParameter param = config.Get(typeof(CachingPermissionProviderFactory), "provider");
                        if (param != null)
                        {
                            string tName = param.Value as string;
                            if (!string.IsNullOrEmpty(tName))
                            {
                                TypeNameReference typeName = TypeNameReference.Parse(tName);
                                if (typeName != null)
                                {
                                    innerFact = NameReflectionUtils.CreateInstance <PermissionProviderFactory>(typeName);
                                    if (innerFact != null)
                                    {
                                        if (InitializeOther(innerFact))
                                        {
                                            //ok preload the cache
                                            LocalSystemUser     u    = new LocalSystemUser(SecurityUtils.AdminIdentity, "Admin", UserState.Active);
                                            IPermissionProvider prov = this.GetProviderOther(this.innerFact, new UserSecurityContext(u));
                                            if (prov != null)
                                            {
                                                IEnumerable <Permission> perms = prov.GetPermissions();
                                                if (perms != null)
                                                {
                                                    foreach (Permission p in perms)
                                                    {
                                                        PermissionMemorySet.RegisterPermission(p);
                                                    }

                                                    this.initialized = true;
                                                    return(true);
                                                }
                                                else
                                                {
                                                    Log(meth, LogLevel.Error, "Failed to get existing permissions");
                                                }
                                            }
                                            else
                                            {
                                                Log(meth, LogLevel.Error, "Failed to get inner provider for preload");
                                            }
                                        }
                                        else
                                        {
                                            Log(meth, LogLevel.Error, "Failed to initialize inner provider");
                                        }
                                    }
                                    else
                                    {
                                        Log(meth, LogLevel.Error, "Failed to create inner provider factory");
                                    }
                                }
                                else
                                {
                                    Log(meth, LogLevel.Error, "Failed to parse permission provider param value");
                                }
                            }
                            else
                            {
                                Log(meth, LogLevel.Error, "Failed to get provider param value");
                            }
                        }
                        else
                        {
                            Log(meth, LogLevel.Error, "Failed to get provider param");
                        }
                    }
                    else
                    {
                        Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider");
                    }
                }
            }
            return(false);
        }