Search in sources :

Example 6 with LogoutRequest

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

the class LogoutActionTests method verifyLogoutRequestBack.

@Test
public void verifyLogoutRequestBack() throws Exception {
    final Cookie cookie = new Cookie(COOKIE_TGC_ID, "test");
    this.request.setCookies(cookie);
    final LogoutRequest logoutRequest = new DefaultLogoutRequest(StringUtils.EMPTY, null, null);
    logoutRequest.setStatus(LogoutRequestStatus.SUCCESS);
    WebUtils.putLogoutRequests(this.requestContext, Arrays.asList(logoutRequest));
    final LogoutProperties properties = new LogoutProperties();
    this.logoutAction = new LogoutAction(getWebApplicationServiceFactory(), this.serviceManager, properties);
    final Event event = this.logoutAction.doExecute(this.requestContext);
    assertEquals(CasWebflowConstants.TRANSITION_ID_FINISH, event.getId());
}
Also used : Cookie(javax.servlet.http.Cookie) LogoutProperties(org.apereo.cas.configuration.model.core.logout.LogoutProperties) LogoutAction(org.apereo.cas.web.flow.logout.LogoutAction) DefaultLogoutRequest(org.apereo.cas.logout.DefaultLogoutRequest) Event(org.springframework.webflow.execution.Event) LogoutRequest(org.apereo.cas.logout.LogoutRequest) DefaultLogoutRequest(org.apereo.cas.logout.DefaultLogoutRequest) Test(org.junit.Test)

Example 7 with LogoutRequest

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

the class LogoutActionTests method verifyLogoutRequestFront.

@SuppressWarnings("unchecked")
@Test
public void verifyLogoutRequestFront() throws Exception {
    final Cookie cookie = new Cookie(COOKIE_TGC_ID, "test");
    this.request.setCookies(cookie);
    final LogoutRequest logoutRequest = new DefaultLogoutRequest(StringUtils.EMPTY, null, null);
    WebUtils.putLogoutRequests(this.requestContext, Arrays.asList(logoutRequest));
    final LogoutProperties properties = new LogoutProperties();
    this.logoutAction = new LogoutAction(getWebApplicationServiceFactory(), this.serviceManager, properties);
    final Event event = this.logoutAction.doExecute(this.requestContext);
    assertEquals(CasWebflowConstants.TRANSITION_ID_FRONT, event.getId());
    final List<LogoutRequest> logoutRequests = WebUtils.getLogoutRequests(this.requestContext);
    assertEquals(1, logoutRequests.size());
    assertEquals(logoutRequest, logoutRequests.get(0));
}
Also used : Cookie(javax.servlet.http.Cookie) LogoutProperties(org.apereo.cas.configuration.model.core.logout.LogoutProperties) LogoutAction(org.apereo.cas.web.flow.logout.LogoutAction) DefaultLogoutRequest(org.apereo.cas.logout.DefaultLogoutRequest) Event(org.springframework.webflow.execution.Event) LogoutRequest(org.apereo.cas.logout.LogoutRequest) DefaultLogoutRequest(org.apereo.cas.logout.DefaultLogoutRequest) Test(org.junit.Test)

Example 8 with LogoutRequest

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

the class TerminateSessionAction method terminate.

/**
     * Terminates the CAS SSO session by destroying the TGT (if any) and removing cookies related to the SSO session.
     *
     * @param context Request context.
     * @return "success"
     */
public Event terminate(final RequestContext context) {
    // in login's webflow : we can get the value from context as it has already been stored
    try {
        final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
        final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
        String tgtId = WebUtils.getTicketGrantingTicketId(context);
        // for logout, we need to get the cookie's value
        if (tgtId == null) {
            tgtId = this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
        }
        if (tgtId != null) {
            LOGGER.debug("Destroying SSO session linked to ticket-granting ticket [{}]", tgtId);
            final List<LogoutRequest> logoutRequests = this.centralAuthenticationService.destroyTicketGrantingTicket(tgtId);
            WebUtils.putLogoutRequests(context, logoutRequests);
        }
        LOGGER.debug("Removing CAS cookies");
        this.ticketGrantingTicketCookieGenerator.removeCookie(response);
        this.warnCookieGenerator.removeCookie(response);
        destroyApplicationSession(request, response);
        LOGGER.debug("Terminated all CAS sessions successfully.");
        return this.eventFactorySupport.success(this);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogoutRequest(org.apereo.cas.logout.LogoutRequest)

Example 9 with LogoutRequest

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

the class TerminateSessionAction method terminate.

/**
 * Terminates the CAS SSO session by destroying the TGT (if any) and removing cookies related to the SSO session.
 *
 * @param context Request context.
 * @return "success"
 */
@SneakyThrows
public Event terminate(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponseFromExternalWebflowContext(context);
    String tgtId = WebUtils.getTicketGrantingTicketId(context);
    // for logout, we need to get the cookie's value
    if (tgtId == null) {
        tgtId = this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);
    }
    if (tgtId != null) {
        LOGGER.debug("Destroying SSO session linked to ticket-granting ticket [{}]", tgtId);
        final List<LogoutRequest> logoutRequests = this.centralAuthenticationService.destroyTicketGrantingTicket(tgtId);
        WebUtils.putLogoutRequests(context, logoutRequests);
    }
    LOGGER.debug("Removing CAS cookies");
    this.ticketGrantingTicketCookieGenerator.removeCookie(response);
    this.warnCookieGenerator.removeCookie(response);
    destroyApplicationSession(request, response);
    LOGGER.debug("Terminated all CAS sessions successfully.");
    return this.eventFactorySupport.success(this);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogoutRequest(org.apereo.cas.logout.LogoutRequest) SneakyThrows(lombok.SneakyThrows)

Aggregations

LogoutRequest (org.apereo.cas.logout.LogoutRequest)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Event (org.springframework.webflow.execution.Event)6 List (java.util.List)4 LogoutProperties (org.apereo.cas.configuration.model.core.logout.LogoutProperties)4 LogoutRequestStatus (org.apereo.cas.logout.LogoutRequestStatus)4 WebUtils (org.apereo.cas.web.support.WebUtils)4 RequestContext (org.springframework.webflow.execution.RequestContext)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Cookie (javax.servlet.http.Cookie)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Slf4j (lombok.extern.slf4j.Slf4j)2 StringUtils (org.apache.commons.lang3.StringUtils)2 CasProtocolConstants (org.apereo.cas.CasProtocolConstants)2 Service (org.apereo.cas.authentication.principal.Service)2 ServiceFactory (org.apereo.cas.authentication.principal.ServiceFactory)2 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)2 DefaultLogoutRequest (org.apereo.cas.logout.DefaultLogoutRequest)2