Search in sources :

Example 36 with AuthenticationException

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));
}
Also used : AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Authentication(org.apereo.cas.authentication.Authentication) AuthenticationRiskContingencyResponse(org.apereo.cas.api.AuthenticationRiskContingencyResponse) Event(org.springframework.webflow.execution.Event) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider)

Example 37 with AuthenticationException

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");
}
Also used : AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

AuthenticationException (org.apereo.cas.authentication.AuthenticationException)37 Event (org.springframework.webflow.execution.Event)19 Authentication (org.apereo.cas.authentication.Authentication)18 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)14 RegisteredService (org.apereo.cas.services.RegisteredService)13 HashMap (java.util.HashMap)8 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)8 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)8 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)8 Credential (org.apereo.cas.authentication.Credential)7 Service (org.apereo.cas.authentication.principal.Service)7 Map (java.util.Map)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)5 Test (org.junit.Test)5 RequestContext (org.springframework.webflow.execution.RequestContext)5 GeneralSecurityException (java.security.GeneralSecurityException)4 Optional (java.util.Optional)4 AccountLockedException (javax.security.auth.login.AccountLockedException)4 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)4