コード例 #1
0
ファイル: EhCacheTicketRegistry.java プロジェクト: frett/cas
  @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
  @Override
  public void addTicket(final Ticket ticketToAdd) {
    final Ticket ticket = encodeTicket(ticketToAdd);
    logger.debug(
        "Adding ticket {} to the cache {}", ticket.getId(), this.ticketIgniteCache.getName());
    this.ticketIgniteCache
        .withExpiryPolicy(
            new ExpiryPolicy() {
              @Override
              public Duration getExpiryForCreation() {
                return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
              }

              @Override
              public Duration getExpiryForAccess() {
                return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToIdle());
              }

              @Override
              public Duration getExpiryForUpdate() {
                return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
              }
            })
        .put(ticket.getId(), ticket);
  }
コード例 #3
0
 @Override
 public boolean deleteSingleTicket(final String ticketId) {
   final Ticket ticket = getTicket(ticketId);
   if (ticket != null) {
     return this.ticketIgniteCache.remove(ticket.getId());
   }
   return true;
 }
コード例 #4
0
ファイル: EhCacheTicketRegistry.java プロジェクト: frett/cas
  /**
   * {@inheritDoc} Either the element is removed from the cache or it's not found in the cache and
   * is already removed. Thus the result of this op would always be true.
   */
  @Override
  public boolean deleteSingleTicket(final String ticketId) {

    final Ticket ticket = getTicket(ticketId);
    if (ticket == null) {
      logger.debug("Ticket {} cannot be retrieved from the cache", ticketId);
      return true;
    }

    if (this.ehcacheTicketsCache.remove(ticket.getId())) {
      logger.debug("Ticket {} is removed", ticket.getId());
    }
    return true;
  }
コード例 #5
0
ファイル: EhCacheTicketRegistry.java プロジェクト: frett/cas
  @Override
  public void addTicket(final Ticket ticketToAdd) {
    final Ticket ticket = encodeTicket(ticketToAdd);
    final Element element = new Element(ticket.getId(), ticket);

    final int idleValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
    element.setTimeToIdle(idleValue);

    final int aliveValue = ticketToAdd.getExpirationPolicy().getTimeToIdle().intValue();
    element.setTimeToLive(aliveValue);

    logger.debug(
        "Adding ticket {} to the cache {}", ticket.getId(), this.ehcacheTicketsCache.getName());
    this.ehcacheTicketsCache.put(element);
  }
コード例 #6
0
ファイル: StatisticsController.java プロジェクト: biliroy/cas
  /**
   * 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;
  }