Skip to content

Commit

Permalink
Refactor the backendrole extraction in oboauthenticator
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Aug 22, 2023
1 parent 9c9e060 commit e52c5ce
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,24 @@ private List<String> extractSecurityRolesFromClaims(Claims claims) {
log.warn("This is a malformed On-behalf-of Token");
}

return Arrays.stream(rolesClaim.split(",")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableList());
List<String> roles = Arrays.stream(rolesClaim.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toUnmodifiableList());

return roles;
}

private String[] extractBackendRolesFromClaims(Claims claims) {
// Object backendRolesObject = ObjectUtils.firstNonNull(claims.get("ebr"), claims.get("dbr"));
if (!claims.containsKey("br")) {
return null;
}

Object backendRolesObject = claims.get("br");
String[] backendRoles;

if (backendRolesObject == null) {
log.warn("This is a malformed On-behalf-of Token");
backendRoles = new String[0];
} else {
final String backendRolesClaim = backendRolesObject.toString();

// Extracting roles based on the compatibility mode
String decryptedBackendRoles = backendRolesClaim;
backendRoles = Arrays.stream(decryptedBackendRoles.split(",")).map(String::trim).toArray(String[]::new);
backendRoles = Arrays.stream(backendRolesObject.toString().split(",")).map(String::trim).toArray(String[]::new);
}

return backendRoles;
Expand Down

0 comments on commit e52c5ce

Please sign in to comment.