Exemple #1
0
 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
            {
                RoleMembershipMemorySet tmp = new RoleMembershipMemorySet();
                foreach (Role p in RoleMemorySet.Instance.GetRoles())
                {
                    IEnumerable <Role> kids = prov.GetChildRoles(p);
                    if (kids != null)
                    {
                        foreach (Role r in kids)
                        {
                            tmp.AddRoleToRole(p.Id, r.Id);
                        }
                    }

                    IEnumerable <Guid> users = prov.GetUsers(p);
                    if (users != null)
                    {
                        foreach (Guid us in users)
                        {
                            tmp.AddUserToRole(us, p.Id);
                        }
                    }

                    IEnumerable <PermissionAssignment> pas = prov.GetPermissionAssignments(p);
                    if (pas != null)
                    {
                        foreach (PermissionAssignment pa in pas)
                        {
                            tmp.AddPermissionToRole(p.Id, pa.Permission.Id, pa.GrantType == GrantType.Grant);
                        }
                    }
                }
                instance = tmp;
                return(true);
            }
            catch
            { }
            return(false);
        }
Exemple #3
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);
        }