/// <summary> /// Intercepts the beginning of the request pipeline. This will detect SingleSignOut /// requests. SingleSignOut requests are posted back to the serviceName URL that /// was passed when the CAS session was established. Since the behavior of the script /// at that URL is unknown, a POST back by the CAS server could have unexpected /// consequences. We want to prevent this request from authenticating and from /// executing the HttpHandler typically associated with that URL. So we are handling /// this by sending back an HTTP 200 (OK) message with a blank body and short /// circuiting all event processing and firing EndRequest directly /// (via CompleteRequest()). /// </summary> /// <param name="sender">The HttpApplication that sent the request</param> /// <param name="e">Not used</param> private static void OnBeginRequest(object sender, EventArgs e) { // Validate the ticket coming back from the CAS server (NETC-55) if (!RequestEvaluator.GetRequestIsAppropriateForCasAuthentication()) { logger.Debug("BeginRequest bypassed for " + HttpContext.Current.Request.RawUrl); return; } CasAuthentication.Initialize(); HttpContext context = HttpContext.Current; HttpRequest request = context.Request; logger.Debug("Starting BeginRequest for " + request.RawUrl); // Cleanup expired ServiceTickets in the ServiceTicketManager if (CasAuthentication.ServiceTicketManager != null) { CasAuthentication.ServiceTicketManager.RemoveExpiredTickets(); } // Cleanup expired ProxyTicket mappings in the ProxyTicketManager if (CasAuthentication.ProxyTicketManager != null) { CasAuthentication.ProxyTicketManager.RemoveExpiredMappings(); } // Detect & process inbound Single SignOut Requests from the CAS server if (CasAuthentication.ServiceTicketManager != null && CasAuthentication.ProcessIncomingSingleSignOutRequests && RequestEvaluator.GetRequestIsCasSingleSignOut()) { logger.Info("Processing inbound Single Sign Out request."); CasAuthentication.ProcessSingleSignOutRequest(); return; } // Detect & process inbound proxy callback verifications from the CAS server if (CasAuthentication.ProxyTicketManager != null && RequestEvaluator.GetRequestIsProxyResponse()) { logger.Info("Processing Proxy Callback request"); CasAuthentication.ProcessProxyCallbackRequest(); return; } logger.Debug("Ending BeginRequest for " + request.RawUrl); }