Search in sources :

Example 11 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class MemCacheTicketRegistry method getTicket.

@Override
public Ticket getTicket(final String ticketIdToGet) {
    Assert.notNull(this.client, NO_MEMCACHED_CLIENT_IS_DEFINED);
    final String ticketId = encodeTicketId(ticketIdToGet);
    try {
        final Ticket t = (Ticket) this.client.get(ticketId);
        if (t != null) {
            return decodeTicket(t);
        }
    } catch (final Exception e) {
        LOGGER.error("Failed fetching [{}] ", ticketId, e);
    }
    return null;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket)

Example 12 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class MemCacheTicketRegistry method updateTicket.

@Override
public Ticket updateTicket(final Ticket ticketToUpdate) {
    Assert.notNull(this.client, NO_MEMCACHED_CLIENT_IS_DEFINED);
    final Ticket ticket = encodeTicket(ticketToUpdate);
    LOGGER.debug("Updating ticket [{}]", ticket);
    try {
        if (!this.client.replace(ticket.getId(), getTimeout(ticketToUpdate), ticket).get()) {
            LOGGER.error("Failed to update [{}]", ticket);
            return null;
        }
    } catch (final InterruptedException e) {
        LOGGER.warn("Interrupted while waiting for response to async replace operation for ticket [{}]. " + "Cannot determine whether update was successful.", ticket);
    } catch (final Exception e) {
        LOGGER.error("Failed updating [{}]", ticket, e);
    }
    return ticket;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket)

Example 13 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class TicketOrCredentialPrincipalResolver method resolveArgument.

/**
     * Resolve the join point argument.
     *
     * @param arg1 the arg
     * @return the resolved string
     */
private String resolveArgument(final Object arg1) {
    LOGGER.debug("Resolving argument [{}] for audit", arg1.getClass().getSimpleName());
    if (arg1 instanceof AuthenticationTransaction) {
        final AuthenticationTransaction transaction = AuthenticationTransaction.class.cast(arg1);
        return resolveArguments(new StringBuilder(), transaction.getCredentials());
    }
    if (arg1 instanceof Credential) {
        return arg1.toString();
    }
    if (arg1 instanceof String) {
        try {
            final Ticket ticket = this.centralAuthenticationService.getTicket((String) arg1, Ticket.class);
            Authentication authentication = null;
            if (ticket instanceof ServiceTicket) {
                authentication = ServiceTicket.class.cast(ticket).getGrantingTicket().getAuthentication();
            } else if (ticket instanceof TicketGrantingTicket) {
                authentication = TicketGrantingTicket.class.cast(ticket).getAuthentication();
            }
            return this.principalIdProvider.getPrincipalIdFrom(authentication);
        } catch (final InvalidTicketException e) {
            LOGGER.trace(e.getMessage(), e);
        }
        LOGGER.debug("Could not locate ticket [{}] in the registry", arg1);
    }
    return WebUtils.getAuthenticatedUsername();
}
Also used : ServiceTicket(org.apereo.cas.ticket.ServiceTicket) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) Ticket(org.apereo.cas.ticket.Ticket) Credential(org.apereo.cas.authentication.Credential) Authentication(org.apereo.cas.authentication.Authentication) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction)

Example 14 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class HazelcastTicketRegistry method addTicket.

@Override
public void addTicket(final Ticket ticket) {
    LOGGER.debug("Adding ticket [{}] with ttl [{}s]", ticket.getId(), ticket.getExpirationPolicy().getTimeToLive());
    final Ticket encTicket = encodeTicket(ticket);
    final TicketDefinition metadata = this.ticketCatalog.find(ticket);
    final IMap<String, Ticket> ticketMap = getTicketMapInstanceByMetadata(metadata);
    ticketMap.set(encTicket.getId(), encTicket, ticket.getExpirationPolicy().getTimeToLive(), TimeUnit.SECONDS);
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) TicketDefinition(org.apereo.cas.ticket.TicketDefinition)

Example 15 with Ticket

use of org.apereo.cas.ticket.Ticket in project cas by apereo.

the class HazelcastTicketRegistry method deleteAll.

@Override
public long deleteAll() {
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    final AtomicLong count = new AtomicLong();
    metadata.forEach(r -> {
        final IMap<String, Ticket> instance = getTicketMapInstanceByMetadata(r);
        if (instance != null) {
            count.addAndGet(instance.size());
            instance.evictAll();
            instance.clear();
        }
    });
    return count.get();
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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