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