LoginTicketManager { public void deleteExpired() { Set<Map.Entry<String, LoginTicket>> entries = tickets.entrySet(); ArrayList<String> idToRemove = new ArrayList<>(); synchronized (tickets) { for (Map.Entry<String, LoginTicket> entry : entries) { if (entry.getValue().isExpired()) { idToRemove.add(entry.getValue().getIdAsString()); } } for (String id : idToRemove) { try { removeTicket(id); } catch (LoginTicketNotFoundException e) { logger.error("DeleteExpired: tried to remove a ticket that cannot be found [id = " + id + "]: ", e); } } } } LoginTicketManager(); int getTicketCountThreashold(); void setTicketCountThreashold(int ticketCountThreashold); int getTicketValiditySeconds(); void setTicketValiditySeconds(int ticketValiditySeconds); UsernameProvider getUsernameProvider(); void setUsernameProvider(UsernameProvider usernameProvider); LoginTicket generateNewTicket(String requestingApplicationName, String requestingApplicationUsername); LoginTicket removeTicket(String ticketId); void deleteExpired(); long getSize(); void resetTickets(); static final int DEFAULT_TICKET_VALIDITY_SECONDS; static final int TICKETS_CLEANING_THRESHOLD; }
@Test public void testDeleteExpired() throws ExternalAppNotMappedException { int oldValidity = manager.getTicketValiditySeconds(); manager.setTicketValiditySeconds(0); manager.resetTickets(); assertEquals(0, manager.getSize()); int i = 0; for (; i < 100; i++) { manager.generateNewTicket("test", "testUser"); } manager.deleteExpired(); assertEquals(0, manager.getSize()); manager.setTicketValiditySeconds(oldValidity); }