org.apereo.cas.ticket.registry.DynamoDbTicketRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cas-server-support-dynamodb-ticket-registry Show documentation
Show all versions of cas-server-support-dynamodb-ticket-registry Show documentation
cas-server-support-dynamodb-ticket-registry
package org.apereo.cas.ticket.registry;
import org.apereo.cas.ticket.Ticket;
import org.apereo.cas.util.crypto.CipherExecutor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import java.util.Collection;
import java.util.function.Predicate;
/**
* This is {@link DynamoDbTicketRegistry}.
*
* @author Misagh Moayyed
* @since 5.1.0
*/
@Slf4j
public class DynamoDbTicketRegistry extends AbstractTicketRegistry {
private final DynamoDbTicketRegistryFacilitator dbTableService;
public DynamoDbTicketRegistry(final CipherExecutor cipher, final DynamoDbTicketRegistryFacilitator dbTableService) {
setCipherExecutor(cipher);
this.dbTableService = dbTableService;
LOGGER.info("Setting up DynamoDb Ticket Registry instance");
}
@Override
public void addTicket(final Ticket ticket) {
try {
LOGGER.debug("Adding ticket [{}] with ttl [{}s]", ticket.getId(), ticket.getExpirationPolicy().getTimeToLive());
val encTicket = encodeTicket(ticket);
this.dbTableService.put(ticket, encTicket);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
@Override
public Ticket getTicket(final String ticketId, final Predicate predicate) {
val encTicketId = encodeTicketId(ticketId);
if (StringUtils.isBlank(encTicketId)) {
return null;
}
LOGGER.debug("Retrieving ticket [{}]", ticketId);
val ticket = this.dbTableService.get(ticketId, encTicketId);
val decodedTicket = decodeTicket(ticket);
if (predicate.test(decodedTicket)) {
return decodedTicket;
}
return null;
}
@Override
public long deleteAll() {
return this.dbTableService.deleteAll();
}
@Override
public Collection extends Ticket> getTickets() {
return decodeTickets(this.dbTableService.getAll());
}
@Override
public Ticket updateTicket(final Ticket ticket) {
addTicket(ticket);
return ticket;
}
@Override
public boolean deleteSingleTicket(final String ticketIdToDelete) {
val ticketId = encodeTicketId(ticketIdToDelete);
return this.dbTableService.delete(ticketIdToDelete, ticketId);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy