Beispiel #1
0
        private static void SetPrincipal(GenericTicketTokenContainer container)
        {
            IPrincipalBuilder principalBuilder = PrincipalSettings.GetConfig().GetPrincipalBuilder(false);

            if (principalBuilder != null)
            {
                IPrincipal principal = principalBuilder.CreatePrincipal(container, null);

                PrincipaContextAccessor.SetPrincipal(principal);
            }
        }
        private static IPrincipal SetPrincipal(string userID, ITicket ticket)
        {
            IPrincipal principal = GetPrincipalInSession(userID);

            if (principal == null)
            {
                LogOnIdentity loi = new LogOnIdentity(userID);

                string identityID = string.Empty;

                if (PassportClientSettings.GetConfig().IdentityWithoutDomainName)
                {
                    identityID = loi.LogOnNameWithoutDomain;
                }
                else
                {
                    identityID = loi.LogOnName;
                }

                principal = PrincipalSettings.GetConfig().GetPrincipalBuilder().CreatePrincipal(identityID, ticket);

                HttpCookie cookie = new HttpCookie(Common.GetPrincipalSessionKey());
                cookie.Expires = DateTime.MinValue;

                CookieCacheDependency cookieDependency = new CookieCacheDependency(cookie);

                SlidingTimeDependency slidingDependency =
                    new SlidingTimeDependency(Common.GetSessionTimeOut());

                PrincipalCache.Instance.Add(
                    Common.GetPrincipalSessionKey(),
                    principal,
                    new MixedDependency(cookieDependency, slidingDependency));
            }

            PrincipaContextAccessor.SetPrincipal(principal);

            return(principal);
        }