Java Code Examples for org.keycloak.models.GroupModel#getParentId()

The following examples show how to use org.keycloak.models.GroupModel#getParentId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeycloakModelUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 2
Source File: KeycloakModelUtils.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);

}
 
Example 3
Source File: CachedGroup.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: GroupMovedEvent.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static GroupMovedEvent create(GroupModel group, GroupModel toParent, String realmId) {
    GroupMovedEvent event = new GroupMovedEvent();
    event.realmId = realmId;
    event.groupId = group.getId();
    event.oldParentId = group.getParentId();
    event.newParentId = toParent==null ? null : toParent.getId();
    return event;
}
 
Example 5
Source File: GroupRemovedEvent.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static GroupRemovedEvent create(GroupModel group, String realmId) {
    GroupRemovedEvent event = new GroupRemovedEvent();
    event.realmId = realmId;
    event.groupId = group.getId();
    event.parentId = group.getParentId();
    return event;
}
 
Example 6
Source File: JpaRealmProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: RoleUtils.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private static void addGroupRoles(GroupModel group, Set<RoleModel> roleMappings) {
    roleMappings.addAll(group.getRoleMappings());
    if (group.getParentId() == null) return;
    addGroupRoles(group.getParent(), roleMappings);
}