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");
}
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());
}
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());
}
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);
}
}
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);
}
}
Aggregations