Search in sources :

Example 1 with SingleLogoutRequestContext

use of org.apereo.cas.logout.slo.SingleLogoutRequestContext in project cas by apereo.

the class DefaultLogoutManager method performLogoutForTicket.

private List<SingleLogoutRequestContext> performLogoutForTicket(final SingleLogoutExecutionRequest context) {
    val ticketToBeLoggedOut = context.getTicketGrantingTicket();
    val streamServices = Stream.concat(Stream.of(ticketToBeLoggedOut.getServices()), Stream.of(ticketToBeLoggedOut.getProxyGrantingTickets()));
    val logoutServices = streamServices.map(Map::entrySet).flatMap(Set::stream).filter(entry -> entry.getValue() instanceof WebApplicationService).filter(Objects::nonNull).map(entry -> Pair.of(entry.getKey(), (WebApplicationService) entry.getValue())).collect(Collectors.toList());
    val sloHandlers = logoutExecutionPlan.getSingleLogoutServiceMessageHandlers();
    return logoutServices.stream().map(entry -> sloHandlers.stream().sorted(Comparator.comparing(SingleLogoutServiceMessageHandler::getOrder)).filter(handler -> handler.supports(context, entry.getValue())).map(handler -> {
        val service = entry.getValue();
        LOGGER.trace("Handling single logout callback for [{}]", service.getId());
        return handler.handle(service, entry.getKey(), context);
    }).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList())).flatMap(Collection::stream).filter(distinctByKey(SingleLogoutRequestContext::getService)).collect(Collectors.toList());
}
Also used : lombok.val(lombok.val) Getter(lombok.Getter) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.SingleLogoutServiceMessageHandler) Set(java.util.Set) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) SingleLogoutRequestContext(org.apereo.cas.logout.slo.SingleLogoutRequestContext) Comparator(java.util.Comparator) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) SingleLogoutRequestContext(org.apereo.cas.logout.slo.SingleLogoutRequestContext) Set(java.util.Set) Objects(java.util.Objects) SingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.SingleLogoutServiceMessageHandler) Collection(java.util.Collection)

Example 2 with SingleLogoutRequestContext

use of org.apereo.cas.logout.slo.SingleLogoutRequestContext 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

Comparator (java.util.Comparator)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 SingleLogoutRequestContext (org.apereo.cas.logout.slo.SingleLogoutRequestContext)2 SingleLogoutServiceMessageHandler (org.apereo.cas.logout.slo.SingleLogoutServiceMessageHandler)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Getter (lombok.Getter)1