Search in sources :

Example 1 with CasTicketGrantingTicketDestroyedEvent

use of org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent in project cas by apereo.

the class DefaultCentralAuthenticationService method destroyTicketGrantingTicket.

@Audit(action = "TICKET_GRANTING_TICKET_DESTROYED", actionResolverName = "DESTROY_TICKET_GRANTING_TICKET_RESOLVER", resourceResolverName = "DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "DESTROY_TICKET_GRANTING_TICKET_METER")
@Counted(name = "DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic = true)
@Override
public List<LogoutRequest> destroyTicketGrantingTicket(final String ticketGrantingTicketId) {
    try {
        LOGGER.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
        final TicketGrantingTicket ticket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        LOGGER.debug("Ticket found. Processing logout requests and then deleting the ticket...");
        AuthenticationCredentialsThreadLocalBinder.bindCurrent(ticket.getAuthentication());
        final List<LogoutRequest> logoutRequests = this.logoutManager.performLogout(ticket);
        deleteTicket(ticketGrantingTicketId);
        doPublishEvent(new CasTicketGrantingTicketDestroyedEvent(this, ticket));
        return logoutRequests;
    } catch (final InvalidTicketException e) {
        LOGGER.debug("TicketGrantingTicket [{}] cannot be found in the ticket registry.", ticketGrantingTicketId);
    }
    return new ArrayList<>(0);
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) ArrayList(java.util.ArrayList) CasTicketGrantingTicketDestroyedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent) LogoutRequest(org.apereo.cas.logout.LogoutRequest) Audit(org.apereo.inspektr.audit.annotation.Audit) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with CasTicketGrantingTicketDestroyedEvent

use of org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent in project cas by apereo.

the class DefaultSingleLogoutRequestExecutor method execute.

@Override
public List<SingleLogoutRequestContext> execute(final String ticketId, final HttpServletRequest request, final HttpServletResponse response) {
    val ca = AuthenticationCredentialsThreadLocalBinder.getCurrentAuthentication();
    try {
        val ticket = centralAuthenticationService.getTicket(ticketId, Ticket.class);
        LOGGER.debug("Ticket [{}] found. Processing logout requests and then deleting the ticket...", ticket.getId());
        val logoutRequests = new ArrayList<SingleLogoutRequestContext>();
        if (ticket instanceof TicketGrantingTicket) {
            val tgt = (TicketGrantingTicket) ticket;
            AuthenticationCredentialsThreadLocalBinder.bindCurrent(tgt.getAuthentication());
            logoutRequests.addAll(logoutManager.performLogout(SingleLogoutExecutionRequest.builder().ticketGrantingTicket(tgt).httpServletRequest(Optional.of(request)).httpServletResponse(Optional.of(response)).build()));
            applicationContext.publishEvent(new CasTicketGrantingTicketDestroyedEvent(this, tgt));
        }
        LOGGER.trace("Removing ticket [{}] from registry...", ticketId);
        centralAuthenticationService.deleteTicket(ticketId);
        return logoutRequests;
    } catch (final Exception e) {
        val msg = String.format("Ticket-granting ticket [%s] cannot be found in the ticket registry.", ticketId);
        LOGGER.debug(msg, e);
    } finally {
        AuthenticationCredentialsThreadLocalBinder.bindCurrent(ca);
    }
    return new ArrayList<>(0);
}
Also used : lombok.val(lombok.val) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ArrayList(java.util.ArrayList) CasTicketGrantingTicketDestroyedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent)

Example 3 with CasTicketGrantingTicketDestroyedEvent

use of org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent in project cas by apereo.

the class CasAuthenticationEventListenerTests method verifyCasTicketGrantingTicketDestroyed.

@Test
public void verifyCasTicketGrantingTicketDestroyed() {
    val event = new CasTicketGrantingTicketDestroyedEvent(this, new MockTicketGrantingTicket("casuser"));
    applicationContext.publishEvent(event);
    assertFalse(casEventRepository.load().findAny().isEmpty());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) CasTicketGrantingTicketDestroyedEvent(org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CasTicketGrantingTicketDestroyedEvent (org.apereo.cas.support.events.ticket.CasTicketGrantingTicketDestroyedEvent)3 ArrayList (java.util.ArrayList)2 lombok.val (lombok.val)2 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)2 Counted (com.codahale.metrics.annotation.Counted)1 Metered (com.codahale.metrics.annotation.Metered)1 Timed (com.codahale.metrics.annotation.Timed)1 LogoutRequest (org.apereo.cas.logout.LogoutRequest)1 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1 Audit (org.apereo.inspektr.audit.annotation.Audit)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1