use of org.apereo.cas.authentication.AuthenticationTransaction 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.authentication.AuthenticationTransaction in project cas by apereo.
the class ByCredentialSourceAuthenticationHandlerResolver method resolve.
@Override
public Set<AuthenticationHandler> resolve(final Set<AuthenticationHandler> candidateHandlers, final AuthenticationTransaction transaction) {
val finalHandlers = new LinkedHashSet<AuthenticationHandler>(candidateHandlers.size());
val upcs = transaction.getCredentialsOfType(UsernamePasswordCredential.class);
candidateHandlers.stream().filter(handler -> handler.supports(UsernamePasswordCredential.class)).filter(handler -> {
val handlerName = handler.getName();
LOGGER.debug("Evaluating authentication handler [{}] for eligibility", handlerName);
return upcs.stream().anyMatch(c -> {
LOGGER.debug("Comparing credential source [{}] against authentication handler [{}]", c.getSource(), handlerName);
return StringUtils.isNotBlank(c.getSource()) && c.getSource().equalsIgnoreCase(handlerName);
});
}).forEach(finalHandlers::add);
return finalHandlers;
}
Aggregations