Exemplo n.º 1
0
 public CustomPrincipal ConstructCustomPrincipal(IIdentity identity, CachedUserInfo userInfo)
 {
     if (userInfo == null)
         return null;
     var ci = new CustomIdentity(userInfo.Username, identity.IsAuthenticated, identity.AuthenticationType);
     switch (userInfo.UserType)
     {
         case UserType.Admin:
             ci.Roles.Add("Admin");
             ci.Roles.Add("User");
             break;
         case UserType.TDR:
             ci.Roles.Add("TDR");
             break;
     }
     return new CustomPrincipal(ci, userInfo);
 }
Exemplo n.º 2
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (this.User != null)
            {
                string cachedKey = string.Format("cui_{0}", this.User.Identity.Name);
                CachedUserInfo userInfo = HttpContext.Current.Cache[cachedKey] as CachedUserInfo;
                if (userInfo == null)
                {

                    var userRepository = DependencyResolver.Current.GetService<IUserRepository>();
                    var user = userRepository.Get(this.User.Identity.Name);
                    if (user == null)
                        return;
                    userInfo = new CachedUserInfo { UserId = user.Id, Username = this.User.Identity.Name, UserType = user.UserType, ClientId =user.ClientId.HasValue? user.ClientId.Value:Guid.Empty };
                    //hquser

                }
                HttpContext.Current.Cache.Insert(cachedKey, userInfo);
                var ws = DependencyResolver.Current.GetService<IWebSecurityService>();
                IPrincipal cp = ws.ConstructCustomPrincipal(this.User.Identity, userInfo);
                this.Context.User = cp;
            }
        }
Exemplo n.º 3
0
 public CustomPrincipal(CustomIdentity cidIdentity, CachedUserInfo userInfo)
 {
     _cidIdentity = cidIdentity;
     UserInfo = userInfo;
 }