Java Code Examples for org.jasig.cas.ticket.TicketGrantingTicket#removeAllServices()

The following examples show how to use org.jasig.cas.ticket.TicketGrantingTicket#removeAllServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogoutManagerImpl.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Perform a back channel logout for a given ticket granting ticket and returns all the logout requests.
 *
 * @param ticket a given ticket granting ticket.
 * @return all logout requests.
 */
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    final Map<String, Service> services;
    // synchronize the retrieval of the services and their cleaning for the TGT
    // to avoid concurrent logout mess ups
    synchronized (ticket) {
        services = ticket.getServices();
        ticket.removeAllServices();
    }
    ticket.markTicketExpired();

    final List<LogoutRequest> logoutRequests = new ArrayList<>();
    // if SLO is not disabled
    if (!this.singleLogoutCallbacksDisabled) {
        // through all services
        for (final Map.Entry<String, Service> entry : services.entrySet()) {
            // it's a SingleLogoutService, else ignore
            final Service service = entry.getValue();
            if (service instanceof SingleLogoutService) {
                final LogoutRequest logoutRequest = handleLogoutForSloService((SingleLogoutService) service, entry.getKey());
                if (logoutRequest != null) {
                    LOGGER.debug("Captured logout request [{}]", logoutRequest);
                    logoutRequests.add(logoutRequest);
                }
            }
        }
    }

    return logoutRequests;
}
 
Example 2
Source File: LogoutManagerImpl.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
/**
 * Perform a back channel logout for a given ticket granting ticket and returns all the logout requests.
 *
 * @param ticket a given ticket granting ticket.
 * @return all logout requests.
 */
@Override
public List<LogoutRequest> performLogout(final TicketGrantingTicket ticket) {
    final Map<String, Service> services;
    // synchronize the retrieval of the services and their cleaning for the TGT
    // to avoid concurrent logout mess ups
    synchronized (ticket) {
        services = ticket.getServices();
        ticket.removeAllServices();
    }
    ticket.markTicketExpired();

    final List<LogoutRequest> logoutRequests = new ArrayList<LogoutRequest>();
    // if SLO is not disabled
    if (!disableSingleSignOut) {
        // through all services
        for (final String ticketId : services.keySet()) {
            final Service service = services.get(ticketId);
            // it's a SingleLogoutService, else ignore
            if (service instanceof SingleLogoutService) {
                final SingleLogoutService singleLogoutService = (SingleLogoutService) service;
                // the logout has not performed already
                if (!singleLogoutService.isLoggedOutAlready()) {
                    final LogoutRequest logoutRequest = new LogoutRequest(ticketId, singleLogoutService);
                    // always add the logout request
                    logoutRequests.add(logoutRequest);
                    final RegisteredService registeredService = servicesManager.findServiceBy(service);
                    // the service is no more defined, or the logout type is not defined or is back channel
                    if (registeredService == null || registeredService.getLogoutType() == null
                            || registeredService.getLogoutType() == LogoutType.BACK_CHANNEL) {
                        // perform back channel logout
                        if (performBackChannelLogout(logoutRequest)) {
                            logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);
                        } else {
                            logoutRequest.setStatus(LogoutRequestStatus.FAILURE);
                            LOGGER.warn("Logout message not sent to [{}]; Continuing processing...",
                                    singleLogoutService.getId());
                        }
                    }
                }
            }
        }
    }

    return logoutRequests;
}