Search in sources :

Example 1 with LogoutHttpMessage

use of org.apereo.cas.logout.LogoutHttpMessage in project cas by apereo.

the class FrontChannelLogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) throws Exception {
    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(context);
    final Map<LogoutRequest, LogoutHttpMessage> logoutUrls = new HashMap<>();
    if (logoutRequests != null) {
        logoutRequests.stream().filter(r -> r.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED).forEach(r -> {
            LOGGER.debug("Using logout url [{}] for front-channel logout requests", r.getLogoutUrl().toExternalForm());
            final String logoutMessage = this.logoutManager.createFrontChannelLogoutMessage(r);
            LOGGER.debug("Front-channel logout message to send is [{}]", logoutMessage);
            final LogoutHttpMessage msg = new LogoutHttpMessage(r.getLogoutUrl(), logoutMessage, true);
            logoutUrls.put(r, msg);
            r.setStatus(LogoutRequestStatus.SUCCESS);
            r.getService().setLoggedOutAlready(true);
        });
        if (!logoutUrls.isEmpty()) {
            context.getFlowScope().put("logoutUrls", logoutUrls);
            return new EventFactorySupport().event(this, "propagate");
        }
    }
    return new EventFactorySupport().event(this, FINISH_EVENT);
}
Also used : LogoutManager(org.apereo.cas.logout.LogoutManager) LogoutRequest(org.apereo.cas.logout.LogoutRequest) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogoutRequestStatus(org.apereo.cas.logout.LogoutRequestStatus) HashMap(java.util.HashMap) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) RequestContext(org.springframework.webflow.execution.RequestContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) Map(java.util.Map) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) HashMap(java.util.HashMap) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) LogoutRequest(org.apereo.cas.logout.LogoutRequest) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 2 with LogoutHttpMessage

use of org.apereo.cas.logout.LogoutHttpMessage in project cas by apereo.

the class FrontChannelLogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) {
    val logoutRequests = WebUtils.getLogoutRequests(context);
    if (logoutRequests == null || logoutRequests.isEmpty()) {
        return getFinishLogoutEvent();
    }
    if (casProperties.getSlo().isDisabled()) {
        LOGGER.debug("Single logout callbacks are disabled");
        return getFinishLogoutEvent();
    }
    val logoutUrls = new HashMap<SingleLogoutRequestContext, LogoutHttpMessage>();
    logoutRequests.stream().filter(r -> r.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED).forEach(r -> {
        LOGGER.debug("Using logout url [{}] for front-channel logout requests", r.getLogoutUrl().toExternalForm());
        logoutExecutionPlan.getSingleLogoutServiceMessageHandlers().stream().sorted(Comparator.comparing(SingleLogoutServiceMessageHandler::getOrder)).filter(handler -> handler.supports(r.getExecutionRequest(), r.getService())).forEach(handler -> {
            val logoutMessage = handler.createSingleLogoutMessage(r);
            LOGGER.debug("Front-channel logout message to send to [{}] is [{}]", r.getLogoutUrl(), logoutMessage);
            val msg = new LogoutHttpMessage(r.getLogoutUrl(), logoutMessage.getPayload(), true);
            logoutUrls.put(r, msg);
            r.setStatus(LogoutRequestStatus.SUCCESS);
            r.getService().setLoggedOutAlready(true);
        });
    });
    if (!logoutUrls.isEmpty()) {
        WebUtils.putLogoutUrls(context, logoutUrls);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_PROPAGATE);
    }
    return getFinishLogoutEvent();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ArgumentExtractor(org.apereo.cas.web.support.ArgumentExtractor) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) LogoutRequestStatus(org.apereo.cas.logout.LogoutRequestStatus) SingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.SingleLogoutServiceMessageHandler) HashMap(java.util.HashMap) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) RequestContext(org.springframework.webflow.execution.RequestContext) LogoutExecutionPlan(org.apereo.cas.logout.LogoutExecutionPlan) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) SingleLogoutRequestContext(org.apereo.cas.logout.slo.SingleLogoutRequestContext) WebUtils(org.apereo.cas.web.support.WebUtils) Comparator(java.util.Comparator) Event(org.springframework.webflow.execution.Event) ServicesManager(org.apereo.cas.services.ServicesManager) HashMap(java.util.HashMap) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Aggregations

HashMap (java.util.HashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LogoutHttpMessage (org.apereo.cas.logout.LogoutHttpMessage)2 LogoutRequestStatus (org.apereo.cas.logout.LogoutRequestStatus)2 WebUtils (org.apereo.cas.web.support.WebUtils)2 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)2 Event (org.springframework.webflow.execution.Event)2 RequestContext (org.springframework.webflow.execution.RequestContext)2 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 LogoutExecutionPlan (org.apereo.cas.logout.LogoutExecutionPlan)1 LogoutManager (org.apereo.cas.logout.LogoutManager)1 LogoutRequest (org.apereo.cas.logout.LogoutRequest)1 SingleLogoutRequestContext (org.apereo.cas.logout.slo.SingleLogoutRequestContext)1