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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations