hazmat345 commented on code in PR #9566:
URL: https://github.com/apache/nifi/pull/9566#discussion_r1881034959


##########
nifi-registry/nifi-registry-core/nifi-registry-web-api/src/main/java/org/apache/nifi/registry/web/security/authentication/jwt/JwtService.java:
##########
@@ -82,6 +85,27 @@ public String getUserIdentityFromToken(final String 
base64EncodedToken) throws J
         }
     }
 
+    public Set<String> getUserGroupsFromToken(final String base64EncodedToken) 
throws JwtException {
+        // The library representations of the JWT should be kept internal to 
this service.
+        try {
+            final Jws<Claims> jws = 
parseTokenFromBase64EncodedString(base64EncodedToken);
+
+            if (jws == null) {
+                throw new JwtException("Unable to parse token");
+            }
+
+            @SuppressWarnings("unchecked")
+            ArrayList<String> groupsString = 
jws.getPayload().get(GROUPS_CLAIM, ArrayList.class);
+
+            return new HashSet<>(groupsString);
+        } catch (JwtException e) {
+            logger.debug("The Base64 encoded JWT: " + base64EncodedToken);
+            final String errorMessage = "There was an error validating the 
JWT";
+            logger.error(errorMessage, e);
+            throw e;

Review Comment:
   Makes sense. I copied the exception handling from the 
`getUserIdentityFromToken` method above, so I'll change this in both places.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to