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);
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class AbstractTicketRegistryTests method verifyGetTicketsFromRegistryEqualToTicketsAdded.
@Test
public void verifyGetTicketsFromRegistryEqualToTicketsAdded() {
final Collection<Ticket> tickets = new ArrayList<>();
for (int i = 0; i < TICKETS_IN_REGISTRY; i++) {
final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX + i, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
final ServiceTicket st = ticketGrantingTicket.grantServiceTicket("ST" + i, RegisteredServiceTestUtils.getService(), new NeverExpiresExpirationPolicy(), false, true);
tickets.add(ticketGrantingTicket);
tickets.add(st);
this.ticketRegistry.addTicket(ticketGrantingTicket);
this.ticketRegistry.addTicket(st);
}
try {
final Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets();
assertEquals("The size of the registry is not the same as the collection.", tickets.size(), ticketRegistryTickets.size());
tickets.stream().filter(ticket -> !ticketRegistryTickets.contains(ticket)).forEach(ticket -> fail("Ticket was added to registry but was not found in retrieval of collection of all tickets."));
} catch (final Exception e) {
fail(EXCEPTION_CAUGHT_NONE_EXPECTED);
}
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class EhCacheTicketRegistry method getTicket.
@Override
public Ticket getTicket(final String ticketIdToGet) {
final String ticketId = encodeTicketId(ticketIdToGet);
if (ticketId == null) {
return null;
}
final Element element = this.ehcacheTicketsCache.get(ticketId);
if (element == null) {
LOGGER.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
final Ticket ticket = decodeTicket((Ticket) element.getObjectValue());
final CacheConfiguration config = new CacheConfiguration();
config.setTimeToIdleSeconds(ticket.getExpirationPolicy().getTimeToIdle());
config.setTimeToLiveSeconds(ticket.getExpirationPolicy().getTimeToLive());
if (element.isExpired(config) || ticket.isExpired()) {
LOGGER.debug("Ticket [{}] has expired", ticket.getId());
this.ehcacheTicketsCache.evictExpiredElements();
this.ehcacheTicketsCache.flush();
return null;
}
return ticket;
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class EhCacheTicketRegistry method addTicket.
@Override
public void addTicket(final Ticket ticketToAdd) {
final Ticket ticket = encodeTicket(ticketToAdd);
final Element element = new Element(ticket.getId(), ticket);
int idleValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
if (idleValue <= 0) {
idleValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
}
if (idleValue <= 0) {
idleValue = Integer.MAX_VALUE;
}
element.setTimeToIdle(idleValue);
int aliveValue = ticketToAdd.getExpirationPolicy().getTimeToLive().intValue();
if (aliveValue <= 0) {
aliveValue = Integer.MAX_VALUE;
}
element.setTimeToLive(aliveValue);
LOGGER.debug("Adding ticket [{}] to the cache [{}] to live [{}] seconds and stay idle for [{}] seconds", ticket.getId(), this.ehcacheTicketsCache.getName(), aliveValue, idleValue);
this.ehcacheTicketsCache.put(element);
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method getAll.
/**
* Gets all.
*
* @return the all
*/
public Collection<Ticket> getAll() {
final Collection<Ticket> tickets = new ArrayList<>();
final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
metadata.forEach(r -> {
final ScanRequest scan = new ScanRequest(r.getProperties().getStorageName());
LOGGER.debug("Scanning table with request [{}]", scan);
final ScanResult result = this.amazonDynamoDBClient.scan(scan);
LOGGER.debug("Scanned table with result [{}]", scan);
tickets.addAll(result.getItems().stream().map(this::deserializeTicket).collect(Collectors.toList()));
});
return tickets;
}
Aggregations