Skip to content

Commit

Permalink
merge #2706 buildkite provier to jetty 1.12.x branch (#2717)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <hga@yahooinc.com>
  • Loading branch information
havetisyan authored Sep 5, 2024
1 parent 95e77da commit ea0880e
Show file tree
Hide file tree
Showing 15 changed files with 1,414 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ long parseDateValue(Date date) {

void setTokenFields() {

setVersion(JwtsHelper.getIntegerClaim(claimsSet, CLAIM_VERSION));
setVersion(JwtsHelper.getIntegerClaim(claimsSet, CLAIM_VERSION, 0));
List<String> audiences = claimsSet.getAudience();
if (audiences != null && !audiences.isEmpty()) {
setAudience(audiences.get(0));
}
setExpiryTime(parseDateValue(claimsSet.getExpirationTime()));
setIssueTime(parseDateValue(claimsSet.getIssueTime()));
setNotBeforeTime(parseDateValue(claimsSet.getNotBeforeTime()));
setAuthTime(JwtsHelper.getLongClaim(claimsSet, CLAIM_AUTH_TIME));
setAuthTime(JwtsHelper.getLongClaim(claimsSet, CLAIM_AUTH_TIME, 0));
setIssuer(claimsSet.getIssuer());
setSubject(claimsSet.getSubject());
setJwtId(claimsSet.getJWTID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,21 @@ public static ConfigurableJWTProcessor<SecurityContext> getJWTProcessor(JwtsSign
return jwtProcessor;
}

public static int getIntegerClaim(JWTClaimsSet claims, final String claim) {
public static int getIntegerClaim(JWTClaimsSet claims, final String claim, int defaultValue) {
try {
return claims.getIntegerClaim(claim);
Integer value = claims.getIntegerClaim(claim);
return value == null ? defaultValue : value;
} catch (ParseException ex) {
return 0;
return defaultValue;
}
}

public static long getLongClaim(JWTClaimsSet claims, final String claim) {
public static long getLongClaim(JWTClaimsSet claims, final String claim, long defaultValue) {
try {
return claims.getLongClaim(claim);
Long value = claims.getLongClaim(claim);
return value == null ? defaultValue : value;
} catch (ParseException ex) {
return 0;
return defaultValue;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ public void testParseFailures() {
.build();
assertNull(JwtsHelper.getStringClaim(claimsSet, "string"));
assertNull(JwtsHelper.getStringListClaim(claimsSet, "stringlist"));
assertEquals(JwtsHelper.getIntegerClaim(claimsSet, "integer"), 0);
assertEquals(JwtsHelper.getLongClaim(claimsSet, "long"), 0);
assertEquals(JwtsHelper.getIntegerClaim(claimsSet, "integer", 0), 0);
assertEquals(JwtsHelper.getLongClaim(claimsSet, "long", -1), -1);
assertNull(JwtsHelper.getAudience(claimsSet));
}
}
Loading

0 comments on commit ea0880e

Please sign in to comment.