use of org.apereo.cas.authentication.AuthenticationResultBuilder in project cas by apereo.
the class RankedAuthenticationProviderWebflowEventResolver method resolveInternal.
@Override
public Set<Event> resolveInternal(final RequestContext context) {
final String tgt = WebUtils.getTicketGrantingTicketId(context);
final RegisteredService service = WebUtils.getRegisteredService(context);
if (service == null) {
LOGGER.debug("No service is available to determine event for principal");
return resumeFlow();
}
if (StringUtils.isBlank(tgt)) {
LOGGER.trace("TGT is blank; proceed with flow normally.");
return resumeFlow();
}
final Authentication authentication = this.ticketRegistrySupport.getAuthenticationFrom(tgt);
if (authentication == null) {
LOGGER.trace("TGT has no authentication and is blank; proceed with flow normally.");
return resumeFlow();
}
final Credential credential = WebUtils.getCredential(context);
final AuthenticationResultBuilder builder = this.authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication, credential);
WebUtils.putAuthenticationResultBuilder(builder, context);
WebUtils.putAuthentication(authentication, context);
final Event event = this.initialAuthenticationAttemptWebflowEventResolver.resolveSingle(context);
if (event == null) {
LOGGER.trace("Request does not indicate a requirement for authentication policy; proceed with flow normally.");
return resumeFlow();
}
final String id = event.getId();
if (id.equals(CasWebflowConstants.TRANSITION_ID_ERROR) || id.equals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE) || id.equals(CasWebflowConstants.TRANSITION_ID_SUCCESS)) {
LOGGER.debug("Returning webflow event as [{}]", id);
return Collections.singleton(event);
}
final Pair<Boolean, Optional<MultifactorAuthenticationProvider>> result = this.authenticationContextValidator.validate(authentication, id, service);
if (result.getKey()) {
LOGGER.debug("Authentication context is successfully validated by [{}] for service [{}]", id, service);
return resumeFlow();
}
if (result.getValue().isPresent()) {
return Collections.singleton(validateEventIdForMatchingTransitionInContext(id, context, buildEventAttributeMap(authentication.getPrincipal(), service, result.getValue().get())));
}
LOGGER.warn("The authentication context cannot be satisfied and the requested event [{}] is unrecognized", id);
return Collections.singleton(new Event(this, CasWebflowConstants.TRANSITION_ID_ERROR));
}
Aggregations