use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class RadiusAccessChallengedMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest request, final HttpServletResponse response, final Service service) {
if (authentication == null) {
LOGGER.debug("No authentication or service is available to determine event for principal");
return Optional.empty();
}
if (!supports(authentication)) {
LOGGER.trace("Authentication attempt does not qualify for radius 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 id = casProperties.getAuthn().getMfa().getRadius().getId();
LOGGER.debug("Authentication requires multifactor authentication via provider [{}]", id);
return MultifactorAuthenticationUtils.resolveProvider(providerMap, id);
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class ScriptedRegisteredServiceMultifactorAuthenticationTrigger 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 || registeredService == null) {
LOGGER.debug("No authentication or service is available to determine event for principal");
return Optional.empty();
}
val policy = registeredService.getMultifactorPolicy();
if (policy == null || StringUtils.isBlank(policy.getScript())) {
LOGGER.trace("Multifactor authentication policy is absent or does not define a script to trigger multifactor authentication");
return Optional.empty();
}
val mfaScript = policy.getScript();
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());
}
LOGGER.trace("Locating multifactor authentication trigger script [{}] in script cache...", mfaScript);
if (!scriptCache.containsKey(mfaScript)) {
val matcherInline = ScriptingUtils.getMatcherForInlineGroovyScript(mfaScript);
val matcherFile = ScriptingUtils.getMatcherForExternalGroovyScript(mfaScript);
if (matcherInline.find()) {
val script = new GroovyShellScript(matcherInline.group(1));
scriptCache.put(mfaScript, script);
LOGGER.trace("Caching multifactor authentication trigger script as an executable shell script");
} else if (matcherFile.find()) {
try {
val scriptPath = SpringExpressionLanguageValueResolver.getInstance().resolve(matcherFile.group());
val resource = ResourceUtils.getResourceFrom(scriptPath);
val script = new WatchableGroovyScriptResource(resource);
scriptCache.put(mfaScript, script);
LOGGER.trace("Caching multifactor authentication trigger script as script resource [{}]", resource);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
}
}
if (scriptCache.containsKey(mfaScript)) {
val executableScript = scriptCache.get(mfaScript);
LOGGER.debug("Executing multifactor authentication trigger script [{}]", executableScript);
val result = executableScript.execute(new Object[] { authentication, registeredService, httpServletRequest, service, applicationContext, LOGGER }, String.class);
LOGGER.debug("Multifactor authentication provider delivered by trigger script is [{}]", result);
if (StringUtils.isBlank(result)) {
LOGGER.debug("No multifactor authentication is returned from trigger script");
return Optional.empty();
}
val providerResult = providerMap.values().stream().filter(provider -> provider.getId().equalsIgnoreCase(result)).findFirst();
if (providerResult.isEmpty()) {
LOGGER.error("Unable to locate multifactor authentication provider [{}] in the application context", result);
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
return providerResult;
}
return Optional.empty();
}
use of org.apereo.cas.authentication.MultifactorAuthenticationProviderAbsentException in project cas by apereo.
the class GlobalMultifactorAuthenticationTrigger 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 globalProviderId = casProperties.getAuthn().getMfa().getTriggers().getGlobal().getGlobalProviderId();
if (StringUtils.isBlank(globalProviderId)) {
LOGGER.trace("No value could be found for for the global provider id");
return Optional.empty();
}
LOGGER.debug("Attempting to globally activate [{}]", globalProviderId);
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap.isEmpty()) {
LOGGER.error("No multifactor authentication providers are available in the application context to handle [{}]", globalProviderId);
throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
}
val providers = org.springframework.util.StringUtils.commaDelimitedListToSet(globalProviderId);
val resolvedProviders = providers.stream().map(provider -> MultifactorAuthenticationUtils.resolveProvider(providerMap, provider)).filter(Optional::isPresent).map(Optional::get).sorted(Comparator.comparing(MultifactorAuthenticationProvider::getOrder)).collect(Collectors.toList());
if (resolvedProviders.size() != providers.size()) {
handleAbsentMultifactorProvider(globalProviderId, resolvedProviders);
}
if (resolvedProviders.size() == 1) {
return resolveSingleMultifactorProvider(resolvedProviders.get(0));
}
return resolveMultifactorProvider(authentication, registeredService, resolvedProviders);
}
Aggregations