Java Code Examples for org.jasig.cas.ticket.Ticket#isExpired()

The following examples show how to use org.jasig.cas.ticket.Ticket#isExpired() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CentralAuthenticationServiceImpl.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name="GET_TICKET_COUNTER", monotonic=true)
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<? extends Ticket> clazz)
        throws InvalidTicketException {
    Assert.notNull(ticketId, "ticketId cannot be null");
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);

    if (ticket == null) {
        logger.debug("Ticket [{}] by type [{}] cannot be found in the ticket registry.", ticketId, clazz.getSimpleName());
        throw new InvalidTicketException(ticketId);
    }

    if (ticket instanceof TicketGrantingTicket) {
        synchronized (ticket) {
            if (ticket.isExpired()) {
                this.ticketRegistry.deleteTicket(ticketId);
                logger.debug("Ticket [{}] has expired and is now deleted from the ticket registry.", ticketId);
                throw new InvalidTicketException(ticketId);
            }
        }
    }
    return (T) ticket;
}
 
Example 2
Source File: TicketGrantingTicketCheckAction.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
/**
 * Determines whether the TGT in the flow request context is valid.
 *
 * @param requestContext Flow request context.
 *
 * @throws Exception in case ticket cannot be retrieved from the service layer
 * @return {@link #NOT_EXISTS}, {@link #INVALID}, or {@link #VALID}.
 */
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    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 TicketException e) {
        logger.trace("Could not retrieve ticket id {} from registry.", e);
    }
    return new Event(this,  eventId);
}
 
Example 3
Source File: TicketGrantingTicketCheckAction.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
/**
 * 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}.
 */
public Event checkValidity(final RequestContext requestContext) {

    final String tgtId = WebUtils.getTicketGrantingTicketId(requestContext);
    if (!StringUtils.hasText(tgtId)) {
        return new Event(this, NOT_EXISTS);
    }

    final Ticket ticket = this.ticketRegistry.getTicket(tgtId);
    return new Event(this, ticket != null && !ticket.isExpired() ? VALID : INVALID);
}
 
Example 4
Source File: StatisticsController.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
/**
 * Handles the request.
 *
 * @param httpServletRequest the http servlet request
 * @param httpServletResponse the http servlet response
 * @return the model and view
 * @throws Exception the exception
 */
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse)
            throws Exception {
    final ModelAndView modelAndView = new ModelAndView(MONITORING_VIEW_STATISTICS);
    modelAndView.addObject("startTime", this.upTimeStartDate);
    final double difference = System.currentTimeMillis() - this.upTimeStartDate.getTime();

    modelAndView.addObject("upTime", calculateUptime(difference, new LinkedList<Integer>(
                    Arrays.asList(NUMBER_OF_MILLISECONDS_IN_A_DAY, NUMBER_OF_MILLISECONDS_IN_AN_HOUR,
                    NUMBER_OF_MILLISECONDS_IN_A_MINUTE, NUMBER_OF_MILLISECONDS_IN_A_SECOND, 1)),
                    new LinkedList<String>(Arrays.asList("day", "hour", "minute", "second", "millisecond"))));

    modelAndView.addObject("totalMemory", convertToMegaBytes(Runtime.getRuntime().totalMemory()));
    modelAndView.addObject("maxMemory", convertToMegaBytes(Runtime.getRuntime().maxMemory()));
    modelAndView.addObject("freeMemory", convertToMegaBytes(Runtime.getRuntime().freeMemory()));
    modelAndView.addObject("availableProcessors", Runtime.getRuntime().availableProcessors());
    modelAndView.addObject("serverHostName", httpServletRequest.getServerName());
    modelAndView.addObject("serverIpAddress", httpServletRequest.getLocalAddr());
    modelAndView.addObject("casTicketSuffix", this.casTicketSuffix);

    int unexpiredTgts = 0;
    int unexpiredSts = 0;
    int expiredTgts = 0;
    int expiredSts = 0;

    try {
        final Collection<Ticket> tickets = this.centralAuthenticationService.getTickets(TruePredicate.INSTANCE);

        for (final Ticket ticket : tickets) {
            if (ticket instanceof ServiceTicket) {
                if (ticket.isExpired()) {
                    expiredSts++;
                } else {
                    unexpiredSts++;
                }
            } else {
                if (ticket.isExpired()) {
                    expiredTgts++;
                } else {
                    unexpiredTgts++;
                }
            }
        }
    } catch (final UnsupportedOperationException e) {
        logger.trace("The ticket registry doesn't support this information.");
    }

    modelAndView.addObject("unexpiredTgts", unexpiredTgts);
    modelAndView.addObject("unexpiredSts", unexpiredSts);
    modelAndView.addObject("expiredTgts", expiredTgts);
    modelAndView.addObject("expiredSts", expiredSts);
    modelAndView.addObject("pageTitle", modelAndView.getViewName());

    return modelAndView;
}
 
Example 5
Source File: StatisticsController.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse)
            throws Exception {
    final ModelAndView modelAndView = new ModelAndView("viewStatisticsView");
    modelAndView.addObject("startTime", this.upTimeStartDate);
    final double difference = System.currentTimeMillis() - this.upTimeStartDate.getTime();

    modelAndView.addObject("upTime", calculateUptime(difference, new LinkedList<Integer>(
                    Arrays.asList(NUMBER_OF_MILLISECONDS_IN_A_DAY, NUMBER_OF_MILLISECONDS_IN_AN_HOUR,
                    NUMBER_OF_MILLISECONDS_IN_A_MINUTE, NUMBER_OF_MILLISECONDS_IN_A_SECOND, 1)),
                    new LinkedList<String>(Arrays.asList("day", "hour", "minute", "second", "millisecond"))));
    modelAndView.addObject("totalMemory", Runtime.getRuntime().totalMemory() / 1024 / 1024);
    modelAndView.addObject("maxMemory", Runtime.getRuntime().maxMemory() / 1024 / 1024);
    modelAndView.addObject("freeMemory", Runtime.getRuntime().freeMemory() / 1024 / 1024);
    modelAndView.addObject("availableProcessors", Runtime.getRuntime().availableProcessors());
    modelAndView.addObject("serverHostName", httpServletRequest.getServerName());
    modelAndView.addObject("serverIpAddress", httpServletRequest.getLocalAddr());
    modelAndView.addObject("casTicketSuffix", this.casTicketSuffix);

    int unexpiredTgts = 0;
    int unexpiredSts = 0;
    int expiredTgts = 0;
    int expiredSts = 0;

    try {
        final Collection<Ticket> tickets = this.ticketRegistry.getTickets();

        for (final Ticket ticket : tickets) {
            if (ticket instanceof ServiceTicket) {
                if (ticket.isExpired()) {
                    expiredSts++;
                } else {
                    unexpiredSts++;
                }
            } else {
                if (ticket.isExpired()) {
                    expiredTgts++;
                } else {
                    unexpiredTgts++;
                }
            }
        }
    } catch (final UnsupportedOperationException e) {
        logger.trace("The ticket registry doesn't support this information.");
    }

    final Collection<GraphingStatisticsAppender> appenders = GraphingStatisticsAppender.getAllGraphingStatisticsAppenders();

    modelAndView.addObject("unexpiredTgts", unexpiredTgts);
    modelAndView.addObject("unexpiredSts", unexpiredSts);
    modelAndView.addObject("expiredTgts", expiredTgts);
    modelAndView.addObject("expiredSts", expiredSts);
    modelAndView.addObject("pageTitle", modelAndView.getViewName());
    modelAndView.addObject("graphingStatisticAppenders", appenders);

    return modelAndView;
}