use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class AbstractTicketRegistry method deleteTicket.
@Override
public int deleteTicket(final String ticketId) {
final AtomicInteger count = new AtomicInteger(0);
if (StringUtils.isBlank(ticketId)) {
return count.intValue();
}
final Ticket ticket = getTicket(ticketId);
if (ticket == null) {
return count.intValue();
}
if (ticket instanceof TicketGrantingTicket) {
LOGGER.debug("Removing children of ticket [{}] from the registry.", ticket.getId());
final TicketGrantingTicket tgt = (TicketGrantingTicket) ticket;
count.addAndGet(deleteChildren(tgt));
if (ticket instanceof ProxyGrantingTicket) {
deleteProxyGrantingTicketFromParent((ProxyGrantingTicket) ticket);
} else {
deleteLinkedProxyGrantingTickets(count, tgt);
}
}
LOGGER.debug("Removing ticket [{}] from the registry.", ticket);
if (deleteSingleTicket(ticketId)) {
count.incrementAndGet();
}
return count.intValue();
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class AbstractTicketRegistry method decodeTicket.
/**
* Decode ticket.
*
* @param result the result
* @return the ticket
*/
@SneakyThrows
protected Ticket decodeTicket(final Ticket result) {
if (!isCipherExecutorEnabled()) {
LOGGER.trace(MESSAGE);
return result;
}
if (result == null) {
LOGGER.warn("Ticket passed is null and cannot be decoded");
return null;
}
if (!result.getClass().isAssignableFrom(EncodedTicket.class)) {
LOGGER.warn("Ticket passed is not an encoded ticket type; rather it's a [{}], no decoding is necessary.", result.getClass().getSimpleName());
return result;
}
LOGGER.debug("Attempting to decode [{}]", result);
final EncodedTicket encodedTicket = (EncodedTicket) result;
final Ticket ticket = SerializationUtils.decodeAndDeserializeObject(encodedTicket.getEncodedTicket(), this.cipherExecutor, Ticket.class);
LOGGER.debug("Decoded ticket to [{}]", ticket);
return ticket;
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class AbstractTicketRegistryTests method verifyGetTicketsFromRegistryEqualToTicketsAdded.
@Test
public void verifyGetTicketsFromRegistryEqualToTicketsAdded() {
Assume.assumeTrue(isIterableRegistry());
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 -> {
throw new AssertionError("Ticket " + ticket + " was not found in retrieval of collection of all tickets.");
});
} catch (final Exception e) {
throw new AssertionError(EXCEPTION_CAUGHT_NONE_EXPECTED + e.getMessage(), e);
}
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class AbstractTicketRegistryTests method verifyWriteGetDelete.
@Test
public void verifyWriteGetDelete() {
final Ticket ticket = new TicketGrantingTicketImpl(TicketGrantingTicket.PREFIX, CoreAuthenticationTestUtils.getAuthentication(), new NeverExpiresExpirationPolicy());
ticketRegistry.addTicket(ticket);
final Ticket ticketFromRegistry = ticketRegistry.getTicket(TicketGrantingTicket.PREFIX);
assertNotNull(ticketFromRegistry);
assertEquals(TicketGrantingTicket.PREFIX, ticketFromRegistry.getId());
ticketRegistry.deleteTicket(TicketGrantingTicket.PREFIX);
assertNull(ticketRegistry.getTicket(TicketGrantingTicket.PREFIX));
}
use of org.apereo.cas.ticket.Ticket in project cas by apereo.
the class MemcachedTicketRegistry method updateTicket.
@Override
public Ticket updateTicket(final Ticket ticketToUpdate) {
final Ticket ticket = encodeTicket(ticketToUpdate);
LOGGER.debug("Updating ticket [{}]", ticket);
final MemcachedClientIF clientFromPool = getClientFromPool();
try {
clientFromPool.replace(ticket.getId(), getTimeout(ticketToUpdate), ticket);
} catch (final Exception e) {
LOGGER.error("Failed updating [{}]", ticket, e);
} finally {
returnClientToPool(clientFromPool);
}
return ticket;
}
Aggregations