Search in sources :

Example 21 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class InfinispanTicketRegistry method getTicket.

@Override
public Ticket getTicket(final String ticketId) {
    final String encTicketId = encodeTicketId(ticketId);
    if (ticketId == null) {
        return null;
    }
    final Ticket result = decodeTicket(Ticket.class.cast(cache.get(encTicketId)));
    if (result != null && result.isExpired()) {
        LOGGER.debug("Ticket [{}] has expired and is now removed from the cache", result.getId());
        this.cache.remove(encTicketId);
        return null;
    }
    return result;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket)

Example 22 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class AbstractTicketRegistry method getTicket.

/**
     *
     *
     * @return specified ticket from the registry
     * @throws IllegalArgumentException if class is null.
     * @throws ClassCastException       if class does not match requested ticket
     *                                  class.
     */
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<T> clazz) {
    Assert.notNull(clazz, "clazz cannot be null");
    final Ticket ticket = this.getTicket(ticketId);
    if (ticket == null) {
        return null;
    }
    if (!clazz.isAssignableFrom(ticket.getClass())) {
        throw new ClassCastException("Ticket [" + ticket.getId() + " is of type " + ticket.getClass() + " when we were expecting " + clazz);
    }
    return (T) ticket;
}
Also used : ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket)

Example 23 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class DefaultTicketRegistryCleaner method cleanInternal.

/**
     * Clean tickets.
     */
protected void cleanInternal() {
    final Collection<Ticket> ticketsToRemove = ticketRegistry.getTickets().stream().filter(Ticket::isExpired).collect(Collectors.toSet());
    LOGGER.debug("[{}] expired tickets found.", ticketsToRemove.size());
    int count = 0;
    for (final Ticket ticket : ticketsToRemove) {
        if (ticket instanceof TicketGrantingTicket) {
            LOGGER.debug("Cleaning up expired ticket-granting ticket [{}]", ticket.getId());
            logoutManager.performLogout((TicketGrantingTicket) ticket);
            count += ticketRegistry.deleteTicket(ticket.getId());
        } else if (ticket instanceof ServiceTicket) {
            LOGGER.debug("Cleaning up expired service ticket [{}]", ticket.getId());
            count += ticketRegistry.deleteTicket(ticket.getId());
        } else {
            LOGGER.warn("Unknown ticket type [{}] found to clean", ticket.getClass().getSimpleName());
        }
    }
    LOGGER.info("[{}] expired tickets removed.", count);
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket)

Example 24 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class TicketEncryptionDecryptionTests method checkSerializationOfTgt.

@Test
public void checkSerializationOfTgt() {
    final byte[] bytes = SerializationUtils.serializeAndEncodeObject(cipher, tgt);
    final Ticket obj = SerializationUtils.decodeAndDeserializeObject(bytes, cipher, Ticket.class);
    assertNotNull(obj);
}
Also used : MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) Test(org.junit.Test)

Example 25 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class TicketEncryptionDecryptionTests method checkSerializationOfTgtByteSource.

@Test
public void checkSerializationOfTgtByteSource() throws Exception {
    final ByteSource bytes = ByteSource.wrap(SerializationUtils.serializeAndEncodeObject(cipher, tgt));
    final Ticket obj = SerializationUtils.decodeAndDeserializeObject(bytes.read(), cipher, Ticket.class);
    assertNotNull(obj);
}
Also used : MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) ByteSource(com.google.common.io.ByteSource) Test(org.junit.Test)

Aggregations

Ticket (org.apereo.cas.ticket.Ticket)60 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)17 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)15 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)14 Test (org.junit.Test)10 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)7 ArrayList (java.util.ArrayList)5 Event (org.springframework.webflow.execution.Event)4 HashMap (java.util.HashMap)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)2 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)2 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)2 Counted (com.codahale.metrics.annotation.Counted)2 Metered (com.codahale.metrics.annotation.Metered)2 Timed (com.codahale.metrics.annotation.Timed)2 SerializableDocument (com.couchbase.client.java.document.SerializableDocument)2 Collection (java.util.Collection)2