@Test public void testValidateTokenWithoutAudiences() throws Exception { JwtAuthenticationProperties properties = createTestProperties(); JwtAuthenticationFilter filter = new JwtAuthenticationFilter(properties, null, null); boolean isValid = filter.validateAudiences(getSignedToken(null)); assertEquals(false, isValid); }
protected boolean validateAudiences(SignedJWT jwtToken) { boolean valid = false; try { List<String> tokenAudienceList = jwtToken.getJWTClaimsSet() .getAudience(); if (audiences == null) { valid = true; } else { if (tokenAudienceList == null) { LOG.warn("JWT token has no audiences, validation failed."); return false; } for (String aud : tokenAudienceList) { if (audiences.contains(aud)) { LOG.debug("JWT token audience has been successfully validated"); valid = true; break; } } if (!valid) { LOG.warn("JWT audience validation failed."); } } } catch (ParseException pe) { LOG.warn("Unable to parse the JWT token.", pe); } return valid; }
JwtAuthenticationFilter implements AmbariAuthenticationFilter { protected boolean validateAudiences(SignedJWT jwtToken) { boolean valid = false; try { List<String> tokenAudienceList = jwtToken.getJWTClaimsSet() .getAudience(); if (audiences == null) { valid = true; } else { if (tokenAudienceList == null) { LOG.warn("JWT token has no audiences, validation failed."); return false; } for (String aud : tokenAudienceList) { if (audiences.contains(aud)) { LOG.debug("JWT token audience has been successfully validated"); valid = true; break; } } if (!valid) { LOG.warn("JWT audience validation failed."); } } } catch (ParseException pe) { LOG.warn("Unable to parse the JWT token.", pe); } return valid; } }
JwtAuthenticationFilter implements AmbariAuthenticationFilter { protected boolean validateAudiences(SignedJWT jwtToken) { boolean valid = false; try { List<String> tokenAudienceList = jwtToken.getJWTClaimsSet() .getAudience(); if (audiences == null) { valid = true; } else { if (tokenAudienceList == null) { LOG.warn("JWT token has no audiences, validation failed."); return false; } for (String aud : tokenAudienceList) { if (audiences.contains(aud)) { LOG.debug("JWT token audience has been successfully validated"); valid = true; break; } } if (!valid) { LOG.warn("JWT audience validation failed."); } } } catch (ParseException pe) { LOG.warn("Unable to parse the JWT token.", pe); } return valid; } JwtAuthenticationFilter(Configuration configuration, AuthenticationEntryPoint entryPoint, Users users);  JwtAuthenticationFilter(JwtAuthenticationProperties jwtProperties, AuthenticationEntryPoint entryPoint,
                                 Users users); }
JwtAuthenticationFilter implements AmbariAuthenticationFilter { protected boolean validateAudiences(SignedJWT jwtToken) { boolean valid = false; try { List<String> tokenAudienceList = jwtToken.getJWTClaimsSet() .getAudience(); if (audiences == null) { valid = true; } else { if (tokenAudienceList == null) { LOG.warn("JWT token has no audiences, validation failed."); return false; } for (String aud : tokenAudienceList) { if (audiences.contains(aud)) { LOG.debug("JWT token audience has been successfully validated"); valid = true; break; } } if (!valid) { LOG.warn("JWT audience validation failed."); } } } catch (ParseException pe) { LOG.warn("Unable to parse the JWT token.", pe); } return valid; } JwtAuthenticationFilter(Configuration configuration, AuthenticationEntryPoint entryPoint, Users users);  JwtAuthenticationFilter(JwtAuthenticationProperties jwtProperties, AuthenticationEntryPoint entryPoint,
                                 Users users); @Override boolean shouldApply(HttpServletRequest httpServletRequest); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); @Override void destroy(); }
JwtAuthenticationFilter implements AmbariAuthenticationFilter { protected boolean validateAudiences(SignedJWT jwtToken) { boolean valid = false; try { List<String> tokenAudienceList = jwtToken.getJWTClaimsSet() .getAudience(); if (audiences == null) { valid = true; } else { if (tokenAudienceList == null) { LOG.warn("JWT token has no audiences, validation failed."); return false; } for (String aud : tokenAudienceList) { if (audiences.contains(aud)) { LOG.debug("JWT token audience has been successfully validated"); valid = true; break; } } if (!valid) { LOG.warn("JWT audience validation failed."); } } } catch (ParseException pe) { LOG.warn("Unable to parse the JWT token.", pe); } return valid; } JwtAuthenticationFilter(Configuration configuration, AuthenticationEntryPoint entryPoint, Users users);  JwtAuthenticationFilter(JwtAuthenticationProperties jwtProperties, AuthenticationEntryPoint entryPoint,
                                 Users users); @Override boolean shouldApply(HttpServletRequest httpServletRequest); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); @Override void destroy();  }