public bool PrePerform(HttpContext httpContext)
        {
            var session = _sessionGetter.GetSession(httpContext);
            if (session[_contants.Authenticated] == true.ToString()) // allow to continue
            {
                return true;
            }

            // redirect to authetnication endpoint and note it of the return url
            var baseUrl = _baseUrlGenerator.GenerateUrlBase(httpContext.HttpRequest);
            var authenticationUrl = new StringBuilder();
            authenticationUrl.Append(baseUrl);
            if (!string.IsNullOrWhiteSpace(_applicationRuntimeSettings.BaseAddress))
            {
                authenticationUrl.AppendFormat("/{0}", _applicationRuntimeSettings.BaseAddress);
            }
            if (!string.IsNullOrWhiteSpace(_authenticateServiceEndpoint.HttpRequestDescriptor.RouteDescription))
            {
                authenticationUrl.AppendFormat("/{0}", _authenticateServiceEndpoint.HttpRequestDescriptor.RouteDescription);
            }
            httpContext.HttpResponse.Headers.Add("Location: ", authenticationUrl.ToString());
            httpContext.HttpResponse.HttpStatusCode = HttpStatusCode.Redirect;
            var returnUrl = new StringBuilder();
            returnUrl.Append(baseUrl);
            if (!string.IsNullOrWhiteSpace(httpContext.HttpRequest.Path))
            {
                authenticationUrl.AppendFormat("/{0}", httpContext.HttpRequest.Path);
            }
            session[_contants.ReturnUrl] = returnUrl.ToString();

            return false;
        }
Beispiel #2
0
 public IHttpSession GetSession(HttpContext httpContext)
 {
     if (httpContext.ActionObjects.ContainsKey(_sessionObject))
     {
         return (IHttpSession)httpContext.ActionObjects[_sessionObject];
     }
     var sessionObject = _sessionReader.ReadSession(httpContext);
     httpContext.ActionObjects[_sessionObject] = sessionObject;
     return sessionObject;
 }
Beispiel #3
0
        public IHttpSession ReadSession(HttpContext httpContext)
        {
            var sessionCookie = _cookieHeadersGetter.GetCookieHeaders(httpContext)
                                                    .Last(x => x.Key == _sessionIdLiteralSpecifier.SessionId);
            if (sessionCookie != null) return _httpSessionRepository.GetHttpSession(sessionCookie.Value);

            sessionCookie = _defaultSessionCookieFactory.GetDefaultSessionCookie(httpContext);
            httpContext.HttpResponse.Headers.Add(_contants.SetCookie, sessionCookie.ToString());

            return _httpSessionRepository.GetHttpSession(sessionCookie.Value);
        }
Beispiel #4
0
        public HeaderCookie[] GetCookieHeaders(HttpContext httpContext)
        {
            if (httpContext.ActionObjects.ContainsKey(_cookieHeadersObject))
            {
                return (HeaderCookie[])httpContext.ActionObjects[_cookieHeadersObject];
            }

            var headerCookies = _cookieHeadersReader.ReadCookieHeaders(httpContext.HttpRequest.Headers)
                                                    .Where(x => _cookieValidator.ValidateCookie(httpContext.HttpRequest, x))
                                                    .ToArray();
            httpContext.ActionObjects[_cookieHeadersObject] = headerCookies;
            return headerCookies;
        }
 public HeaderCookie GetDefaultSessionCookie(HttpContext httpContext)
 {
     return new HeaderCookie
     {
         Domain = httpContext.HttpRequest.ServerDomain,
         Expires = DateTimeOffset.Now.Add(_lifespan),
         HttpOnly = true,
         Key = _sessionIdLiteral,
         Value = Guid.NewGuid().ToString(),
         Path = "/",
         Secure = httpContext.HttpRequest.UsesSsl
     };
 }
 public void OnException(Exception exception, HttpContext httpContext, IHttpEndpoint httpEndpoint)
 {
     throw new NotImplementedException();
 }