use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class AdaptiveMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest httpServletRequest, final HttpServletResponse response, final Service service) {
val multifactorMap = casProperties.getAuthn().getAdaptive().getPolicy().getRequireMultifactor();
if (service == null || authentication == null) {
LOGGER.trace("No service or authentication is available to determine event for principal");
return Optional.empty();
}
if (multifactorMap == null || multifactorMap.isEmpty()) {
LOGGER.trace("Adaptive authentication is not configured to require multifactor authentication");
return Optional.empty();
}
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context");
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
val clientInfo = ClientInfoHolder.getClientInfo();
val clientIp = clientInfo.getClientIpAddress();
LOGGER.debug("Located client IP address as [{}]", clientIp);
val agent = HttpRequestUtils.getHttpServletRequestUserAgent(httpServletRequest);
val entries = multifactorMap.entrySet();
for (final Map.Entry entry : entries) {
val mfaMethod = entry.getKey().toString();
val pattern = entry.getValue().toString();
val providerFound = MultifactorAuthenticationUtils.resolveProvider(providerMap, mfaMethod);
if (providerFound.isEmpty()) {
LOGGER.error("Adaptive authentication is configured to require [{}] for [{}], yet [{}] is absent in the configuration.", mfaMethod, pattern, mfaMethod);
throw new AuthenticationException();
}
if (checkUserAgentOrClientIp(clientIp, agent, mfaMethod, pattern)) {
return providerFound;
}
if (checkRequestGeoLocation(httpServletRequest, clientIp, mfaMethod, pattern)) {
return providerFound;
}
}
return Optional.empty();
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class GlobalMultifactorAuthenticationTrigger method handleAbsentMultifactorProvider.
/**
* Handle absent multifactor provider.
*
* @param globalProviderId the global provider id
* @param resolvedProviders the resolved providers
*/
protected void handleAbsentMultifactorProvider(final String globalProviderId, final List<MultifactorAuthenticationProvider> resolvedProviders) {
val providerIds = resolvedProviders.stream().map(MultifactorAuthenticationProvider::getId).collect(Collectors.joining(","));
val message = String.format("Not all requested multifactor providers could be found. " + "Requested providers are [%s] and resolved providers are [%s]", globalProviderId, providerIds);
LOGGER.warn(message, globalProviderId);
throw new MultifactorAuthenticationProviderAbsentException(message);
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class HttpRequestMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest httpServletRequest, final HttpServletResponse response, final Service service) {
if (authentication == null) {
LOGGER.debug("No authentication is available to determine event for principal");
return Optional.empty();
}
val values = resolveEventFromHttpRequest(httpServletRequest);
if (values != null && !values.isEmpty()) {
LOGGER.debug("Received request as [{}]", values);
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context to satisfy [{}]", values);
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
val providerFound = MultifactorAuthenticationUtils.resolveProvider(providerMap, values.get(0));
if (providerFound.isPresent()) {
return providerFound;
}
LOGGER.warn("No multifactor provider could be found for request parameter [{}]", values);
throw new AuthenticationException();
}
return Optional.empty();
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class TimedMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest httpServletRequest, final HttpServletResponse response, final Service service) {
val timedMultifactor = casProperties.getAuthn().getAdaptive().getPolicy().getRequireTimedMultifactor();
if (service == null || authentication == null) {
LOGGER.trace("No service or authentication is available to determine event for principal");
return Optional.empty();
}
if (timedMultifactor == null || timedMultifactor.isEmpty()) {
LOGGER.trace("Adaptive authentication is not configured to require multifactor authentication by time");
return Optional.empty();
}
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context");
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
return checkTimedMultifactorProvidersForRequest(registeredService);
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class OidcMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest request, final HttpServletResponse response, final Service service) {
val acr = getAuthenticationClassReference(request, response);
if (StringUtils.isBlank(acr)) {
LOGGER.debug("No ACR provided in the authentication request");
return Optional.empty();
}
val values = List.of(org.springframework.util.StringUtils.delimitedListToStringArray(acr, " "));
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context to handle [{}]", values);
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
val authnContexts = casProperties.getAuthn().getOidc().getCore().getAuthenticationContextReferenceMappings();
val mappings = CollectionUtils.convertDirectedListToMap(authnContexts);
val mappedAcrValues = values.stream().map(acrValue -> mappings.getOrDefault(acrValue, acrValue)).collect(Collectors.toList());
LOGGER.debug("Mapped ACR values are [{}] to compare against [{}]", mappedAcrValues, providerMap.values());
return providerMap.values().stream().filter(v -> mappedAcrValues.contains(v.getId())).findAny();
}
Aggregations