查询所有的groups
RealmResource realm =Keycloak.realm("test");
List<GroupRepresentation> groupResourceList =realm.groups().groups();
新增groups
GroupRepresentation groupRepresentation = new GroupRepresentation();
groupRepresentation.setName("测试分组1");
realm.groups().add(groupRepresentation);
修改groups
GroupRepresentation group =groupResourceList.get(0);
GroupRepresentation anotherTopGroup = new GroupRepresentation();
anotherTopGroup.setName("测试");
realm.groups().group(group.getId()).update(anotherTopGroup);
删除groups
realm.groups().group(group.getId()).remove();
用户添加到指定的groups中
List<UserRepresentation> userRepresentationList =realm.users().list();
UserRepresentation userRepresentation =userRepresentationList.get(0);
realm.users().get(userRepresentation.getId()).joinGroup(group.getId());
用户离开当前groups
List<UserRepresentation> userRepresentationList =realm.users().list();
UserRepresentation userRepresentation =userRepresentationList.get(0);
realm.users().get(userRepresentation.getId()).leaveGroup(group.getId());
有可能会帮助到大家!