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;
}
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;
}
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();
}
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);
}
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();
}
Aggregations