use of org.apereo.cas.ticket.TicketDefinition in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method get.
/**
* Get ticket.
*
* @param ticketId the ticket id
* @param encodedTicketId the encoded ticket id
* @return the ticket
*/
public Ticket get(final String ticketId, final String encodedTicketId) {
final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
if (metadata != null) {
final Map<String, AttributeValue> keys = new HashMap<>();
keys.put(ColumnNames.ID.getColumnName(), new AttributeValue(encodedTicketId));
final GetItemRequest request = new GetItemRequest().withKey(keys).withTableName(metadata.getProperties().getStorageName());
LOGGER.debug("Submitting request [{}] to get ticket item [{}]", request, ticketId);
final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
if (returnItem != null) {
final Ticket ticket = deserializeTicket(returnItem);
LOGGER.debug("Located ticket [{}]", ticket);
if (ticket == null || ticket.isExpired()) {
LOGGER.warn("The expiration policy for ticket id [{}] has expired the ticket", ticketId);
return null;
}
return ticket;
}
} else {
LOGGER.warn("No ticket definition could be found in the catalog to match [{}]", ticketId);
}
return null;
}
use of org.apereo.cas.ticket.TicketDefinition in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method delete.
/**
* Delete.
*
* @param ticketId the ticket id
* @param encodedTicketId the encoded ticket id
* @return the boolean
*/
public boolean delete(final String ticketId, final String encodedTicketId) {
final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
if (metadata != null) {
final DeleteItemRequest del = new DeleteItemRequest().withTableName(metadata.getProperties().getStorageName()).withKey(CollectionUtils.wrap(ColumnNames.ID.getColumnName(), new AttributeValue(encodedTicketId)));
LOGGER.debug("Submitting delete request [{}] for ticket [{}]", del, ticketId);
final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del);
LOGGER.debug("Delete request came back with result [{}]", res);
return res != null;
}
return false;
}
use of org.apereo.cas.ticket.TicketDefinition in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method createTicketTables.
/**
* Create ticket tables.
*
* @param deleteTables the delete tables
*/
public void createTicketTables(final boolean deleteTables) {
final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
metadata.forEach(Unchecked.consumer(r -> {
final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(r.getProperties().getStorageName());
if (deleteTables) {
final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
}
LOGGER.debug("Sending delete request [{}] to create table", request);
TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
}));
}
use of org.apereo.cas.ticket.TicketDefinition in project cas by apereo.
the class EhCacheTicketRegistry method deleteSingleTicket.
/**
* Either the element is removed from the cache
* or it's not found in the cache and is already removed.
* Thus the result of this op would always be true.
*/
@Override
public boolean deleteSingleTicket(final String ticketId) {
final Ticket ticket = getTicket(ticketId);
if (ticket == null) {
LOGGER.debug("Ticket [{}] cannot be retrieved from the cache", ticketId);
return true;
}
final TicketDefinition metadata = this.ticketCatalog.find(ticket);
final Ehcache cache = getTicketCacheFor(metadata);
if (cache.remove(encodeTicketId(ticket.getId()))) {
LOGGER.debug("Ticket [{}] is removed", ticket.getId());
}
return true;
}
use of org.apereo.cas.ticket.TicketDefinition in project cas by apereo.
the class HazelcastTicketRegistryConfiguration method buildHazelcastMapConfigurations.
private Map<String, MapConfig> buildHazelcastMapConfigurations(final TicketCatalog ticketCatalog) {
final Map<String, MapConfig> mapConfigs = new HashMap<>();
final HazelcastTicketRegistryProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
final HazelcastConfigurationFactory factory = new HazelcastConfigurationFactory();
final Collection<TicketDefinition> definitions = ticketCatalog.findAll();
definitions.forEach(t -> {
final MapConfig mapConfig = factory.buildMapConfig(hz, t.getProperties().getStorageName(), t.getProperties().getStorageTimeout());
LOGGER.debug("Created Hazelcast map configuration for [{}]", t);
mapConfigs.put(t.getProperties().getStorageName(), mapConfig);
});
return mapConfigs;
}
Aggregations