use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.
the class MultifactorAuthenticationContingencyPlan method executeInternal.
@Override
protected AuthenticationRiskContingencyResponse executeInternal(final Authentication authentication, final RegisteredService service, final AuthenticationRiskScore score, final HttpServletRequest request) {
final Map<String, MultifactorAuthenticationProvider> providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
if (providerMap == null || providerMap.isEmpty()) {
LOGGER.warn("No multifactor authentication providers are available in the application context");
throw new AuthenticationException();
}
String id = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getMfaProvider();
if (StringUtils.isBlank(id)) {
if (providerMap.size() == 1) {
id = providerMap.values().iterator().next().getId();
} else {
LOGGER.warn("No multifactor authentication providers are specified to handle risk-based authentication");
throw new AuthenticationException();
}
}
final String attributeName = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getRiskyAuthenticationAttribute();
final Authentication newAuthn = DefaultAuthenticationBuilder.newInstance(authentication).addAttribute(attributeName, Boolean.TRUE).build();
LOGGER.debug("Updated authentication to remember risk-based authn via [{}]", attributeName);
authentication.update(newAuthn);
return new AuthenticationRiskContingencyResponse(new Event(this, id));
}
use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.
the class JdbcThrottledSubmissionHandlerInterceptorAdapterTests method loginUnsuccessfully.
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
request.setRequestURI("/cas/login");
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
throttle.preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.of(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
} catch (final AuthenticationException e) {
throttle.postHandle(request, response, null, null);
return response;
}
throw new AssertionError("Expected AbstractAuthenticationException");
}
Aggregations