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

feat: fix JWT parse bug #71

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 5 additions & 5 deletions src/main/java/org/casbin/casdoor/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@
// read "access_token" from payload and convert to CasdoorUser
try {
JWTClaimsSet claimsSet = parseJwt.getJWTClaimsSet();
String accessToken = claimsSet.getStringClaim("access_token");
String userJson = claimsSet == null ? null : claimsSet.toString();

if (accessToken == null || accessToken.isEmpty()) {
throw new AuthException("Access token not found in JWT payload.");
if (userJson == null || userJson.isEmpty()) {
throw new AuthException("Cannot get claims from JWT payload.");

Check warning on line 99 in src/main/java/org/casbin/casdoor/service/AuthService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/casdoor/service/AuthService.java#L99

Added line #L99 was not covered by tests
}

return objectMapper.readValue(accessToken, User.class);
return objectMapper.readValue(userJson, User.class);

Check warning on line 102 in src/main/java/org/casbin/casdoor/service/AuthService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/casdoor/service/AuthService.java#L102

Added line #L102 was not covered by tests
} catch (JsonProcessingException | java.text.ParseException e) {
throw new AuthException("Cannot read access token from JWT payload.", e);
throw new AuthException("Cannot convert claims to User", e);

Check warning on line 104 in src/main/java/org/casbin/casdoor/service/AuthService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/casbin/casdoor/service/AuthService.java#L104

Added line #L104 was not covered by tests
}
}

Expand Down
Loading