Search in sources :

Example 26 with Ticket

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);
}
Also used : MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) ByteSource(com.google.common.io.ByteSource) Test(org.junit.Test)

Example 27 with Ticket

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);
    }
}
Also used : Collection(java.util.Collection) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Test(org.junit.Test) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Service(org.apereo.cas.authentication.principal.Service) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Assert(org.junit.Assert) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) Ticket(org.apereo.cas.ticket.Ticket) Before(org.junit.Before) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Example 28 with Ticket

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

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

Example 30 with Ticket

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

Aggregations

Ticket (org.apereo.cas.ticket.Ticket)38 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)13 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)11 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)6 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)6 Test (org.junit.Test)6 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)5 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)2 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)2 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)2 Counted (com.codahale.metrics.annotation.Counted)2 Metered (com.codahale.metrics.annotation.Metered)2 Timed (com.codahale.metrics.annotation.Timed)2 SerializableDocument (com.couchbase.client.java.document.SerializableDocument)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2