Search in sources :

Example 71 with GroupModel

use of org.keycloak.models.GroupModel in project keycloak by keycloak.

the class MapGroupProvider method searchForGroupByNameStream.

@Override
public Stream<GroupModel> searchForGroupByNameStream(RealmModel realm, String search, Integer firstResult, Integer maxResults) {
    LOG.tracef("searchForGroupByNameStream(%s, %s, %d, %d)%s", realm, search, firstResult, maxResults, getShortStackTrace());
    DefaultModelCriteria<GroupModel> mcb = criteria();
    mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId()).compare(SearchableFields.NAME, Operator.ILIKE, "%" + search + "%");
    return tx.read(withCriteria(mcb).pagination(firstResult, maxResults, SearchableFields.NAME)).map(MapGroupEntity::getId).map(id -> {
        GroupModel groupById = session.groups().getGroupById(realm, id);
        while (Objects.nonNull(groupById.getParentId())) {
            groupById = session.groups().getGroupById(realm, groupById.getParentId());
        }
        return groupById;
    }).sorted(GroupModel.COMPARE_BY_NAME).distinct();
}
Also used : GroupModel(org.keycloak.models.GroupModel)

Example 72 with GroupModel

use of org.keycloak.models.GroupModel in project keycloak by keycloak.

the class UserMapStorage method createUser.

private UserModel createUser(RealmModel realm, String username) {
    UserModel user;
    if (isImportEnabled()) {
        user = session.userLocalStorage().addUser(realm, username);
        user.setEnabled(true);
        user.setFederationLink(model.getId());
    } else {
        user = new AbstractUserAdapterFederatedStorage.Streams(session, realm, model) {

            @Override
            public String getUsername() {
                return username.toLowerCase();
            }

            @Override
            public void setUsername(String innerUsername) {
                if (!Objects.equals(innerUsername, username.toLowerCase())) {
                    throw new RuntimeException("Unsupported");
                }
            }

            @Override
            public void leaveGroup(GroupModel group) {
                UserMapStorage.this.leaveGroup(realm, getUsername(), group);
            }

            @Override
            public void joinGroup(GroupModel group) {
                UserMapStorage.this.joinGroup(realm, getUsername(), group);
            }

            @Override
            public String getFederationLink() {
                return model.getId();
            }
        };
    }
    return user;
}
Also used : UserModel(org.keycloak.models.UserModel) GroupModel(org.keycloak.models.GroupModel) AbstractUserAdapterFederatedStorage(org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage)

Aggregations

GroupModel (org.keycloak.models.GroupModel)72 RealmModel (org.keycloak.models.RealmModel)40 Test (org.junit.Test)26 ComponentModel (org.keycloak.component.ComponentModel)23 UserModel (org.keycloak.models.UserModel)20 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)18 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)13 GroupLDAPStorageMapper (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapper)12 RoleModel (org.keycloak.models.RoleModel)10 ClientModel (org.keycloak.models.ClientModel)9 GroupLDAPStorageMapperFactory (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapperFactory)9 HashMap (java.util.HashMap)8 List (java.util.List)8 NotFoundException (javax.ws.rs.NotFoundException)7 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)7 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 Path (javax.ws.rs.Path)6 Policy (org.keycloak.authorization.model.Policy)6