Search in sources :

Example 1 with DirectoryGroup

use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.

the class AdElementListModel method addGroupsToModel.

protected void addGroupsToModel(QueryReturnValue returnValue, Set<String> excludeUsers) {
    for (Queryable item : (Collection<Queryable>) returnValue.getReturnValue()) {
        DirectoryGroup a = (DirectoryGroup) item;
        if (!excludeUsers.contains(a.getId())) {
            // TODO: This is a hack, we should either use DbGroup or reimplement user/group representation in GWT
            DbUser group = new DbUser();
            group.setExternalId(a.getId());
            group.setFirstName(a.getName());
            // $NON-NLS-1$
            group.setLastName("");
            // TODO: Due to group -> DbUser mapping hack we have to use note to represent display name of group
            group.setNote(a.getDisplayName());
            group.setDomain(a.getDirectoryName());
            group.setNamespace(a.getNamespace());
            EntityModel<DbUser> groupEntity = new EntityModel<>();
            groupEntity.setEntity(group);
            getgroups().add(groupEntity);
        }
    }
}
Also used : DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Queryable(org.ovirt.engine.core.common.businessentities.Queryable) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Collection(java.util.Collection) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 2 with DirectoryGroup

use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.

the class SearchQuery method searchDirectoryGroups.

private List<DirectoryGroup> searchDirectoryGroups() {
    // Parse the query:
    QueryData data = initQueryData(true);
    if (data == null) {
        return Collections.emptyList();
    }
    List<DirectoryGroup> results = new ArrayList<>();
    Map<String, Object> response = SsoOAuthServiceUtils.searchGroups(sessionDataContainer.getSsoAccessToken(getParameters().getSessionId()), getParamsMap(data));
    if (response.containsKey("result")) {
        Collection<ExtMap> groups = (Collection<ExtMap>) response.get("result");
        results = groups.stream().map((ExtMap g) -> directoryUtils.mapGroupRecordToDirectoryGroup(data.getAuthz(), g)).collect(Collectors.toList());
    }
    return results;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) QueryData(org.ovirt.engine.core.aaa.QueryData) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 3 with DirectoryGroup

use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.

the class DirectoryUtils method mapGroupRecordToDirectoryGroup.

private DirectoryGroup mapGroupRecordToDirectoryGroup(final String authzName, final ExtMap group, final Set<String> loopPrevention) {
    DirectoryGroup directoryGroup = null;
    if (group != null) {
        directoryGroup = new DirectoryGroup(authzName, group.get(Authz.GroupRecord.NAMESPACE), group.get(Authz.GroupRecord.ID), group.get(Authz.GroupRecord.NAME), group.get(Authz.GroupRecord.DISPLAY_NAME));
        loopPrevention.add(directoryGroup.getId());
        for (ExtMap memberOf : group.<Collection<ExtMap>>get(Authz.GroupRecord.GROUPS, Collections.<ExtMap>emptyList())) {
            if (!loopPrevention.contains(memberOf.<String>get(GroupRecord.ID))) {
                directoryGroup.getGroups().add(mapGroupRecordToDirectoryGroup(authzName, memberOf, loopPrevention));
            }
        }
    }
    return directoryGroup;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Collection(java.util.Collection)

Example 4 with DirectoryGroup

use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.

the class BackendGroupsResource method add.

@Override
public Response add(Group group) {
    List<String> authzProvidersNames = getBackendCollection(String.class, QueryType.GetDomainList, new QueryParametersBase());
    validateParameters(group, "name");
    if (AuthzUtils.getAuthzNameFromEntityName(group.getName(), authzProvidersNames) == null) {
        validateParameters(group, "domain.id|name");
    }
    String directoryName = getAuthzProviderName(group, authzProvidersNames);
    DirectoryGroup directoryGroup = findDirectoryGroup(directoryName, group);
    if (directoryGroup == null) {
        return Response.status(Status.BAD_REQUEST).entity("No such group: " + group.getName() + " in directory " + directoryName).build();
    }
    AddGroupParameters parameters = new AddGroupParameters();
    parameters.setGroupToAdd(new DbGroup(directoryGroup));
    QueryIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetDbGroupById, IdQueryParameters.class);
    return performCreate(ActionType.AddGroup, parameters, resolver, BaseResource.class);
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Guid(org.ovirt.engine.core.compat.Guid) AddGroupParameters(org.ovirt.engine.core.common.action.AddGroupParameters)

Example 5 with DirectoryGroup

use of org.ovirt.engine.core.aaa.DirectoryGroup in project ovirt-engine by oVirt.

the class UserMapper method map.

@Mapping(from = DirectoryUser.class, to = User.class)
public static User map(DirectoryUser entity, User template) {
    User model = template != null ? template : new User();
    model.setName(entity.getFirstName());
    model.setUserName(entity.getName() + "@" + entity.getDirectoryName());
    model.setId(DirectoryEntryIdUtils.encode(entity.getId()));
    model.setLastName(entity.getLastName());
    model.setEmail(entity.getEmail());
    model.setDepartment(entity.getDepartment());
    model.setPrincipal(entity.getPrincipal());
    model.setNamespace(entity.getNamespace());
    if (entity.getGroups() != null) {
        model.setGroups(new Groups());
        for (DirectoryGroup directoryGroup : entity.getGroups()) {
            Group group = new Group();
            group.setName(directoryGroup.getName());
            model.getGroups().getGroups().add(group);
        }
    }
    if (!StringUtils.isEmpty(entity.getDirectoryName())) {
        Domain dom = new Domain();
        dom.setName(entity.getDirectoryName());
        dom.setId(DirectoryEntryIdUtils.encode(dom.getName()));
        model.setDomain(dom);
    }
    return model;
}
Also used : Group(org.ovirt.engine.api.model.Group) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) User(org.ovirt.engine.api.model.User) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Groups(org.ovirt.engine.api.model.Groups) Domain(org.ovirt.engine.api.model.Domain)

Aggregations

DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)9 Collection (java.util.Collection)4 ExtMap (org.ovirt.engine.api.extensions.ExtMap)4 ArrayList (java.util.ArrayList)3 Group (org.ovirt.engine.api.model.Group)3 Domain (org.ovirt.engine.api.model.Domain)2 Groups (org.ovirt.engine.api.model.Groups)2 DirectoryUser (org.ovirt.engine.core.aaa.DirectoryUser)2 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)2 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 User (org.ovirt.engine.api.model.User)1 QueryData (org.ovirt.engine.core.aaa.QueryData)1 AddGroupParameters (org.ovirt.engine.core.common.action.AddGroupParameters)1 Queryable (org.ovirt.engine.core.common.businessentities.Queryable)1 AuthzGroup (org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup)1 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)1 Guid (org.ovirt.engine.core.compat.Guid)1 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)1