Search in sources :

Example 31 with DbGroup

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

the class GroupMapper method map.

@Mapping(from = Group.class, to = DbGroup.class)
public static DbGroup map(Group model, DbGroup template) {
    DbGroup entity = template != null ? template : new DbGroup();
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetId()) {
        String id = model.getId();
        entity.setId(GuidUtils.asGuid(id));
    }
    if (model.isSetDomain()) {
        Domain domain = model.getDomain();
        if (domain.isSetName()) {
            entity.setDomain(domain.getName());
        }
    }
    if (model.isSetDomainEntryId()) {
        entity.setExternalId(DirectoryEntryIdUtils.decode(model.getDomainEntryId()));
    }
    if (model.isSetNamespace()) {
        entity.setNamespace(model.getNamespace());
    }
    return entity;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Domain(org.ovirt.engine.api.model.Domain)

Example 32 with DbGroup

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

the class CreateUserSessionCommand method buildUser.

private DbUser buildUser(T params, String authzName) {
    DbUser dbUser = dbUserDao.getByExternalId(authzName, params.getPrincipalId());
    DbUser user = new DbUser(dbUser);
    user.setId(dbUser == null ? Guid.newGuid() : dbUser.getId());
    user.setExternalId(params.getPrincipalId());
    user.setDomain(authzName);
    user.setEmail(params.getEmail());
    user.setFirstName(params.getFirstName());
    user.setLastName(params.getLastName());
    user.setNamespace(params.getNamespace());
    user.setLoginName(params.getPrincipalName());
    List<Guid> groupIds = new ArrayList<>();
    Map<String, ExtMap> groupRecords = new HashMap<>();
    flatGroups((Collection<ExtMap>) params.getGroupIds(), groupRecords);
    for (Map.Entry<String, ExtMap> group : groupRecords.entrySet()) {
        DbGroup dbGroup = dbGroupDao.getByExternalId(authzName, group.getKey());
        if (dbGroup != null) {
            dbGroup.setName(group.getValue().get(Authz.GroupRecord.NAME));
            dbGroupDao.update(dbGroup);
            groupIds.add(dbGroup.getId());
        }
    }
    user.setGroupIds(groupIds);
    user.setAdmin(!roleDao.getAnyAdminRoleForUserAndGroups(user.getId(), StringUtils.join(user.getGroupIds(), ",")).isEmpty());
    if (dbUser == null) {
        dbUserDao.save(user);
    } else if (!dbUser.equals(user)) {
        dbUserDao.update(user);
    }
    return user;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) ExtMap(org.ovirt.engine.api.extensions.ExtMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map) ExtMap(org.ovirt.engine.api.extensions.ExtMap) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 33 with DbGroup

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

the class AttachUserGroupToTagCommand method executeCommand.

@Override
protected void executeCommand() {
    if (getTagId() != null) {
        for (Guid groupGuid : getGroupList()) {
            DbGroup group = dbGroupDao.get(groupGuid);
            if (tagDao.getTagUserGroupByGroupIdAndByTagId(getTagId(), groupGuid) == null) {
                TagsUserGroupMap map = new TagsUserGroupMap(groupGuid, getTagId());
                tagDao.attachUserGroupToTag(map);
                noActionDone = false;
                if (group != null) {
                    appendCustomCommaSeparatedValue("AttachGroupsNames", group.getName());
                }
            } else {
                if (group != null) {
                    appendCustomCommaSeparatedValue("AttachGroupsNamesExists", group.getName());
                }
            }
        }
        setSucceeded(true);
    }
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) TagsUserGroupMap(org.ovirt.engine.core.common.businessentities.TagsUserGroupMap) Guid(org.ovirt.engine.core.compat.Guid)

Example 34 with DbGroup

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

the class AddPermissionCommand method executeCommand.

@Override
protected void executeCommand() {
    // Get the parameters:
    T parameters = getParameters();
    // The user or group given in the parameters may haven't been added to the database yet, if this is the case
    // then they need to be added to the database now, before the permission:
    DbUser user = parameters.getUser();
    if (user != null) {
        Guid id = user.getId();
        String directory = user.getDomain();
        String externalId = user.getExternalId();
        DbUser existing = dbUserDao.getByIdOrExternalId(id, directory, externalId);
        if (existing != null) {
            user = existing;
        } else {
            user = addUser(user);
            if (user == null) {
                setSucceeded(false);
                return;
            }
        }
    }
    DbGroup group = parameters.getGroup();
    if (group != null) {
        Guid id = group.getId();
        String directory = group.getDomain();
        String externalId = group.getExternalId();
        DbGroup existing = dbGroupDao.getByIdOrExternalId(id, directory, externalId);
        if (existing != null) {
            group = existing;
        } else {
            group = addGroup(group);
            if (group == null) {
                setSucceeded(false);
                return;
            }
        }
    }
    // The identifier of the principal of the permission can come from the parameters directly or from the
    // user/group objects:
    Guid principalId;
    if (user != null) {
        principalId = user.getId();
    } else if (group != null) {
        principalId = group.getId();
    } else {
        principalId = parameters.getPermission().getAdElementId();
    }
    final Permission paramPermission = parameters.getPermission();
    Permission permission = permissionDao.getForRoleAndAdElementAndObject(paramPermission.getRoleId(), principalId, paramPermission.getObjectId());
    if (permission == null) {
        paramPermission.setAdElementId(principalId);
        TransactionSupport.executeInNewTransaction(() -> {
            permissionDao.save(paramPermission);
            getCompensationContext().snapshotNewEntity(paramPermission);
            getCompensationContext().stateChanged();
            return null;
        });
        permission = paramPermission;
    }
    getReturnValue().setActionReturnValue(permission.getId());
    if (user != null) {
        updateAdminStatus(permission);
    }
    vmStaticDao.incrementDbGeneration(paramPermission.getObjectId());
    setSucceeded(true);
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Permission(org.ovirt.engine.core.common.businessentities.Permission) Guid(org.ovirt.engine.core.compat.Guid) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

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