public RolePrincipal(RoleIdentity identity)
 {
     if (identity == null)
     {
         throw new ArgumentNullException("identity", "Missing object reference.");
     }
     this.identity = identity;
 }
        private void RegisterMADPrincipal()
        {
            IPrincipal user = HttpContext.Current.User;

            if (user != null && user.Identity.IsAuthenticated && user.Identity.AuthenticationType == "Forms")
            {
                var formsIdentity = user.Identity as FormsIdentity;
                if (formsIdentity != null)
                {
                    var newIdentity  = new RoleIdentity(formsIdentity.Ticket);
                    var newPrincipal = new RolePrincipal(newIdentity);

                    HttpContext.Current.User = newPrincipal;
                    Thread.CurrentPrincipal  = newPrincipal;
                }
            }
        }
Esempio n. 3
0
        public static string[] GetRolesFromIdentity()
        {
            IPrincipal user = HttpContext.Current.User;

            if (user == null || !user.Identity.IsAuthenticated)
            {
                return new string[] {}
            }
            ;

            RoleIdentity roleIdentity = user.Identity as RoleIdentity;

            if (roleIdentity == null)
            {
                throw new InvalidOperationException("Can not get roles for current user. RoleIdentity is not set.");
            }
            return(roleIdentity.Roles);
        }