mirror of
https://github.com/jwtk/jjwt.git
synced 2025-02-10 19:34:41 +00:00
Refactored validateExpectedClaims
This commit is contained in:
parent
62ccd16748
commit
5dd95b6755
@ -363,18 +363,32 @@ public class DefaultJwtParser implements JwtParser {
|
|||||||
|
|
||||||
private void validateExpectedClaims(Header header, Claims claims) {
|
private void validateExpectedClaims(Header header, Claims claims) {
|
||||||
for (String expectedClaimName : expectedClaims.keySet()) {
|
for (String expectedClaimName : expectedClaims.keySet()) {
|
||||||
Object expectedClaimValue;
|
|
||||||
Object actualClaimValue;
|
|
||||||
|
|
||||||
// since issued at is a date, call the specific method
|
// this will be overridden if one of the default claims is used
|
||||||
// other methods deal with strings and the more
|
Object expectedClaimValue = expectedClaims.get(expectedClaimName);
|
||||||
// general method can be used
|
Object actualClaimValue = claims.get(expectedClaimName);
|
||||||
|
|
||||||
if (Claims.ISSUED_AT.equals(expectedClaimName)) {
|
if (Claims.ISSUED_AT.equals(expectedClaimName)) {
|
||||||
expectedClaimValue = expectedClaims.getIssuedAt();
|
expectedClaimValue = expectedClaims.getIssuedAt();
|
||||||
actualClaimValue = claims.getIssuedAt();
|
actualClaimValue = claims.getIssuedAt();
|
||||||
} else {
|
} else if (Claims.AUDIENCE.equals(expectedClaimName)) {
|
||||||
expectedClaimValue = expectedClaims.get(expectedClaimName);
|
expectedClaimValue = expectedClaims.getAudience();
|
||||||
actualClaimValue = claims.get(expectedClaimName);
|
actualClaimValue = claims.getAudience();
|
||||||
|
} else if (Claims.ISSUER.equals(expectedClaimName)) {
|
||||||
|
expectedClaimValue = expectedClaims.getIssuer();
|
||||||
|
actualClaimValue = claims.getIssuer();
|
||||||
|
} else if (Claims.SUBJECT.equals(expectedClaimName)) {
|
||||||
|
expectedClaimValue = expectedClaims.getSubject();
|
||||||
|
actualClaimValue = claims.getSubject();
|
||||||
|
} else if (Claims.EXPIRATION.equals(expectedClaimName)) {
|
||||||
|
expectedClaimValue = expectedClaims.getExpiration();
|
||||||
|
actualClaimValue = claims.getExpiration();
|
||||||
|
} else if (Claims.NOT_BEFORE.equals(expectedClaimName)) {
|
||||||
|
expectedClaimValue = expectedClaims.getNotBefore();
|
||||||
|
actualClaimValue = claims.getNotBefore();
|
||||||
|
} else if (Claims.ID.equals(expectedClaimName)) {
|
||||||
|
expectedClaimValue = expectedClaims.getId();
|
||||||
|
actualClaimValue = claims.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidClaimException invalidClaimException = null;
|
InvalidClaimException invalidClaimException = null;
|
||||||
@ -385,8 +399,7 @@ public class DefaultJwtParser implements JwtParser {
|
|||||||
expectedClaimName, expectedClaimValue
|
expectedClaimName, expectedClaimValue
|
||||||
);
|
);
|
||||||
invalidClaimException = new MissingClaimException(header, claims, msg);
|
invalidClaimException = new MissingClaimException(header, claims, msg);
|
||||||
}
|
} else if (!expectedClaimValue.equals(actualClaimValue)) {
|
||||||
else if (!expectedClaimValue.equals(actualClaimValue)) {
|
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
ClaimJwtException.INCORRECT_EXPECTED_CLAIM_MESSAGE_TEMPLATE,
|
ClaimJwtException.INCORRECT_EXPECTED_CLAIM_MESSAGE_TEMPLATE,
|
||||||
expectedClaimName, expectedClaimValue, actualClaimValue
|
expectedClaimName, expectedClaimValue, actualClaimValue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user