use of org.apereo.cas.ticket.AbstractTicketException in project cas by apereo.
the class TicketGrantingTicketCheckAction method doExecute.
/**
* Determines whether the TGT in the flow request context is valid.
*
* @param requestContext Flow request context.
*
* @return {@link #NOT_EXISTS}, {@link #INVALID}, or {@link #VALID}.
*/
@Override
public Event doExecute(final RequestContext requestContext) {
final String tgtId = WebUtils.getTicketGrantingTicketId(requestContext);
if (!StringUtils.hasText(tgtId)) {
return new Event(this, NOT_EXISTS);
}
String eventId = INVALID;
try {
final Ticket ticket = this.centralAuthenticationService.getTicket(tgtId, Ticket.class);
if (ticket != null && !ticket.isExpired()) {
eventId = VALID;
}
} catch (final AbstractTicketException e) {
LOGGER.trace("Could not retrieve ticket id [{}] from registry.", e.getMessage());
}
return new Event(this, eventId);
}
use of org.apereo.cas.ticket.AbstractTicketException in project cas by apereo.
the class AuthenticationExceptionHandlerAction method handle.
/**
* Maps an authentication exception onto a state name.
* Also sets an ERROR severity message in the message context.
*
* @param e Authentication error to handle.
* @param requestContext the spring context
* @return Name of next flow state to transition to or {@value #UNKNOWN}
*/
public String handle(final Exception e, final RequestContext requestContext) {
final MessageContext messageContext = requestContext.getMessageContext();
if (e instanceof AuthenticationException) {
return handleAuthenticationException((AuthenticationException) e, requestContext);
}
if (e instanceof AbstractTicketException) {
return handleAbstractTicketException((AbstractTicketException) e, requestContext);
}
LOGGER.trace("Unable to translate errors of the authentication exception [{}]. Returning [{}]", e, UNKNOWN);
final String messageCode = this.messageBundlePrefix + UNKNOWN;
messageContext.addMessage(new MessageBuilder().error().code(messageCode).build());
return UNKNOWN;
}
use of org.apereo.cas.ticket.AbstractTicketException in project cas by apereo.
the class ProxyController method handleRequestInternal.
/**
* Handle request internal.
*
* @param request the request
* @param response the response
* @return ModelAndView containing a view name of either
* {@code casProxyFailureView} or {@code casProxySuccessView}
*/
@Override
@GetMapping(path = "/proxy")
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) {
final String proxyGrantingTicket = request.getParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET);
final Service targetService = getTargetService(request);
if (!StringUtils.hasText(proxyGrantingTicket) || targetService == null) {
return generateErrorView(CasProtocolConstants.ERROR_CODE_INVALID_REQUEST_PROXY, null, request);
}
try {
final ProxyTicket proxyTicket = this.centralAuthenticationService.grantProxyTicket(proxyGrantingTicket, targetService);
final Map model = CollectionUtils.wrap(CasProtocolConstants.PARAMETER_TICKET, proxyTicket);
return new ModelAndView(this.successView, model);
} catch (final AbstractTicketException e) {
return generateErrorView(e.getCode(), new Object[] { proxyGrantingTicket }, request);
} catch (final UnauthorizedServiceException e) {
return generateErrorView(CasProtocolConstants.ERROR_CODE_UNAUTHORIZED_SERVICE_PROXY, new Object[] { targetService }, request);
}
}
Aggregations