TicketValidityService { public boolean isTicketValid(Ticket ticket) { return isTicketValid(ByteBuffer.wrap(TicketUtil.serialize(ticket))); }  boolean isTicketValid(Ticket ticket); void validateTicket(Ticket ticket); boolean isTicketValid(ByteBuffer serializedTicket); boolean isTicketValid(Pair<Ticket, byte[]> deserializedTicket); boolean isTicketValidIgnoringInvalidatedTickets(Ticket t); void validateTicket(ByteBuffer serializedTicket); void markTicketAsInvalid(TicketInfo ticketInfo); Set<TicketInfo> getInvalidTicketInfos(); static final long CLEANUP_NO_REMOVE_MOST_RECENT_MS; }
@Test public void tooLate() { synchronized (TestTicketRsaKeyFileProvider.class) { TestTicketRsaKeyFileProvider.clean(); TestTicketRsaKeyFileProvider.files.add(PRIVATE_PLAIN); TestTicketRsaKeyFileProvider.isFilesWithPrivateKeyAreRequired = true; startNewContext(500); Ticket t = new Ticket(); t.setClaim(new TicketClaim()); t.getClaim().setTicketId(RUuidUtil.toRUuid(UUID.randomUUID())); t.getClaim().setUsername("abc"); t.getClaim().setValidUntil(123); t.getClaim().setIsSuperUser(false); ticketSignatureService.signTicket(t); boolean isValid = ticketValidityService.isTicketValid(t); Assert.assertFalse(isValid, "Ticket should NOT be valid."); } }
@Test public void tampered() { synchronized (TestTicketRsaKeyFileProvider.class) { TestTicketRsaKeyFileProvider.clean(); TestTicketRsaKeyFileProvider.files.add(PRIVATE_PLAIN); TestTicketRsaKeyFileProvider.isFilesWithPrivateKeyAreRequired = true; startNewContext(0); Ticket t = new Ticket(); t.setClaim(new TicketClaim()); t.getClaim().setTicketId(RUuidUtil.toRUuid(UUID.randomUUID())); t.getClaim().setUsername("abc"); t.getClaim().setValidUntil(123); t.getClaim().setIsSuperUser(false); ticketSignatureService.signTicket(t); t.getClaim().setUsername("xyz"); boolean isValid = ticketValidityService.isTicketValid(t); Assert.assertFalse(isValid, "Ticket should NOT be valid."); } }