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();
}
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;
}
Aggregations