Search in sources :

Example 11 with AbstractTicketException

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);
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) Event(org.springframework.webflow.execution.Event) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException)

Example 12 with AbstractTicketException

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;
}
Also used : MessageBuilder(org.springframework.binding.message.MessageBuilder) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) MessageContext(org.springframework.binding.message.MessageContext) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException)

Example 13 with AbstractTicketException

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);
    }
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Service(org.apereo.cas.authentication.principal.Service) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) AbstractTicketException(org.apereo.cas.ticket.AbstractTicketException) Map(java.util.Map) ProxyTicket(org.apereo.cas.ticket.proxy.ProxyTicket) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AbstractTicketException (org.apereo.cas.ticket.AbstractTicketException)13 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)4 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)4 Service (org.apereo.cas.authentication.principal.Service)4 Credential (org.apereo.cas.authentication.Credential)3 RegisteredService (org.apereo.cas.services.RegisteredService)3 Assertion (org.apereo.cas.validation.Assertion)3 HashMap (java.util.HashMap)2 Authentication (org.apereo.cas.authentication.Authentication)2 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)2 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)2 ServiceTicket (org.apereo.cas.ticket.ServiceTicket)2 Ticket (org.apereo.cas.ticket.Ticket)2 Association (org.openid4java.association.Association)2 ParameterList (org.openid4java.message.ParameterList)2 Event (org.springframework.webflow.execution.Event)2 URI (java.net.URI)1 Map (java.util.Map)1 Optional (java.util.Optional)1