@Test(expected = MalformedContinuationTokenException.class) public void continuationTokenWithMalformedDatesShouldThrow() throws Exception { ContinuationToken.fromString(USER + ContinuationToken.SEPARATOR + "2011-25-03T10:15:30+01:00" + ContinuationToken.SEPARATOR + SIGNATURE); }
public static ContinuationToken fromString(String serializedToken) throws MalformedContinuationTokenException { Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedToken), "Serialized continuation token should not be null or empty"); LinkedList<String> tokenParts = Lists.newLinkedList(Splitter.on(SEPARATOR).split(serializedToken)); try { return ContinuationToken.builder() .signature(tokenParts.removeLast()) .expirationDate(ZonedDateTime.parse(tokenParts.removeLast(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .username(Joiner.on(SEPARATOR).join(tokenParts)) .build(); } catch (NoSuchElementException | IllegalArgumentException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " does not have enough parts", e); } catch (DateTimeException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " as an incorrect date", e); } }
ContinuationToken implements SignedExpiringToken { public static ContinuationToken fromString(String serializedToken) throws MalformedContinuationTokenException { Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedToken), "Serialized continuation token should not be null or empty"); LinkedList<String> tokenParts = Lists.newLinkedList(Splitter.on(SEPARATOR).split(serializedToken)); try { return ContinuationToken.builder() .signature(tokenParts.removeLast()) .expirationDate(ZonedDateTime.parse(tokenParts.removeLast(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .username(Joiner.on(SEPARATOR).join(tokenParts)) .build(); } catch (NoSuchElementException | IllegalArgumentException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " does not have enough parts", e); } catch (DateTimeException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " as an incorrect date", e); } } }
ContinuationToken implements SignedExpiringToken { public static ContinuationToken fromString(String serializedToken) throws MalformedContinuationTokenException { Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedToken), "Serialized continuation token should not be null or empty"); LinkedList<String> tokenParts = Lists.newLinkedList(Splitter.on(SEPARATOR).split(serializedToken)); try { return ContinuationToken.builder() .signature(tokenParts.removeLast()) .expirationDate(ZonedDateTime.parse(tokenParts.removeLast(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .username(Joiner.on(SEPARATOR).join(tokenParts)) .build(); } catch (NoSuchElementException | IllegalArgumentException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " does not have enough parts", e); } catch (DateTimeException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " as an incorrect date", e); } } ContinuationToken(String username, ZonedDateTime expirationDate, String signature); }
ContinuationToken implements SignedExpiringToken { public static ContinuationToken fromString(String serializedToken) throws MalformedContinuationTokenException { Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedToken), "Serialized continuation token should not be null or empty"); LinkedList<String> tokenParts = Lists.newLinkedList(Splitter.on(SEPARATOR).split(serializedToken)); try { return ContinuationToken.builder() .signature(tokenParts.removeLast()) .expirationDate(ZonedDateTime.parse(tokenParts.removeLast(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .username(Joiner.on(SEPARATOR).join(tokenParts)) .build(); } catch (NoSuchElementException | IllegalArgumentException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " does not have enough parts", e); } catch (DateTimeException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " as an incorrect date", e); } } ContinuationToken(String username, ZonedDateTime expirationDate, String signature); static Builder builder(); static ContinuationToken fromString(String serializedToken); String getUsername(); @Override ZonedDateTime getExpirationDate(); @Override String getSignature(); String serialize(); @Override String getPayload(); @Override String getSignedContent(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); }
ContinuationToken implements SignedExpiringToken { public static ContinuationToken fromString(String serializedToken) throws MalformedContinuationTokenException { Preconditions.checkArgument(!Strings.isNullOrEmpty(serializedToken), "Serialized continuation token should not be null or empty"); LinkedList<String> tokenParts = Lists.newLinkedList(Splitter.on(SEPARATOR).split(serializedToken)); try { return ContinuationToken.builder() .signature(tokenParts.removeLast()) .expirationDate(ZonedDateTime.parse(tokenParts.removeLast(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)) .username(Joiner.on(SEPARATOR).join(tokenParts)) .build(); } catch (NoSuchElementException | IllegalArgumentException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " does not have enough parts", e); } catch (DateTimeException e) { throw new MalformedContinuationTokenException("Token " + serializedToken + " as an incorrect date", e); } } ContinuationToken(String username, ZonedDateTime expirationDate, String signature); static Builder builder(); static ContinuationToken fromString(String serializedToken); String getUsername(); @Override ZonedDateTime getExpirationDate(); @Override String getSignature(); String serialize(); @Override String getPayload(); @Override String getSignedContent(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); static final String SEPARATOR; }