Exemplo n.º 1
0
        /// <summary>
        /// Determines whether the user's browser refuses to accept session cookies
        /// </summary>
        /// <returns>True if the browser does not allow session cookies, otherwise False</returns>
        internal static bool GetUserDoesNotAllowSessionCookies()
        {
            CasAuthentication.Initialize();

            // If the request has a gateway parameter but the cookie does not
            // reflect the fact that gateway was attempted, then cookies must
            // be disabled.
            GatewayStatus status = CasAuthentication.GetGatewayStatus();

            bool gatewayEnabled                 = CasAuthentication.Gateway;
            bool gatewayWasNotAttempted         = (status == GatewayStatus.NotAttempted);
            bool requestHasGatewayParameter     = GetRequestHasGatewayParameter();
            bool cookiesRequiredUrlIsDefined    = !string.IsNullOrEmpty(CasAuthentication.CookiesRequiredUrl);
            bool requestIsNotCookiesRequiredUrl = cookiesRequiredUrlIsDefined && !GetRequestIsCookiesRequiredUrl();

            bool result =
                (
                    gatewayEnabled &&
                    gatewayWasNotAttempted &&
                    requestHasGatewayParameter &&
                    requestIsNotCookiesRequiredUrl
                );

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the current request requires a Gateway authentication redirect
        /// </summary>
        /// <returns>True if the request requires Gateway authentication, otherwise False</returns>
        internal static bool GetRequestRequiresGateway()
        {
            CasAuthentication.Initialize();

            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;

            GatewayStatus status = CasAuthentication.GetGatewayStatus();

            bool gatewayEnabled                     = CasAuthentication.Gateway;
            bool gatewayWasNotAttempted             = (status == GatewayStatus.NotAttempted);
            bool requestDoesNotHaveGatewayParameter = !GetRequestHasGatewayParameter();
            bool cookiesRequiredUrlIsDefined        = !string.IsNullOrEmpty(CasAuthentication.CookiesRequiredUrl);
            bool requestIsNotCookiesRequiredUrl     = !GetRequestIsCookiesRequiredUrl();
            bool notAuthorizedUrlIsDefined          = !String.IsNullOrEmpty(CasAuthentication.NotAuthorizedUrl);
            bool requestIsNotAuthorizedUrl          = notAuthorizedUrlIsDefined && request.RawUrl.StartsWith(UrlUtil.ResolveUrl(CasAuthentication.NotAuthorizedUrl), true, CultureInfo.InvariantCulture);

            bool result =
                (
                    gatewayEnabled &&
                    gatewayWasNotAttempted &&
                    requestDoesNotHaveGatewayParameter &&
                    cookiesRequiredUrlIsDefined &&
                    requestIsNotCookiesRequiredUrl &&
                    !requestIsNotAuthorizedUrl
                );

            return(result);
        }