Search in sources :

Example 36 with Ticket

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();
}
Also used : ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket)

Example 37 with Ticket

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;
}
Also used : ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) SneakyThrows(lombok.SneakyThrows)

Example 38 with 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);
    }
}
Also used : IntStream(java.util.stream.IntStream) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) AlwaysExpiresExpirationPolicy(org.apereo.cas.ticket.support.AlwaysExpiresExpirationPolicy) AopTestUtils(org.springframework.test.util.AopTestUtils) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) SpringMethodRule(org.springframework.test.context.junit4.rules.SpringMethodRule) Authentication(org.apereo.cas.authentication.Authentication) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Assume(org.junit.Assume) SpringClassRule(org.springframework.test.context.junit4.rules.SpringClassRule) ClassRule(org.junit.ClassRule) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Before(org.junit.Before) Collection(java.util.Collection) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) Test(org.junit.Test) CipherExecutor(org.apereo.cas.CipherExecutor) CoreTicketUtils(org.apereo.cas.util.CoreTicketUtils) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) Service(org.apereo.cas.authentication.principal.Service) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Assert(org.junit.Assert) Collections(java.util.Collections) CoreAuthenticationTestUtils(org.apereo.cas.authentication.CoreAuthenticationTestUtils) EncryptionRandomizedSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionRandomizedSigningJwtCryptographyProperties) Ticket(org.apereo.cas.ticket.Ticket) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ArrayList(java.util.ArrayList) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Test(org.junit.Test)

Example 39 with Ticket

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));
}
Also used : MockServiceTicket(org.apereo.cas.mock.MockServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ProxyGrantingTicket(org.apereo.cas.ticket.proxy.ProxyGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) Ticket(org.apereo.cas.ticket.Ticket) NeverExpiresExpirationPolicy(org.apereo.cas.ticket.support.NeverExpiresExpirationPolicy) TicketGrantingTicketImpl(org.apereo.cas.ticket.TicketGrantingTicketImpl) Test(org.junit.Test)

Example 40 with Ticket

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;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) MemcachedClientIF(net.spy.memcached.MemcachedClientIF)

Aggregations

Ticket (org.apereo.cas.ticket.Ticket)60 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)17 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)15 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)14 Test (org.junit.Test)10 MockServiceTicket (org.apereo.cas.mock.MockServiceTicket)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 ProxyGrantingTicket (org.apereo.cas.ticket.proxy.ProxyGrantingTicket)7 ArrayList (java.util.ArrayList)5 Event (org.springframework.webflow.execution.Event)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