@Override
    public Stream<? extends Ticket> getSessionsFor(final String principalId) {
        val ticketDefinitions = ticketCatalog.findTicketDefinition(TicketGrantingTicket.class);
        return ticketDefinitions
            .stream()
            .map(this::getTicketCollectionInstanceByMetadata)
            .flatMap(map -> {
                val query = isCipherExecutorEnabled()
                    ? new Query(Criteria.where(MongoDbTicketDocument.FIELD_NAME_PRINCIPAL).is(digestIdentifier(principalId)))
                    : new Query(Criteria.where(MongoDbTicketDocument.FIELD_NAME_PRINCIPAL).regex(principalId, "i"));
                return mongoTemplate.stream(query, MongoDbTicketDocument.class, map);
            })
            .map(ticket -> decodeTicket(deserializeTicket(ticket.getJson(), ticket.getType())))
            .filter(ticket -> !ticket.isExpired());
    }
Calculate the time at which the ticket is eligible for automated deletion by MongoDb.
Makes the assumption that the CAS server date and the Mongo server date are in sync.
support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/ticket/registry/MongoDbTicketRegistry.java