@Test(expected = IllegalArgumentException.class) public void testOperationWithTamperedKey() { KeyBasedPersistenceTokenService service = getService(); Token goodToken = service.allocateToken(""); String fake = goodToken.getKey().toUpperCase(); Token token = new DefaultToken(fake, new Date().getTime(), ""); service.verifyToken(token.getKey()); } }
@Test(expected = IllegalArgumentException.class) public void testOperationWithMissingKey() { KeyBasedPersistenceTokenService service = getService(); Token token = new DefaultToken("", new Date().getTime(), ""); service.verifyToken(token.getKey()); }
@Test public void testOperationWithSimpleExtendedInformation() { KeyBasedPersistenceTokenService service = getService(); Token token = service.allocateToken("Hello world"); Token result = service.verifyToken(token.getKey()); assertThat(result).isEqualTo(token); }
@Test public void testOperationWithComplexExtendedInformation() { KeyBasedPersistenceTokenService service = getService(); Token token = service.allocateToken("Hello:world:::"); Token result = service.verifyToken(token.getKey()); assertThat(result).isEqualTo(token); }
@Test public void testOperationWithNoExtendedInformation() { KeyBasedPersistenceTokenService service = getService(); Token token = service.allocateToken(""); Token result = service.verifyToken(token.getKey()); assertThat(result).isEqualTo(token); }
@Test public void testOperationWithEmptyRandomNumber() { KeyBasedPersistenceTokenService service = getService(); service.setPseudoRandomNumberBytes(0); Token token = service.allocateToken("Hello:world:::"); Token result = service.verifyToken(token.getKey()); assertThat(result).isEqualTo(token); }
/** * Generates a random password in a format suitable for presentation as an authentication credential. */ public String generatePassword() { String password = passwordGenerator.allocateToken("").getKey(); return password.length() <= User.PASSWORD_LEN_MAX ? password : password.substring(0, User.PASSWORD_LEN_MAX - 1); }
/** * Generates a random password in a format suitable for presentation as an authentication credential. */ public String generatePassword() { String password = passwordGenerator.allocateToken("").getKey(); return password.length() <= User.PASSWORD_LEN_MAX ? password : password.substring(0, User.PASSWORD_LEN_MAX - 1); }
@Override public String generateToken(ActionToken actionToken) { Token token = tokenService.allocateToken(encryptTokenAsString(actionToken)); return token.getKey(); }
@Override public void createTicket(Item item, Ticket ticket) { if (ticket == null) { throw new IllegalArgumentException("ticket cannot be null"); } if (item == null) { throw new IllegalArgumentException("item cannot be null"); } User owner = ticket.getOwner(); if (owner == null) { throw new IllegalArgumentException("ticket must have owner"); } if (ticket.getKey() == null) { ticket.setKey(ticketKeyGenerator.allocateToken("").getKey()); } ticket.setCreated(new Date()); item.addTicket(ticket); this.em.persist(ticket); this.em.merge(item); this.em.flush(); }
@Override public void createTicket(Item item, Ticket ticket) { if (ticket == null) { throw new IllegalArgumentException("ticket cannot be null"); } if (item == null) { throw new IllegalArgumentException("item cannot be null"); } User owner = ticket.getOwner(); if (owner == null) { throw new IllegalArgumentException("ticket must have owner"); } if (ticket.getKey() == null) { ticket.setKey(ticketKeyGenerator.allocateToken("").getKey()); } ticket.setCreated(new Date()); item.addTicket(ticket); this.em.persist(ticket); this.em.merge(item); this.em.flush(); }
protected void setBaseItemProps(Item item) { if (item.getUid() == null) { item.setUid(idGenerator.nextStringIdentifier()); } if (item.getName() == null) { item.setName(item.getUid()); } if (item instanceof ICalendarItem) { ICalendarItem ical = (ICalendarItem) item; if (ical.getIcalUid() == null) { ical.setIcalUid(item.getUid()); EventStamp es = HibEventStamp.getStamp(ical); if (es != null) { es.setIcalUid(ical.getIcalUid()); } } } for (Ticket ticket : item.getTickets()) { if (ticket.getOwner() == null) { ticket.setOwner(item.getOwner()); } if (ticket.getKey() == null) { ticket.setKey(ticketKeyGenerator.allocateToken("").getKey()); } if (ticket.getTimeout() == null) { ticket.setTimeout(Ticket.TIMEOUT_INFINITE); } ticket.setCreated(new Date()); } }
protected void setBaseItemProps(Item item) { if (item.getUid() == null) { item.setUid(idGenerator.nextStringIdentifier()); } if (item.getName() == null) { item.setName(item.getUid()); } if (item instanceof ICalendarItem) { ICalendarItem ical = (ICalendarItem) item; if (ical.getIcalUid() == null) { ical.setIcalUid(item.getUid()); EventStamp es = HibEventStamp.getStamp(ical); if (es != null) { es.setIcalUid(ical.getIcalUid()); } } } for (Ticket ticket : item.getTickets()) { if (ticket.getOwner() == null) { ticket.setOwner(item.getOwner()); } if (ticket.getKey() == null) { ticket.setKey(ticketKeyGenerator.allocateToken("").getKey()); } if (ticket.getTimeout() == null) { ticket.setTimeout(Ticket.TIMEOUT_INFINITE); } ticket.setCreated(new Date()); } }