Skip to content

Commit

Permalink
small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
akurnosau committed Dec 11, 2024
1 parent c3642d9 commit 8d5651f
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,7 @@ private List<String> extractUserRoles(Map<String, Object> map) {

@SuppressWarnings({"unchecked", "rawtypes"})
private List<String> extractUserRoles(Map<String, Object> map, String[] rolePath) {
for (int i = 0; i < rolePath.length - 1; i++) {
if (map.get(rolePath[i]) instanceof Map next) {
map = next;
} else {
return EMPTY_LIST;
}
}
Object field = map.get(rolePath[rolePath.length - 1]);
Object field = extractClaim(map, rolePath);

if (field instanceof List list) {
return list;
Expand Down Expand Up @@ -253,18 +246,24 @@ private static String extractUserSub(Map<String, Object> userContext) {
}

@SuppressWarnings({"unchecked", "rawtypes"})
private String extractProject(Map<String, Object> claims) {
if (projectPath == null) {
return null;
}
for (int i = 0; i < projectPath.length - 1; i++) {
if (claims.get(projectPath[i]) instanceof Map next) {
private static Object extractClaim(Map<String, Object> claims, String[] claimPath) {
for (int i = 0; i < claimPath.length - 1; i++) {
if (claims.get(claimPath[i]) instanceof Map next) {
claims = next;
} else {
return null;
}
}
Object field = claims.get(projectPath[projectPath.length - 1]);
return claims.get(claimPath[claimPath.length - 1]);
}


private String extractProject(Map<String, Object> claims) {
if (projectPath == null) {
return null;
}
Object field = extractClaim(claims, projectPath);

if (field instanceof String project) {
return project;
}
Expand Down

0 comments on commit 8d5651f

Please sign in to comment.