/** * * @param groups * @param targetGroup * @return true if targetGroup is in groups (directly or indirectly via parent child relationship) */ public static boolean isMember(Set<GroupModel> groups, GroupModel targetGroup) { if (groups.contains(targetGroup)) return true; for (GroupModel mapping : groups) { GroupModel child = mapping; while(child.getParent() != null) { if (child.getParent().equals(targetGroup)) return true; child = child.getParent(); } } return false; }
public static List<String> resolveAttribute(GroupModel group, String name) { List<String> values = group.getAttribute(name); if (values != null && !values.isEmpty()) return values; if (group.getParentId() == null) return null; return resolveAttribute(group.getParent(), name); }
public static String resolveFirstAttribute(GroupModel group, String name) { String value = group.getFirstAttribute(name); if (value != null) return value; if (group.getParentId() == null) return null; return resolveFirstAttribute(group.getParent(), name); }
/** * * @param groups * @param targetGroup * @return true if targetGroup is in groups (directly or indirectly via parent child relationship) */ public static boolean isMember(Set<GroupModel> groups, GroupModel targetGroup) { if (groups.contains(targetGroup)) return true; for (GroupModel mapping : groups) { GroupModel child = mapping; while(child.getParent() != null) { if (child.getParent().equals(targetGroup)) return true; child = child.getParent(); } } return false; } // USER FEDERATION RELATED STUFF
private static void addGroupRoles(GroupModel group, Set<RoleModel> roleMappings) { roleMappings.addAll(group.getRoleMappings()); if (group.getParentId() == null) return; addGroupRoles(group.getParent(), roleMappings); }
@Override public void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent) { if (toParent != null && group.getId().equals(toParent.getId())) { return; } if (group.getParentId() != null) { group.getParent().removeChild(group); } group.setParent(toParent); if (toParent != null) toParent.addChild(group); else session.realms().addTopLevelGroup(realm, group); }
@Override public List<GroupModel> getTopLevelGroups() { List<GroupModel> all = getGroups(); Iterator<GroupModel> it = all.iterator(); while (it.hasNext()) { GroupModel group = it.next(); if (group.getParent() != null) { it.remove(); } } return all; }
@Override public void moveGroup(RealmModel realm, GroupModel group, GroupModel toParent) { if (toParent != null && group.getId().equals(toParent.getId())) { return; } if (group.getParentId() != null) { group.getParent().removeChild(group); } group.setParent(toParent); if (toParent != null) toParent.addChild(group); else session.realms().addTopLevelGroup(realm, group); }
/** * Checks whether the {@code targetRole} is contained in the given group or its parents * (if requested) * @param group Group to check role for * @param targetRole * @param checkParentGroup When {@code true}, also parent group is recursively checked for role * @return true if targetRole is in roles (directly or indirectly via composite role) */ public static boolean hasRoleFromGroup(GroupModel group, RoleModel targetRole, boolean checkParentGroup) { if (group.hasRole(targetRole)) return true; if (checkParentGroup) { GroupModel parent = group.getParent(); return parent != null && hasRoleFromGroup(parent, targetRole, true); } return false; }
@Override public GroupModel getParent() { if (updated != null) return updated.getParent(); if (cached.getParentId() == null) return null; return keycloakSession.realms().getGroupById(cached.getParentId(), realm); }
@Override public GroupModel getParent() { if (isUpdated()) return updated.getParent(); if (cached.getParentId() == null) return null; return keycloakSession.realms().getGroupById(cached.getParentId(), realm); }