AuthServicePluginUtils { public static RoleFilter createRoleFilter(List<RoleResponse> roles, List<GroupResponse> groups) { Set<String> allowed = new HashSet<>(); groups.forEach(g -> { g.getRoles().forEach(r -> { allowed.add(r.getName() + "-" + g.getName()); }); }); roles.forEach(r -> { r.getGroups().forEach(g -> { allowed.add(r.getName() + "-" + g.getName()); }); }); return (groupName, roleName) -> { return !allowed.contains(roleName + "-" + groupName); }; } private  AuthServicePluginUtils(); static RoleFilter createRoleFilter(List<RoleResponse> roles, List<GroupResponse> groups); static GroupFilter createGroupFilter(List<GroupResponse> groups);  }
@Test public void testRoleFilter() { List<RoleResponse> roles = new ArrayList<>(); roles.add(new RoleResponse().setName("role1").setGroups(new GroupReference().setName("group1"))); roles.add(new RoleResponse().setName("role2")); roles.add(new RoleResponse().setName("role3")); List<GroupResponse> groups = new ArrayList<>(); groups.add(new GroupResponse().setName("group2").setRoles(new RoleReference().setName("role2"))); groups.add(new GroupResponse().setName("group3")); RoleFilter filter = AuthServicePluginUtils.createRoleFilter(roles, groups); assertTrue(filter.filter("admin", "role")); assertTrue(filter.filter("group3", "role3")); assertFalse(filter.filter("group2", "role2")); assertFalse(filter.filter("group1", "role1")); }