public static GroupRepresentation toGroupHierarchy(GroupModel group, boolean full) { GroupRepresentation rep = toRepresentation(group, full); List<GroupRepresentation> subGroups = new LinkedList<>(); for (GroupModel subGroup : group.getSubGroups()) { subGroups.add(toGroupHierarchy(subGroup, full)); } rep.setSubGroups(subGroups); return rep; }
@Override public Set<GroupModel> getSubGroups() { if (updated != null) return updated.getSubGroups(); Set<GroupModel> subGroups = new HashSet<>(); for (String id : cached.getSubGroups()) { GroupModel subGroup = keycloakSession.realms().getGroupById(id, realm); if (subGroup == null) { // chance that role was removed, so just delegate to persistence and get user invalidated getDelegateForUpdate(); return updated.getSubGroups(); } subGroups.add(subGroup); } return subGroups; }
private static GroupModel findSubGroup(String[] path, int index, GroupModel parent) { for (GroupModel group : parent.getSubGroups()) { if (group.getName().equals(path[index])) { if (path.length == index + 1) { return group; } else { if (index + 1 < path.length) { GroupModel found = findSubGroup(path, index + 1, group); if (found != null) return found; } else { return null; } } } } return null; }
@Override public Set<GroupModel> getSubGroups() { if (isUpdated()) return updated.getSubGroups(); Set<GroupModel> subGroups = new HashSet<>(); for (String id : cached.getSubGroups(modelSupplier)) { GroupModel subGroup = keycloakSession.realms().getGroupById(id, realm); if (subGroup == null) { // chance that role was removed, so just delegate to persistence and get user invalidated getDelegateForUpdate(); return updated.getSubGroups(); } subGroups.add(subGroup); } return subGroups; }
public CachedGroup(Long revision, RealmModel realm, GroupModel group) { super(revision, group.getId()); this.realm = realm.getId(); this.name = group.getName(); this.parentId = group.getParentId(); this.attributes = new DefaultLazyLoader<>(source -> new MultivaluedHashMap<>(source.getAttributes()), MultivaluedHashMap::new); this.roleMappings = new DefaultLazyLoader<>(source -> source.getRoleMappings().stream().map(RoleModel::getId).collect(Collectors.toSet()), Collections::emptySet); this.subGroups = new DefaultLazyLoader<>(source -> source.getSubGroups().stream().map(GroupModel::getId).collect(Collectors.toSet()), Collections::emptySet); }
parent = topLevelGroups.stream().filter(groupModel -> groupModel.getName().equals(part)).findFirst().orElseThrow(() -> new RuntimeException("Top level group with name [" + part + "] not found")); } else { group = parent.getSubGroups().stream().filter(groupModel -> groupModel.getName().equals(part)).findFirst().orElseThrow(() -> new RuntimeException("Group with name [" + part + "] not found")); parent = group;
public CachedGroup(RealmModel realm, GroupModel group) { this.id = group.getId(); this.realm = realm.getId(); this.name = group.getName(); this.parentId = group.getParentId(); this.attributes.putAll(group.getAttributes()); for (RoleModel role : group.getRoleMappings()) { roleMappings.add(role.getId()); } Set<GroupModel> subGroups1 = group.getSubGroups(); if (subGroups1 != null) { for (GroupModel subGroup : subGroups1) { subGroups.add(subGroup.getId()); } } }
for (GroupModel subGroup : group.getSubGroups()) { session.realms().removeGroup(realm, subGroup);
@Override public boolean removeGroup(RealmModel realm, GroupModel group) { session.users().preRemove(realm, group); realm.removeDefaultGroup(group); for (GroupModel subGroup : group.getSubGroups()) { removeGroup(realm, subGroup); } moveGroup(realm, group, null); return getMongoStore().removeEntity(MongoGroupEntity.class, group.getId(), invocationContext); }