Example #1
0
        public static void SetThreadPrincipal(UserInfo user)
        {
            // set roles array
            List <string> roles = new List <string>();

            roles.Add(SecurityContext.ROLE_USER);
            if (user.Role == UserRole.Reseller || user.Role == UserRole.Administrator)
            {
                roles.Add(SecurityContext.ROLE_RESELLER);
            }
            if (user.Role == UserRole.Administrator)
            {
                roles.Add(SecurityContext.ROLE_ADMINISTRATOR);
            }

            // create a new generic principal/identity and place them to context
            EnterpriseServerIdentity  identity  = new EnterpriseServerIdentity(user.UserId.ToString());
            EnterpriseServerPrincipal principal = new EnterpriseServerPrincipal(identity, roles.ToArray());

            principal.UserId  = user.UserId;
            principal.OwnerId = user.OwnerId;
            principal.IsPeer  = user.IsPeer;
            principal.IsDemo  = user.IsDemo;
            principal.Status  = user.Status;

            Thread.CurrentPrincipal = principal;
        }
Example #2
0
        public static void SetThreadPrincipal(UserInfo user)
        {
            // set roles array
            List<string> roles = new List<string>();
            roles.Add(SecurityContext.ROLE_USER);
            if (user.Role == UserRole.Reseller || user.Role == UserRole.Administrator)
                roles.Add(SecurityContext.ROLE_RESELLER);
            if (user.Role == UserRole.Administrator)
                roles.Add(SecurityContext.ROLE_ADMINISTRATOR);

            // create a new generic principal/identity and place them to context
            EnterpriseServerIdentity identity = new EnterpriseServerIdentity(user.UserId.ToString());
            EnterpriseServerPrincipal principal = new EnterpriseServerPrincipal(identity, roles.ToArray());

            principal.UserId = user.UserId;
            principal.OwnerId = user.OwnerId;
            principal.IsPeer = user.IsPeer;
            principal.IsDemo = user.IsDemo;
            principal.Status = user.Status;

            Thread.CurrentPrincipal = principal;
        }