UaaTokenUtils { public static boolean hasRequiredUserAuthorities(Collection<String> requiredGroups, Collection<? extends GrantedAuthority> userGroups) { return hasRequiredUserGroups(requiredGroups, ofNullable(userGroups).orElse(emptySet()) .stream() .map(GrantedAuthority::getAuthority) .collect(Collectors.toList()) ); } private  UaaTokenUtils(); static String getRevocationHash(List<String> salts); static int murmurhash3x8632(byte[] data, int offset, int len, int seed); static Set<String> retainAutoApprovedScopes(Collection<String> requestedScopes, Set<String> autoApprovedScopes); static boolean isUserToken(Map<String, Object> claims); static String getRevocableTokenSignature(ClientDetails client, String clientSecret, UaaUser user); static String getRevocableTokenSignature(UaaUser user, String tokenSalt, String clientId, String clientSecret); static String constructToken(Map<String, Object> header, Map<String, Object> claims, Signer signer); static boolean isJwtToken(String token); static String constructTokenEndpointUrl(String issuer, IdentityZone identityZone); static boolean hasRequiredUserAuthorities(Collection<String> requiredGroups, Collection<? extends GrantedAuthority> userGroups); static boolean hasRequiredUserGroups(Collection<String> requiredGroups, Collection<String> userGroups); static Map<String, Object> getClaims(String jwtToken); static final Pattern jwtPattern; }
@Test public void required_user_groups_null_args_are_ok() { assertTrue(hasRequiredUserAuthorities(null, null)); assertTrue(hasRequiredUserAuthorities(emptySet(), null)); assertTrue(hasRequiredUserAuthorities(null, emptySet())); assertTrue(hasRequiredUserAuthorities(emptySet(), emptySet())); }
@Test public void test_required_user_authorities_invalid() { List<String> requiredGroups = Arrays.asList("scope1","scope2","scope3","scope4"); List<GrantedAuthority> userGroups = Arrays.asList( new SimpleGrantedAuthority("scope1"), new SimpleGrantedAuthority("scope2"), new SimpleGrantedAuthority("scope3"), new SimpleGrantedAuthority("scope5") ); assertFalse(UaaTokenUtils.hasRequiredUserAuthorities(requiredGroups, userGroups)); }
@Test public void test_required_user_authorities_valid() { List<String> requiredGroups = Arrays.asList("scope1","scope2","scope3"); List<GrantedAuthority> userGroups = Arrays.asList( new SimpleGrantedAuthority("scope1"), new SimpleGrantedAuthority("scope2"), new SimpleGrantedAuthority("scope3"), new SimpleGrantedAuthority("scope4") ); assertTrue(UaaTokenUtils.hasRequiredUserAuthorities(requiredGroups, userGroups)); }