private void Scavenge(object notUsed) { if (AuthorizationManager.Instance.State == Runtime.RunState.Running) { 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)) { RoleMembershipMemorySet.Reset(prov); } } } }
internal static bool Reset(IRoleProvider prov) { try { IEnumerable <Role> perms = prov.GetRoles(); if (perms != null) { RoleMemorySet tmp = new RoleMemorySet(); foreach (Role p in perms) { tmp.RegisterRole(p); } instance = tmp; return(true); } } catch { } return(false); }
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); }