Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JwtTimestampValidator.java #6416

Merged
merged 1 commit into from
Jan 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
public final class JwtTimestampValidator implements OAuth2TokenValidator<Jwt> {
private static final Duration DEFAULT_MAX_CLOCK_SKEW = Duration.of(60, ChronoUnit.SECONDS);

private final Duration maxClockSkew;
private final Duration clockSkew;

private Clock clock = Clock.systemUTC();

Expand All @@ -55,10 +55,10 @@ public JwtTimestampValidator() {
this(DEFAULT_MAX_CLOCK_SKEW);
}

public JwtTimestampValidator(Duration maxClockSkew) {
Assert.notNull(maxClockSkew, "maxClockSkew cannot be null");
public JwtTimestampValidator(Duration clockSkew) {
Assert.notNull(clockSkew, "clockSkew cannot be null");

this.maxClockSkew = maxClockSkew;
this.clockSkew = clockSkew;
}

/**
Expand All @@ -71,7 +71,7 @@ public OAuth2TokenValidatorResult validate(Jwt jwt) {
Instant expiry = jwt.getExpiresAt();

if (expiry != null) {
if (Instant.now(this.clock).minus(maxClockSkew).isAfter(expiry)) {
if (Instant.now(this.clock).minus(clockSkew).isAfter(expiry)) {
OAuth2Error error = new OAuth2Error(
OAuth2ErrorCodes.INVALID_REQUEST,
String.format("Jwt expired at %s", jwt.getExpiresAt()),
Expand All @@ -83,7 +83,7 @@ public OAuth2TokenValidatorResult validate(Jwt jwt) {
Instant notBefore = jwt.getNotBefore();

if (notBefore != null) {
if (Instant.now(this.clock).plus(maxClockSkew).isBefore(notBefore)) {
if (Instant.now(this.clock).plus(clockSkew).isBefore(notBefore)) {
OAuth2Error error = new OAuth2Error(
OAuth2ErrorCodes.INVALID_REQUEST,
String.format("Jwt used before %s", jwt.getNotBefore()),
Expand Down