Search in sources :

Example 1 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class AuthenticationExceptionHandlerTests method handleUnknownExceptionByDefault.

@Test
public void handleUnknownExceptionByDefault() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("unknown", GeneralSecurityException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, "UNKNOWN");
}
Also used : HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 2 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class AuthenticationExceptionHandlerTests method correctHandlersOrder.

@Test
public void correctHandlersOrder() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("accountLocked", AccountLockedException.class);
    map.put("accountNotFound", AccountNotFoundException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, AccountLockedException.class.getSimpleName());
}
Also used : AccountLockedException(javax.security.auth.login.AccountLockedException) HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 3 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class AuthenticationExceptionHandlerTests method handleAccountNotFoundExceptionByDefault.

@Test
public void handleAccountNotFoundExceptionByDefault() {
    final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
    final MessageContext ctx = mock(MessageContext.class);
    final Map<String, Class<? extends Exception>> map = new HashMap<>();
    map.put("notFound", AccountNotFoundException.class);
    final String id = handler.handle(new AuthenticationException(map), ctx);
    assertEquals(id, AccountNotFoundException.class.getSimpleName());
}
Also used : HashMap(java.util.HashMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) AccountLockedException(javax.security.auth.login.AccountLockedException) InvalidTicketException(org.apereo.cas.ticket.InvalidTicketException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) PreventedException(org.apereo.cas.authentication.PreventedException) Test(org.junit.Test)

Example 4 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class ServiceTicketRequestWebflowEventResolver method grantServiceTicket.

/**
     * Grant service ticket for the given credential based on the service and tgt
     * that are found in the request context.
     *
     * @param context the context
     * @return the resulting event. Warning, authentication failure or error.
     * @since 4.1.0
     */
protected Event grantServiceTicket(final RequestContext context) {
    final String ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
    final Credential credential = getCredentialFromContext(context);
    try {
        final Service service = WebUtils.getService(context);
        final AuthenticationResult authenticationResult = this.authenticationSystemSupport.handleAndFinalizeSingleAuthenticationTransaction(service, credential);
        final ServiceTicket serviceTicketId = this.centralAuthenticationService.grantServiceTicket(ticketGrantingTicketId, service, authenticationResult);
        WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
        WebUtils.putWarnCookieIfRequestParameterPresent(this.warnCookieGenerator, context);
        return newEvent(CasWebflowConstants.TRANSITION_ID_WARN);
    } catch (final AuthenticationException | AbstractTicketException e) {
        return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
    }
}
Also used : Credential(org.apereo.cas.authentication.Credential) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) ServiceTicket(org.apereo.cas.ticket.ServiceTicket) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException) AuthenticationResult(org.apereo.cas.authentication.AuthenticationResult)

Example 5 with AuthenticationException

use of org.apereo.cas.authentication.AuthenticationException in project cas by apereo.

the class AbstractCasWebflowEventResolver method validateEventIdForMatchingTransitionInContext.

/**
     * Validate event for transition.
     *
     * @param eventId    the event id
     * @param context    the context
     * @param attributes the attributes
     * @return the event
     */
protected Event validateEventIdForMatchingTransitionInContext(final String eventId, final RequestContext context, final Map<String, Object> attributes) {
    try {
        final AttributeMap<Object> attributesMap = new LocalAttributeMap<>(attributes);
        final Event event = new Event(this, eventId, attributesMap);
        LOGGER.debug("Resulting event id is [{}]. Locating transitions in the context for that event id...", event.getId());
        final TransitionDefinition def = context.getMatchingTransition(event.getId());
        if (def == null) {
            LOGGER.warn("Transition definition cannot be found for event [{}]", event.getId());
            throw new AuthenticationException();
        }
        LOGGER.debug("Found matching transition [{}] with target [{}] for event [{}] with attributes [{}].", def.getId(), def.getTargetStateId(), event.getId(), event.getAttributes());
        return event;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) Event(org.springframework.webflow.execution.Event) TransitionDefinition(org.springframework.webflow.definition.TransitionDefinition) AuthenticationException(org.apereo.cas.authentication.AuthenticationException)

Aggregations

AuthenticationException (org.apereo.cas.authentication.AuthenticationException)21 Event (org.springframework.webflow.execution.Event)10 Authentication (org.apereo.cas.authentication.Authentication)9 MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)7 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)7 RegisteredService (org.apereo.cas.services.RegisteredService)6 HashMap (java.util.HashMap)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 Credential (org.apereo.cas.authentication.Credential)5 Map (java.util.Map)4 AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)4 GeneralSecurityException (java.security.GeneralSecurityException)3 Optional (java.util.Optional)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 Service (org.apereo.cas.authentication.principal.Service)3 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)3