You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to generate a new JWT with the current Authentication, but with a new expiration.
Calling JwtTokenGenerator.generateToken(authentication, newExp) should create a new token derived from the authentication, with an exp claim that matches thenewExp that I pass in.
Actual Behaviour
Instead, I get a new token with an exp claim that matches the previous exp claim from the authentication.
It looks like the JWTClaimsSetGenerator sets the exp claim from the provided expiration value, but then overwrites all claims from the authentication.
Instead, if an expiration is provided, it should be set after populating claims from the authentication.
Here's the relevant code as it looks today:
public Map<String, Object> generateClaims(Authentication authentication, @Nullable Integer expiration) {
JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder();
this.populateIat(builder);
this.populateExp(builder, expiration); // sets the 'exp' claim with provided expiration value
this.populateJti(builder);
this.populateIss(builder);
this.populateAud(builder);
this.populateNbf(builder);
this.populateWithAuthentication(builder, authentication); // overwrites the 'exp' claim with the authentication's original exp
if (LOG.isDebugEnabled()) {
LOG.debug("Generated claim set: {}", builder.build().toJSONObject());
}
return builder.build().getClaims();
}
Steps To Reproduce
Inject a JwtTokenGenerator and attempt to generate a new token with a new desired expiration:
Expected Behavior
I want to generate a new JWT with the current Authentication, but with a new expiration.
Calling
JwtTokenGenerator.generateToken(authentication, newExp)
should create a new token derived from theauthentication
, with anexp
claim that matches thenewExp
that I pass in.Actual Behaviour
Instead, I get a new token with an
exp
claim that matches the previousexp
claim from theauthentication
.It looks like the
JWTClaimsSetGenerator
sets theexp
claim from the provided expiration value, but then overwrites all claims from theauthentication
.Instead, if an expiration is provided, it should be set after populating claims from the
authentication
.Here's the relevant code as it looks today:
Steps To Reproduce
Inject a JwtTokenGenerator and attempt to generate a new token with a new desired expiration:
Inspect the new token and notice that the
exp
claim does not change, regardless of what the specified expiration is set to.Environment Information
Example Application
No response
Version
4.5.0
The text was updated successfully, but these errors were encountered: