Minor edits to @MichaelSims pull request - prepping for release

This commit is contained in:
Les Hazlewood 2016-09-12 16:12:30 -07:00
parent a06e35cf84
commit 8f1b528d8c
3 changed files with 15 additions and 15 deletions

View File

@ -131,7 +131,7 @@ public interface JwtParser {
* The parser uses a {@link DefaultClock DefaultClock} instance by default.
*
* @param clock a {@code Clock} object to return the timestamp to use when validating the parsed JWT.
* @return the builder instance for method chaining.
* @return the parser for method chaining.
* @since 0.7.0
*/
JwtParser setClock(Clock clock);
@ -140,11 +140,11 @@ public interface JwtParser {
* Sets the amount of clock skew in seconds to tolerate when verifying the local time against the {@code exp}
* and {@code nbf} claims.
*
* @param seconds
* @param seconds the number of seconds to tolerate for clock skew when verifying {@code exp} or {@code nbf} claims.
* @return the parser for method chaining.
* @since 0.7.0
*/
JwtParser setAllowedClockSkewInSeconds(int seconds);
JwtParser setAllowedClockSkewSeconds(long seconds);
/**
* Sets the signing key used to verify any discovered JWS digital signature. If the specified JWT string is not

View File

@ -73,7 +73,7 @@ public class DefaultJwtParser implements JwtParser {
private Clock clock = DefaultClock.INSTANCE;
private int allowedClockSkewInSeconds = 0;
private long allowedClockSkewSeconds = 0;
@Override
public JwtParser requireIssuedAt(Date issuedAt) {
@ -141,8 +141,8 @@ public class DefaultJwtParser implements JwtParser {
}
@Override
public JwtParser setAllowedClockSkewInSeconds(int seconds) {
allowedClockSkewInSeconds = seconds;
public JwtParser setAllowedClockSkewSeconds(long seconds) {
allowedClockSkewSeconds = seconds;
return this;
}
@ -366,7 +366,7 @@ public class DefaultJwtParser implements JwtParser {
//since 0.3:
if (claims != null) {
long allowedClockSkewInMilliseconds = (long) allowedClockSkewInSeconds * MILLISECONDS_PER_SECOND;
long allowedClockSkewMillis = allowedClockSkewSeconds * MILLISECONDS_PER_SECOND;
SimpleDateFormat sdf;
final Date now = this.clock.now();
@ -376,14 +376,14 @@ public class DefaultJwtParser implements JwtParser {
Date exp = claims.getExpiration();
if (exp != null) {
Date nowWithAllowedClockSkew = new Date(now.getTime() - allowedClockSkewInMilliseconds);
Date nowWithAllowedClockSkew = new Date(now.getTime() - allowedClockSkewMillis);
if (nowWithAllowedClockSkew.equals(exp) || nowWithAllowedClockSkew.after(exp)) {
sdf = new SimpleDateFormat(ISO_8601_FORMAT);
String expVal = sdf.format(exp);
String nowVal = sdf.format(now);
String msg = "JWT expired at " + expVal + ". Current time: " + nowVal +
". Allowed clock skew: " + allowedClockSkewInSeconds + " second(s).";
". Allowed clock skew: " + allowedClockSkewSeconds + " second(s).";
throw new ExpiredJwtException(header, claims, msg);
}
}
@ -393,14 +393,14 @@ public class DefaultJwtParser implements JwtParser {
Date nbf = claims.getNotBefore();
if (nbf != null) {
Date nowWithAllowedClockSkew = new Date(now.getTime() + allowedClockSkewInMilliseconds);
Date nowWithAllowedClockSkew = new Date(now.getTime() + allowedClockSkewMillis);
if (nowWithAllowedClockSkew.before(nbf)) {
sdf = new SimpleDateFormat(ISO_8601_FORMAT);
String nbfVal = sdf.format(nbf);
String nowVal = sdf.format(now);
String msg = "JWT must not be accepted before " + nbfVal + ". Current time: " + nowVal +
". Allowed clock skew: " + allowedClockSkewInSeconds + " second(s).";
". Allowed clock skew: " + allowedClockSkewSeconds + " second(s).";
throw new PrematureJwtException(header, claims, msg);
}
}

View File

@ -206,7 +206,7 @@ class JwtParserTest {
String subject = 'Joe'
String compact = Jwts.builder().setSubject(subject).setExpiration(exp).compact()
Jwt<Header,Claims> jwt = Jwts.parser().setAllowedClockSkewInSeconds(10).parse(compact)
Jwt<Header,Claims> jwt = Jwts.parser().setAllowedClockSkewSeconds(10).parse(compact)
assertEquals jwt.getBody().getSubject(), subject
}
@ -218,7 +218,7 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setExpiration(exp).compact()
try {
Jwts.parser().setAllowedClockSkewInSeconds(1).parse(compact)
Jwts.parser().setAllowedClockSkewSeconds(1).parse(compact)
fail()
} catch (ExpiredJwtException e) {
assertTrue e.getMessage().startsWith('JWT expired at ')
@ -232,7 +232,7 @@ class JwtParserTest {
String subject = 'Joe'
String compact = Jwts.builder().setSubject(subject).setNotBefore(exp).compact()
Jwt<Header,Claims> jwt = Jwts.parser().setAllowedClockSkewInSeconds(10).parse(compact)
Jwt<Header,Claims> jwt = Jwts.parser().setAllowedClockSkewSeconds(10).parse(compact)
assertEquals jwt.getBody().getSubject(), subject
}
@ -244,7 +244,7 @@ class JwtParserTest {
String compact = Jwts.builder().setSubject('Joe').setNotBefore(exp).compact()
try {
Jwts.parser().setAllowedClockSkewInSeconds(1).parse(compact)
Jwts.parser().setAllowedClockSkewSeconds(1).parse(compact)
fail()
} catch (PrematureJwtException e) {
assertTrue e.getMessage().startsWith('JWT must not be accepted before ')