kumaab commented on code in PR #901:
URL: https://github.com/apache/ranger/pull/901#discussion_r3053065488
##########
ranger-authn/src/main/java/org/apache/ranger/authz/handler/jwt/RangerJwtAuthHandler.java:
##########
@@ -290,6 +303,38 @@ protected boolean validateAudiences(final SignedJWT
jwtToken) {
return valid;
}
+ /**
+ * Validate whether any of the accepted issuer claims is present in the
issued
+ * token claims list for issuer. Override this method in subclasses in
order
+ * to customize the audience validation behavior.
+ *
+ * @param jwtToken the JWT token from which the JWT issuer will be obtained
+ * @return true if an expected issuer is present, otherwise false
+ */
+ protected boolean validateIssuer(final SignedJWT jwtToken) {
+ boolean valid = false;
+ try {
+ String tokenIssuer = jwtToken.getJWTClaimsSet().getIssuer();
+ // if no expected issuer is configured then consider any issuer
acceptable
+ if (StringUtils.isBlank(issuer)) {
+ valid = true;
+ } else {
+ // if any of the configured issuers is found then consider it
acceptable
+ if (issuer.equals(tokenIssuer)) {
+ if (LOG.isDebugEnabled()) {
Review Comment:
Remove if condition `LOG.isDebugEnabled()`
##########
ranger-authn/src/main/java/org/apache/ranger/authz/handler/jwt/RangerJwtAuthHandler.java:
##########
@@ -290,6 +303,38 @@ protected boolean validateAudiences(final SignedJWT
jwtToken) {
return valid;
}
+ /**
+ * Validate whether any of the accepted issuer claims is present in the
issued
Review Comment:
Update the comments here for one issuer check.
##########
ranger-authn/src/main/java/org/apache/ranger/authz/handler/jwt/RangerJwtAuthHandler.java:
##########
@@ -290,6 +303,38 @@ protected boolean validateAudiences(final SignedJWT
jwtToken) {
return valid;
}
+ /**
+ * Validate whether any of the accepted issuer claims is present in the
issued
+ * token claims list for issuer. Override this method in subclasses in
order
+ * to customize the audience validation behavior.
+ *
+ * @param jwtToken the JWT token from which the JWT issuer will be obtained
+ * @return true if an expected issuer is present, otherwise false
+ */
+ protected boolean validateIssuer(final SignedJWT jwtToken) {
+ boolean valid = false;
+ try {
+ String tokenIssuer = jwtToken.getJWTClaimsSet().getIssuer();
+ // if no expected issuer is configured then consider any issuer
acceptable
+ if (StringUtils.isBlank(issuer)) {
Review Comment:
Simplify `if else` into one `if`:
```
boolean valid = false;
if ( StringUtils.isBlank(issuer) || issuer.equals(tokenIssuer)){
valid = true;
LOG.debug("JWT token issuer has been successfully validated");
}
```
##########
security-admin/src/test/java/org/apache/ranger/security/web/filter/TestRangerSSOAuthenticationFilter.java:
##########
@@ -498,4 +498,9 @@ public void
testDoFilter_ssoDisabled_locallogin_redirectsToLoginJsp() throws Exc
verify(res, times(1)).sendRedirect("/login.jsp");
verify(chain, times(0)).doFilter(any(ServletRequest.class),
any(ServletResponse.class));
}
+
+ @Test
Review Comment:
What value does this test add? A test function to test `protected boolean
validateIssuer(final SignedJWT jwtToken) {` seems appropriate.
--
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]