Пример #1
0
  @Override
  public Ticket getTicket(final String ticketIdToGet) {
    final String ticketId = encodeTicketId(ticketIdToGet);
    if (ticketId == null) {
      return null;
    }

    final Element element = this.ehcacheTicketsCache.get(ticketId);
    if (element == null) {
      logger.debug("No ticket by id [{}] is found in the registry", ticketId);
      return null;
    }
    final Ticket ticket = decodeTicket((Ticket) element.getObjectValue());

    final CacheConfiguration config = new CacheConfiguration();
    config.setTimeToIdleSeconds(ticket.getExpirationPolicy().getTimeToIdle());
    config.setTimeToLiveSeconds(ticket.getExpirationPolicy().getTimeToIdle());

    if (element.isExpired(config) || ticket.isExpired()) {
      logger.debug("Ticket {} has expired", ticket.getId());
      this.ehcacheTicketsCache.evictExpiredElements();
      this.ehcacheTicketsCache.flush();
      return null;
    }

    return ticket;
  }
Пример #2
0
  /**
   * Gets ticket stats.
   *
   * @param httpServletRequest the http servlet request
   * @param httpServletResponse the http servlet response
   * @return the ticket stats
   */
  @RequestMapping(value = "/getTicketStats", method = RequestMethod.GET)
  @ResponseBody
  public Map<String, Object> getTicketStats(
      final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) {
    final Map<String, Object> model = new HashMap<>();

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

    final Collection<Ticket> tickets =
        this.centralAuthenticationService.getTickets(Predicates.alwaysTrue());

    for (final Ticket ticket : tickets) {
      if (ticket instanceof ServiceTicket) {
        if (ticket.isExpired()) {
          expiredSts++;
        } else {
          unexpiredSts++;
        }
      } else {
        if (ticket.isExpired()) {
          expiredTgts++;
        } else {
          unexpiredTgts++;
        }
      }
    }

    model.put("unexpiredTgts", unexpiredTgts);
    model.put("unexpiredSts", unexpiredSts);
    model.put("expiredTgts", expiredTgts);
    model.put("expiredSts", expiredSts);

    return model;
  }