diff --git a/server/src/main/java/com/epam/aidial/core/server/security/IdentityProvider.java b/server/src/main/java/com/epam/aidial/core/server/security/IdentityProvider.java index a187b26d..8a79ddfd 100644 --- a/server/src/main/java/com/epam/aidial/core/server/security/IdentityProvider.java +++ b/server/src/main/java/com/epam/aidial/core/server/security/IdentityProvider.java @@ -177,14 +177,7 @@ private List extractUserRoles(Map map) { @SuppressWarnings({"unchecked", "rawtypes"}) private List extractUserRoles(Map 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; @@ -253,18 +246,24 @@ private static String extractUserSub(Map userContext) { } @SuppressWarnings({"unchecked", "rawtypes"}) - private String extractProject(Map 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 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 claims) { + if (projectPath == null) { + return null; + } + Object field = extractClaim(claims, projectPath); + if (field instanceof String project) { return project; }