public void SignIn(User user)
    {
        FormsAuthentication.SignOut();
        if (user == null)
        {
            return;
        }
        DateTime issued  = DateTime.Now;
        DateTime expires = issued.AddMinutes(30);

        if (user.ExpiryDate.HasValue)
        {
            if (user.Expires && expires > user.ExpiryDate)
            {
                expires = (DateTime)user.ExpiryDate;
            }
        }
        var roles           = user.Roles.Select(x => x.Name).ToList();
        var ticket          = new FormsAuthenticationTicket(1, user.UserName, issued, expires, false, string.Join(",", roles.Distinct().ToArray()));
        var encryptedTicket = FormsAuthentication.Encrypt(ticket);
        var authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
        {
            Expires = ticket.Expiration
        };

        _httpContextProvider.GetCurrentHttpContext().Response.Cookies.Add(authCookie);
    }
Exemple #2
0
        public ISecurityPrincipal GetPrincipal()
        {
            var httpContext = _httpContextProvider.GetCurrentHttpContext();

            Assertion.IsNotNull(httpContext, "IHttpContextProvider.GetCurrentHttpContext() evaludated and returned null.");

            var identity = httpContext.User.Identity;

            if (!identity.IsAuthenticated)
            {
                return(s_nullSecurityPrincipal);
            }

            return(new SecurityPrincipal(identity.Name, null, null, null));
        }
Exemple #3
0
        private string GetApplicationPath()
        {
            var context = _httpContextProvider.GetCurrentHttpContext();

            return(GetApplicationPathFromHttpContext(context));
        }