Search in sources :

Example 31 with Ticket

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

the class MemCacheTicketRegistry method addTicket.

@Override
public void addTicket(final Ticket ticketToAdd) {
    Assert.notNull(this.client, NO_MEMCACHED_CLIENT_IS_DEFINED);
    try {
        final Ticket ticket = encodeTicket(ticketToAdd);
        LOGGER.debug("Adding ticket [{}]", ticket);
        final int timeout = getTimeout(ticketToAdd);
        if (!this.client.add(ticket.getId(), getTimeout(ticketToAdd), ticket).get()) {
            LOGGER.error("Failed to add [{}] without timeout [{}]", ticketToAdd, timeout);
        }
        // Sanity check to ensure ticket can retrieved
        if (this.client.get(ticket.getId()) == null) {
            LOGGER.warn("Ticket [{}] was added to memcached with timeout [{}], yet it cannot be retrieved. " + "Ticket expiration policy may be too aggressive ?", ticketToAdd, timeout);
        }
    } catch (final InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for response to async add operation for ticket [{}]." + "Cannot determine whether add was successful.", ticketToAdd);
    } catch (final Exception e) {
        LOGGER.error("Failed adding [{}]", ticketToAdd, e);
    }
}
Also used : Ticket(org.apereo.cas.ticket.Ticket)

Example 32 with Ticket

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

the class AbstractCentralAuthenticationService method getTicket.

/**
 * {@inheritDoc}
 * <p>
 * Note:
 * Synchronization on ticket object in case of cache based registry doesn't serialize
 * access to critical section. The reason is that cache pulls serialized data and
 * builds new object, most likely for each pull. Is this synchronization needed here?
 */
@Transactional(transactionManager = "ticketTransactionManager", noRollbackFor = InvalidTicketException.class)
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name = "GET_TICKET_COUNTER", monotonic = true)
@Override
public <T extends Ticket> T getTicket(@NonNull final String ticketId, final Class<T> clazz) throws InvalidTicketException {
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);
    verifyTicketState(ticket, ticketId, clazz);
    return (T) ticket;
}
Also used : TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) Counted(com.codahale.metrics.annotation.Counted) Metered(com.codahale.metrics.annotation.Metered) Timed(com.codahale.metrics.annotation.Timed) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with Ticket

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

the class TicketGrantingTicketCheckAction method doExecute.

/**
 * Determines whether the TGT in the flow request context is valid.
 *
 * @param requestContext Flow request context.
 *
 * @return {@link #NOT_EXISTS}, {@link #INVALID}, or {@link #VALID}.
 */
@Override
public Event doExecute(final RequestContext requestContext) {
    final String tgtId = WebUtils.getTicketGrantingTicketId(requestContext);
    if (!StringUtils.hasText(tgtId)) {
        return new Event(this, NOT_EXISTS);
    }
    String eventId = INVALID;
    try {
        final Ticket ticket = this.centralAuthenticationService.getTicket(tgtId, Ticket.class);
        if (ticket != null && !ticket.isExpired()) {
            eventId = VALID;
        }
    } catch (final AbstractTicketException e) {
        LOGGER.trace("Could not retrieve ticket id [{}] from registry.", e.getMessage());
    }
    return new Event(this, eventId);
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) Event(org.springframework.webflow.execution.Event) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException)

Example 34 with Ticket

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

the class AbstractMapBasedTicketRegistry method addTicket.

@Override
public void addTicket(@NonNull final Ticket ticket) {
    final Ticket encTicket = encodeTicket(ticket);
    LOGGER.debug("Added ticket [{}] to registry.", ticket.getId());
    getMapInstance().put(encTicket.getId(), encTicket);
}
Also used : Ticket(org.apereo.cas.ticket.Ticket)

Example 35 with Ticket

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

the class AbstractTicketRegistry method encodeTicket.

/**
 * Encode ticket.
 *
 * @param ticket the ticket
 * @return the ticket
 */
@SneakyThrows
protected Ticket encodeTicket(final Ticket ticket) {
    if (!isCipherExecutorEnabled()) {
        LOGGER.trace(MESSAGE);
        return ticket;
    }
    if (ticket == null) {
        LOGGER.debug("Ticket passed is null and cannot be encoded");
        return null;
    }
    LOGGER.debug("Encoding ticket [{}]", ticket);
    final byte[] encodedTicketObject = SerializationUtils.serializeAndEncodeObject(this.cipherExecutor, ticket);
    final String encodedTicketId = encodeTicketId(ticket.getId());
    final Ticket encodedTicket = new EncodedTicket(encodedTicketId, ByteSource.wrap(encodedTicketObject).read());
    LOGGER.debug("Created encoded ticket [{}]", encodedTicket);
    return encodedTicket;
}
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) SneakyThrows(lombok.SneakyThrows)

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