Search in sources :

Example 1 with TicketDefinition

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;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest)

Example 2 with TicketDefinition

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;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult)

Example 3 with TicketDefinition

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);
    }));
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) PutItemResult(com.amazonaws.services.dynamodbv2.model.PutItemResult) Getter(lombok.Getter) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) KeyType(com.amazonaws.services.dynamodbv2.model.KeyType) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TicketCatalog(org.apereo.cas.ticket.TicketCatalog) Unchecked(org.jooq.lambda.Unchecked) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest) ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) Collection(java.util.Collection) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Collectors(java.util.stream.Collectors) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TableUtils(com.amazonaws.services.dynamodbv2.util.TableUtils) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest) ScalarAttributeType(com.amazonaws.services.dynamodbv2.model.ScalarAttributeType) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) Slf4j(lombok.extern.slf4j.Slf4j) DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) AllArgsConstructor(lombok.AllArgsConstructor) Ticket(org.apereo.cas.ticket.Ticket) DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement)

Example 4 with TicketDefinition

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;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) Ehcache(net.sf.ehcache.Ehcache)

Example 5 with TicketDefinition

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;
}
Also used : HazelcastConfigurationFactory(org.apereo.cas.hz.HazelcastConfigurationFactory) HashMap(java.util.HashMap) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) HazelcastTicketRegistryProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastTicketRegistryProperties) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

TicketDefinition (org.apereo.cas.ticket.TicketDefinition)28 Ticket (org.apereo.cas.ticket.Ticket)15 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 Query (javax.persistence.Query)4 Ehcache (net.sf.ehcache.Ehcache)4 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ToString (lombok.ToString)3 Query (org.springframework.data.mongodb.core.query.Query)3 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)2 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)2 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)2 PutItemRequest (com.amazonaws.services.dynamodbv2.model.PutItemRequest)2 PutItemResult (com.amazonaws.services.dynamodbv2.model.PutItemResult)2 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 TypedQuery (javax.persistence.TypedQuery)2 Element (net.sf.ehcache.Element)2