Search in sources :

Example 1 with AuthzGroup

use of org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup in project ovirt-engine by oVirt.

the class GetAuthzGroupsByUserIdQuery method getDirectoryUser.

private Collection<AuthzGroup> getDirectoryUser(DbUser dbUser) {
    Collection<AuthzGroup> groups = new ArrayList<>();
    if (dbUser != null) {
        Map<String, Object> response = SsoOAuthServiceUtils.findPrincipalsByIds(getSessionDataContainer().getSsoAccessToken(getParameters().getSessionId()), dbUser.getDomain(), dbUser.getNamespace(), Arrays.asList(dbUser.getExternalId()), true, true);
        Collection<ExtMap> principalRecords = Collections.emptyList();
        if (response.containsKey("result")) {
            principalRecords = (Collection<ExtMap>) response.get("result");
        }
        if (!principalRecords.isEmpty()) {
            ExtMap principalRecord = principalRecords.iterator().next();
            directoryUtils.flatGroups(principalRecord);
            for (ExtMap group : principalRecord.<Collection<ExtMap>>get(PrincipalRecord.GROUPS, Collections.<ExtMap>emptyList())) {
                groups.add(new AuthzGroup(dbUser.getDomain(), group.get(GroupRecord.NAMESPACE), group.get(GroupRecord.NAME), group.get(GroupRecord.ID)));
            }
        }
    }
    return groups;
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) AuthzGroup(org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 2 with AuthzGroup

use of org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup in project ovirt-engine by oVirt.

the class GetPermissionsOnBehalfByAdElementIdQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    QueryReturnValue returnValue = Backend.getInstance().runInternalQuery(QueryType.GetAuthzGroupsByUserId, getParameters());
    Collection<AuthzGroup> authzGroups = returnValue.getReturnValue();
    List<Guid> groupsIds = authzGroups.stream().map(g -> dbGroupDao.getByExternalId(g.getAuthz(), g.getId())).filter(Objects::nonNull).map(g -> g.getId()).collect(Collectors.toList());
    getQueryReturnValue().setReturnValue(permissionDao.getAllForAdElementAndGroups(getParameters().getId(), getUserID(), groupsIds, getParameters().isFiltered()));
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Guid(org.ovirt.engine.core.compat.Guid) Collection(java.util.Collection) DbGroupDao(org.ovirt.engine.core.dao.DbGroupDao) Collectors(java.util.stream.Collectors) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) AuthzGroup(org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup) DbUserDao(org.ovirt.engine.core.dao.DbUserDao) Objects(java.util.Objects) Inject(javax.inject.Inject) List(java.util.List) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) AuthzGroup(org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup) Objects(java.util.Objects) Guid(org.ovirt.engine.core.compat.Guid)

Example 3 with AuthzGroup

use of org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup in project ovirt-engine by oVirt.

the class BackendDomainUserGroupsResource method mapGroups.

private Groups mapGroups(List<AuthzGroup> authzGroups) {
    Groups groups = new Groups();
    groups.getGroups().addAll(authzGroups.stream().map(g -> map(g)).map(g -> addLinks(g)).collect(Collectors.toList()));
    return groups;
}
Also used : Group(org.ovirt.engine.api.model.Group) QueryType(org.ovirt.engine.core.common.queries.QueryType) List(java.util.List) Groups(org.ovirt.engine.api.model.Groups) Guid(org.ovirt.engine.core.compat.Guid) Collectors(java.util.stream.Collectors) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) DomainUserGroupsResource(org.ovirt.engine.api.resource.aaa.DomainUserGroupsResource) AbstractBackendCollectionResource(org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource) AuthzGroup(org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup) Groups(org.ovirt.engine.api.model.Groups)

Example 4 with AuthzGroup

use of org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup in project ovirt-engine by oVirt.

the class GroupMapper method map.

@Mapping(from = AuthzGroup.class, to = Group.class)
public static Group map(AuthzGroup authzGroup, Group template) {
    Group model = template != null ? template : new Group();
    model.setId(DirectoryEntryIdUtils.encode(authzGroup.getId()));
    model.setName(authzGroup.getName());
    model.setNamespace(authzGroup.getNamespace());
    if (!StringUtils.isEmpty(authzGroup.getAuthz())) {
        Domain dom = new Domain();
        dom.setName(authzGroup.getAuthz());
        dom.setId(DirectoryEntryIdUtils.encode(dom.getName()));
        model.setDomain(dom);
    }
    return model;
}
Also used : Group(org.ovirt.engine.api.model.Group) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) AuthzGroup(org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup) Domain(org.ovirt.engine.api.model.Domain)

Aggregations

AuthzGroup (org.ovirt.engine.core.common.businessentities.aaa.AuthzGroup)4 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Group (org.ovirt.engine.api.model.Group)2 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)2 QueryType (org.ovirt.engine.core.common.queries.QueryType)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 Inject (javax.inject.Inject)1 ExtMap (org.ovirt.engine.api.extensions.ExtMap)1 Domain (org.ovirt.engine.api.model.Domain)1 Groups (org.ovirt.engine.api.model.Groups)1 DomainUserGroupsResource (org.ovirt.engine.api.resource.aaa.DomainUserGroupsResource)1 AbstractBackendCollectionResource (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResource)1 DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)1 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)1 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1