Search in sources :

Example 16 with DbGroup

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

the class DirectoryUtils method mapPrincipalRecordToDbUser.

public DbUser mapPrincipalRecordToDbUser(String authz, ExtMap principal) {
    principal = principal.clone();
    flatGroups(principal);
    DbUser dbUser = dbUserDao.getByExternalId(authz, principal.get(PrincipalRecord.ID));
    Guid userId = dbUser != null ? dbUser.getId() : Guid.newGuid();
    dbUser = new DbUser(mapPrincipalRecordToDirectoryUser(authz, principal));
    dbUser.setId(userId);
    Set<Guid> groupIds = new HashSet<>();
    Set<String> groupsNames = new HashSet<>();
    for (ExtMap group : principal.<Collection<ExtMap>>get(PrincipalRecord.GROUPS, Collections.<ExtMap>emptyList())) {
        DbGroup dbGroup = dbGroupDao.getByExternalId(authz, group.get(GroupRecord.ID));
        if (dbGroup != null) {
            groupIds.add(dbGroup.getId());
            groupsNames.add(dbGroup.getName());
        }
    }
    dbUser.setGroupIds(groupIds);
    dbUser.setGroupNames(groupsNames);
    return dbUser;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) ExtMap(org.ovirt.engine.api.extensions.ExtMap) Collection(java.util.Collection) Guid(org.ovirt.engine.core.compat.Guid) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 17 with DbGroup

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

the class BackendGroupsResource method mapDbGroupCollection.

private Groups mapDbGroupCollection(List<DbGroup> entities) {
    Groups collection = new Groups();
    for (DbGroup entity : entities) {
        Group group = map(entity);
        group = populate(group, entity);
        group = addLinks(group, BaseResource.class);
        collection.getGroups().add(group);
    }
    return collection;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Group(org.ovirt.engine.api.model.Group) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Groups(org.ovirt.engine.api.model.Groups) BaseResource(org.ovirt.engine.api.model.BaseResource)

Example 18 with DbGroup

use of org.ovirt.engine.core.common.businessentities.aaa.DbGroup 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 19 with DbGroup

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

the class DbGroupDaoTest method testUpdateDoesntChangeExternalId.

/**
 * Ensures that update cycle doesn't change the external identifier.
 */
@Test
public void testUpdateDoesntChangeExternalId() {
    DbGroup groupBefore = dao.get(existingGroup.getId());
    dao.update(groupBefore);
    DbGroup groupAfter = dao.get(existingGroup.getId());
    assertEquals(groupBefore.getExternalId(), groupAfter.getExternalId());
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Test(org.junit.Test)

Example 20 with DbGroup

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

the class DbGroupDaoTest method testGetByExternalId.

/**
 * Ensures that retrieving an group by external id works as expected.
 */
@Test
public void testGetByExternalId() {
    DbGroup result = dao.getByExternalId("rhel", "a");
    assertNotNull(result);
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Test(org.junit.Test)

Aggregations

DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)34 Test (org.junit.Test)13 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)10 Guid (org.ovirt.engine.core.compat.Guid)9 ArrayList (java.util.ArrayList)6 Group (org.ovirt.engine.api.model.Group)6 DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)6 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)5 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)5 Permission (org.ovirt.engine.core.common.businessentities.Permission)5 Response (javax.ws.rs.core.Response)3 Domain (org.ovirt.engine.api.model.Domain)3 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)3 Role (org.ovirt.engine.core.common.businessentities.Role)3 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)3 AdElementListModel (org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExtMap (org.ovirt.engine.api.extensions.ExtMap)2