KeyCloakGroupManager extends BaseKeyCloakManager implements GroupManager,
                                                                         ContextualManager { @Override public void assignUsers(String name, Collection<String> users) throws SecurityManagementException { checkNotNull("name", name); if (users != null) { consumeRealm(realmResource -> { final UsersResource usersResource = realmResource.users(); final RolesResource rolesResource = realmResource.roles(); final RoleResource roleResource = rolesResource.get(name); final List<RoleRepresentation> rolesToAdd = new ArrayList<RoleRepresentation>(1); rolesToAdd.add(getRoleRepresentation(name, roleResource)); for (String username : users) { final UserResource userResource = getUserResource(usersResource, username); if (userResource == null) { throw new UserNotFoundException(username); } userResource.roles().realmLevel().add(rolesToAdd); } }); } } KeyCloakGroupManager(); @Override void initialize(UserSystemManager userSystemManager); @Override SearchResponse<Group> search(SearchRequest request); @Override Group get(String identifier); @Override List<Group> getAll(); @Override Group create(Group entity); @Override Group update(Group entity); @Override void delete(String... identifiers); @Override GroupManagerSettings getSettings(); @Override void assignUsers(String name,
                            Collection<String> users); @Override void destroy();  }
@Test public void testAssignUsers() { final Collection<String> users = new ArrayList<String>(); users.add("user0"); UserResource user0Resource = userResources.get(0); RoleMappingResource roleMappingResource = user0Resource.roles(); RoleScopeResource roleScopeResource = roleMappingResource.realmLevel(); groupsManager.assignUsers("role0", users); ArgumentCaptor<List> rolesCaptor = ArgumentCaptor.forClass(List.class); verify(roleScopeResource, times(1)).add(rolesCaptor.capture()); List rolesAdded = rolesCaptor.getValue(); assertEquals(1, rolesAdded.size()); }