//:id, :oType, :payload, :token, :locked, :dateFrom, :dateTo public bool AddCredential(Guid userId, IAuthenticationProvider provider, string token, string payload) { if (!Guid.Empty.Equals(userId) && provider != null && !string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(payload)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Insert; cmd.Parameters.AddWithValue("id", userId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); cmd.Parameters.AddWithValue("payload", payload); cmd.Parameters.AddWithValue("token", token); cmd.Parameters.AddWithValue("locked", false); cmd.Parameters.AddWithValue("dateFrom", DateTime.UtcNow); cmd.Parameters.AddWithValue("dateTo", new DateTime(3000, 1, 1)); //should move this to config Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
protected override void BootstrapImpl() { lock (this.syncRoot) { this.State = RunState.Bootstrapping; try { ConfigurationProviderBase prov = ConfigurationManager.Instance.GetProvider(); if (prov != null) { ConfigurationParameter param = prov.Get(typeof(LogManager), "provider"); if (param != null) { string fName = (string)param.Value; if (!string.IsNullOrEmpty(fName)) { TypeNameReference tnr = TypeNameReference.Parse(fName, ','); if (tnr != null) { this.Bootstrap(tnr); return; } } } } } catch { } this.State = RunState.FailedBootstrapping; } }
protected internal override ConfigurationParameter GetImpl(string typeName, string name) { if (this.configs.ContainsKey(typeName)) { if (this.configs[typeName].ContainsKey(name)) { return(ConfigurationParameter.Create(typeName, name, this.configs[typeName][name])); } else { TypeNameReference ty = TypeNameReference.Parse(typeName); if (ty != null) //try for a new file { string corePath = Path.GetDirectoryName(AppContext.BaseDirectory); if (File.Exists(Path.Combine(corePath, ty.AssemblyFileName + ".jconfig"))) { try { this.Init(Path.Combine(corePath, ty.AssemblyFileName + ".jconfig")); } catch { } if (this.configs[typeName].ContainsKey(name)) { return(ConfigurationParameter.Create(typeName, name, this.configs[typeName][name])); } } } } } return(null); }
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; } } }
protected override void BootstrapImpl() { lock (this.syncRoot) { try { this.State = RunState.Bootstrapping; string corePath = Path.GetDirectoryName(AppContext.BaseDirectory); JsonProvider tmpProvider = new JsonProvider(); if (tmpProvider.Init(Path.Combine(corePath, "Osrs.Runtime.Configuration.jconfig"))) { Type t = typeof(ConfigurationManager); string name = string.Format("{0}.{1}, {2}", t.Namespace, t.Name, t.GetTypeInfo().Assembly.GetName().Name); ConfigurationParameter param = tmpProvider.GetImpl(name, "provider"); if (param != null) { string fName = (string)param.Value; if (!string.IsNullOrEmpty(fName)) { TypeNameReference tnr = TypeNameReference.Parse(fName, ','); if (tnr != null) { Bootstrap(tnr, tmpProvider); return; } } } } } catch { } this.State = RunState.FailedBootstrapping; } }
public NewInstanceDependencyTarget(TypeNameReference targetType = default, IEnumerable <TypeNameReference> constructorSignature = default, bool isReadOnly = default) : base(isReadOnly: isReadOnly) { _targetType = targetType; _constructorSignature = constructorSignature is null ? (isReadOnly ? (new TypeNameReference[] { }).AsReadOnlyCollection() : (new TypeNameReference[] { })) : (isReadOnly ? (ICollection <TypeNameReference>) new ListReadOnlyWrap <TypeNameReference>(collection: constructorSignature) : new List <TypeNameReference>(collection: constructorSignature)); }
public TypeDependencyId( ITypeDependencyId other, bool isReadOnly = false) : base(isReadOnly: isReadOnly) { // other.EnsureNotNull(nameof(other)); // _type = other.Type; }
public LogItem(TypeNameReference typeName, DateTime when, string eventId, ushort severity, string title, string exception, string message) { this.TypeName = typeName; this.When = when; this.EventId = eventId; this.Severity = severity; this.Title = title; this.Exception = exception; this.Message = message; }
internal void Log(TypeNameReference typeName, DateTime when, string eventId, ushort severity, string title, Exception exception, string message) { if (exception != null) { this.Log(typeName, when, eventId, severity, title, exception.ToString(), message); } else { this.Log(typeName, when, eventId, severity, title, (string)null, message); } }
public virtual bool Equals(TypeDependencyId other) { if (ReferenceEquals(other, null)) { return(false); } else { return(TypeNameReference.Equals(_type, other._type)); } }
public void Bootstrap() { lock (instance) { if (RuntimeUtils.Bootstrappable(this.State)) { string meth = "Bootstrap"; this.State = RunState.Bootstrapping; this.logger = LogManager.Instance.GetProvider(typeof(IdentityManager)); Log(meth, LogLevel.Info, "Called"); ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider(); if (config != null) { ConfigurationParameter param = config.Get(typeof(IdentityManager), "provider"); if (param != null) { string tName = param.Value as string; if (!string.IsNullOrEmpty(tName)) { TypeNameReference typeName = TypeNameReference.Parse(tName); if (typeName != null) { IdentityConfiguration iConfig = new IdentityConfiguration(); iConfig.FactoryTypeName = typeName; Bootstrap(iConfig); return; } else { Log(meth, LogLevel.Error, "Failed to parse 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"); } this.State = RunState.FailedBootstrapping; } } }
protected override void InitializeImpl() { lock (instance) { if (RuntimeUtils.Initializable(this.State)) { string meth = "Initialize"; this.State = RunState.Initializing; this.logger = LogManager.Instance.GetProvider(typeof(InstrumentManager)); Log(meth, LogLevel.Info, "Called"); ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider(); if (config != null) { ConfigurationParameter param = config.Get(typeof(InstrumentManager), "provider"); if (param != null) { string tName = param.Value as string; if (!string.IsNullOrEmpty(tName)) { TypeNameReference typeName = TypeNameReference.Parse(tName); if (typeName != null) { this.Initialize(typeName); return; } else { Log(meth, LogLevel.Error, "Failed to parse role provider param value"); } } else { Log(meth, LogLevel.Error, "Failed to get role provider param value"); } } else { Log(meth, LogLevel.Error, "Failed to get role provider param"); } } else { Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider"); } this.State = RunState.FailedInitializing; } } }
protected override void Log(TypeNameReference typeName, DateTime when, string eventId, ushort severity, string title, string exception, string message) { lock (FlatFileLogFactory.syncRoot) { if (FlatFileLogFactory.writer != null) { LogItem tmp = new LogItem(typeName, when, eventId, severity, title, exception, message); FlatFileLogFactory.writer.WriteLine(tmp.ToString()); FlatFileLogFactory.count++; if (FlatFileLogFactory.count > 99) { FlatFileLogFactory.writer.Flush(); FlatFileLogFactory.count = 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; } } }
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; } } }
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; } } }
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; } } }
public bool Lock(IAuthenticationProvider provider, Guid userId) { if (provider != null && !Guid.Empty.Equals(userId)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Lock + "AND \"OwnerType\"=:oType"; cmd.Parameters.AddWithValue("id", userId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
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; } } }
public bool DeleteCredential(Guid userId, IAuthenticationProvider provider, string token) { if (!Guid.Empty.Equals(userId) && provider != null && !string.IsNullOrEmpty(token)) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Delete; cmd.Parameters.AddWithValue("id", userId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); cmd.Parameters.AddWithValue("token", token); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public bool Lock(IAuthenticationProvider provider, PersistedCredential credential) { if (provider != null && credential != null) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Lock + "AND \"OwnerType\"=:oType AND \"Token\"=:token"; cmd.Parameters.AddWithValue("id", credential.UserId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); cmd.Parameters.AddWithValue("token", credential.TextToken); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
public IEnumerable <PersistedCredential> Get(IAuthenticationProvider provider, Guid userId, string token) { if (provider != null) { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Select + "\"Id\"=:id AND \"OwnerType\"=:oType AND \"Token\"=:token"; cmd.Parameters.AddWithValue("id", userId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); cmd.Parameters.AddWithValue("token", token); NpgsqlDataReader rdr = Db.ExecuteReader(cmd); List <PersistedCredential> permissions = new List <PersistedCredential>(); try { PersistedCredential o; while (rdr.Read()) { o = PgCredentialStoreFactory.Instance.Create(rdr); if (o != null) { permissions.Add(o); } } if (cmd.Connection.State == System.Data.ConnectionState.Open) { cmd.Connection.Close(); } } catch { } finally { cmd.Dispose(); } return(permissions); } return(null); }
public bool UpdateCredential(IAuthenticationProvider provider, PersistedCredential credential, DateTime validFrom, DateTime validTo, bool isLocked) { if (provider != null && credential != null) { try { NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString); cmd.CommandText = Db.Update; cmd.Parameters.AddWithValue("id", credential.UserId); cmd.Parameters.AddWithValue("oType", TypeNameReference.Create(provider).ToString()); cmd.Parameters.AddWithValue("token", credential.TextToken); cmd.Parameters.AddWithValue("dateFrom", validFrom); cmd.Parameters.AddWithValue("dateTo", validTo); cmd.Parameters.AddWithValue("locked", isLocked); Db.ExecuteNonQuery(cmd); return(true); } catch { } } return(false); }
protected override void InitializeImpl() { lock (instance) { if (RuntimeUtils.Initializable(this.State)) { string meth = "Initialize"; this.State = RunState.Initializing; this.logger = LogManager.Instance.GetProvider(typeof(UserAffilationSecurityManager)); Log(meth, LogLevel.Info, "Called"); ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider(); if (config != null) { ConfigurationParameter param = config.Get(NameReflectionUtils.GetType(TypeNameReference.Parse("Osrs.WellKnown.FieldActivities.Providers.PgFieldActivityProviderFactory, Osrs.WellKnown.FieldActivities.Providers.Postgres")), "connectionString"); if (param != null) { string tName = param.Value as string; if (!string.IsNullOrEmpty(tName)) { if (NpgSqlCommandUtils.TestConnection(tName)) { Db.ConnectionString = tName; this.initialized = true; this.State = RunState.Initialized; return; } } else { Log(meth, LogLevel.Error, "Failed to get connectionString param value"); } } else { Log(meth, LogLevel.Error, "Failed to get connectionString param"); } } else { Log(meth, LogLevel.Error, "Failed to get ConfigurationProvider"); } this.State = RunState.FailedInitializing; } } }
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 internal override void Log(TypeNameReference typeName, DateTime when, string eventId, ushort severity, string title, string exception, string message) { MemoryLoggerFactory.Items.Add(new LogItem(typeName, when, eventId, severity, title, exception, message)); }
protected LogProviderBase(Type logType) { this.Type = logType; this.typeName = TypeNameReference.Create(this.Type); }
protected internal abstract void Log(TypeNameReference typeName, DateTime when, string eventId, ushort severity, string title, string exception, string message);
protected override bool Initialize() { lock (this) { if (!initialized) { ConfigurationProviderBase config = ConfigurationManager.Instance.GetProvider(); if (config != null) { Type myType = typeof(UserPasswordProviderFactory); ConfigurationParameter parm = config.Get(myType, "historyProvider"); if (parm != null) { TypeNameReference fact = TypeNameReference.Parse((string)parm.Value); if (fact != null) { UserPasswordConfig myConfig = new UserPasswordConfig(); myConfig.HistoryProvider = fact; parm = config.Get(myType, "maxHistory"); if (parm != null) { try { myConfig.MaxHistory = (ushort)(int)parm.Value; parm = config.Get(myType, "hashLength"); if (parm != null) { try { myConfig.HashLength = (int)parm.Value; if (myConfig.HashLength > 0) { parm = config.Get(myType, "hashMinChar"); if (parm != null) { try { myConfig.MinChar = (char)(int)parm.Value; if (myConfig.MinChar > 0) { parm = config.Get(myType, "hashMaxChar"); if (parm != null) { try { myConfig.MaxChar = (char)(int)parm.Value; if (myConfig.MaxChar > 0) { //TODO -- add complexity rule config params return(this.Initialize(myConfig)); } } catch { } } } } catch { } } } } catch { } } } 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; } } }