Search in sources :

Example 1 with AuthenticationTransaction

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();
}
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 2 with AuthenticationTransaction

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;
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) Slf4j(lombok.extern.slf4j.Slf4j) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) AuthenticationHandlerResolver(org.apereo.cas.authentication.AuthenticationHandlerResolver) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) Set(java.util.Set) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) LinkedHashSet(java.util.LinkedHashSet) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Aggregations

AuthenticationTransaction (org.apereo.cas.authentication.AuthenticationTransaction)2 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 AuthenticationHandlerResolver (org.apereo.cas.authentication.AuthenticationHandlerResolver)1 Credential (org.apereo.cas.authentication.Credential)1 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)1 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)1 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)1 Ticket (org.apereo.cas.ticket.Ticket)1 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)1