janhoy commented on code in PR #890:
URL: https://github.com/apache/solr/pull/890#discussion_r966499940


##########
solr/modules/jwt-auth/src/java/org/apache/solr/security/jwt/JWTAuthPlugin.java:
##########
@@ -598,12 +598,26 @@ protected JWTAuthenticationResponse authenticate(String 
authorizationHeader) {
             } else {
               // Pull roles from separate claim, either as whitespace 
separated list or as JSON
               // array
-              Object rolesObj = jwtClaims.getClaimValue(rolesClaim);
+              Object rolesObj;
+              if (rolesClaim.indexOf('.') > 0) {
+                // support map resolution of nested values
+                String[] nestedKeys = rolesClaim.split("\\.");
+                rolesObj = jwtClaims.getClaimValue(nestedKeys[0]);
+                for (int i = 1; i < nestedKeys.length; i++) {
+                  if (rolesObj instanceof Map) {
+                    String key = nestedKeys[i];
+                    rolesObj = ((Map<?, ?>) rolesObj).get(key);
+                  }
+                }
+              } else {
+                rolesObj = jwtClaims.getClaimValue(rolesClaim);
+              }
+
               if (rolesObj != null) {
                 if (rolesObj instanceof String) {
                   finalRoles.addAll(Arrays.asList(((String) 
rolesObj).split("\\s+")));
                 } else if (rolesObj instanceof List) {
-                  
finalRoles.addAll(jwtClaims.getStringListClaimValue(rolesClaim));
+                  ((List<?>) rolesObj).forEach(entry -> 
finalRoles.add((String) entry));

Review Comment:
   Yea. The CCEx could happen either due to a mis-config, or due to some bad 
Access Token. In either case the best would probably be an `else` clause there 
which would log/throw a meaningful error:
   ```suggestion
                     ((List<?>) rolesObj)
                         .forEach(
                             entry -> {
                               if (entry instanceof String) {
                                 finalRoles.add((String) entry);
                               } else {
                                 throw new SolrException(
                                     SolrException.ErrorCode.BAD_REQUEST,
                                     String.format(
                                         "Could not parse roles from JWT claim 
%s; expected array of strings, got array with a value of type %s",
                                         rolesClaim, 
entry.getClass().getSimpleName()));
                               }
                             });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to