Search in sources :

Example 81 with DbUser

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

the class BackendAssignedPermissionsResource method getPrincipal.

/**
 * Find the user or group that the permissions applies to.
 *
 * @param permission the incoming permission model
 * @return the user or group that the permission applies to
 */
private Object getPrincipal(Permission permission) {
    if (isUserSubCollection()) {
        DbUser dbUser = new DbUser();
        dbUser.setId(targetId);
        return dbUser;
    }
    if (isGroupSubCollection()) {
        DbGroup dbGroup = new DbGroup();
        dbGroup.setId(targetId);
        return dbGroup;
    }
    if (permission.isSetUser()) {
        User user = permission.getUser();
        DbUser dbUser = UserMapper.map(user, null);
        if (dbUser.getDomain() == null) {
            dbUser.setDomain(getCurrent().getUser().getDomain());
        }
        return dbUser;
    }
    if (permission.isSetGroup()) {
        Group group = permission.getGroup();
        DbGroup dbGroup = GroupMapper.map(group, null);
        if (dbGroup.getDomain() == null) {
            dbGroup.setDomain(getCurrent().getUser().getDomain());
        }
        return dbGroup;
    }
    return null;
}
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) User(org.ovirt.engine.api.model.User) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 82 with DbUser

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

the class BackendAssignedPermissionsResource method getParameters.

/**
 * Create the parameters for the permissions operation.
 *
 * @param model the incoming permission
 * @return the parameters for the operation
 */
private PermissionsOperationsParameters getParameters(Permission model) {
    org.ovirt.engine.core.common.businessentities.Permission entity = map(model, null);
    if (!isPrincipalSubCollection()) {
        entity.setObjectId(targetId);
        entity.setObjectType(objectType);
    }
    PermissionsOperationsParameters parameters = new PermissionsOperationsParameters();
    parameters.setPermission(entity);
    Object principal = getPrincipal(model);
    if (principal instanceof DbUser) {
        DbUser user = (DbUser) principal;
        entity.setAdElementId(user.getId());
        parameters.setUser(user);
    }
    if (principal instanceof DbGroup) {
        DbGroup group = (DbGroup) principal;
        entity.setAdElementId(group.getId());
        parameters.setGroup(group);
    }
    return parameters;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 83 with DbUser

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

the class OvfOvirtReader method readUserDomainsSection.

protected void readUserDomainsSection(@SuppressWarnings("unused") XmlNode section) {
    XmlNodeList list = selectNodes(section, OvfProperties.USER);
    Set<DbUser> dbUsers = new HashSet<>();
    Map<String, Set<String>> userToRoles = new HashMap<>();
    for (XmlNode node : list) {
        String userDomain = selectSingleNode(node, OvfProperties.USER_DOMAIN, _xmlNS).innerText;
        DbUser dbUser = new DbUser();
        dbUser.setLoginName(userDomain.split("@")[0]);
        dbUser.setDomain(userDomain.split("@")[1]);
        dbUsers.add(dbUser);
        XmlNode rolesElement = selectSingleNode(node, OvfProperties.USER_ROLES);
        XmlNodeList roleNodes = selectNodes(rolesElement, OvfProperties.ROLE_NAME);
        Set<String> roleNames = new HashSet<>();
        for (XmlNode roleNode : roleNodes) {
            String roleName = roleNode.innerText;
            roleNames.add(roleName);
        }
        userToRoles.put(dbUser.getLoginName(), roleNames);
    }
    fullEntityOvfData.setDbUsers(dbUsers);
    fullEntityOvfData.setUserToRoles(userToRoles);
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 84 with DbUser

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

the class BackendVmSessionsResource method setSessionUser.

/**
 * The console user, if exists, is a real ovirt-user. Use its name to get ID and href information, and set them
 * inside the user object, inside the session. If user is not found in database, those information won't be set.
 */
private void setSessionUser(Session session) {
    // Get the user entity and don't fail if user is not found in database:
    DbUser entity = getEntity(DbUser.class, QueryType.GetDbUserByUserNameAndDomain, new GetDbUserByUserNameAndDomainQueryParameters(session.getUser().getUserName(), session.getUser().getDomain().getName()), "", false, false);
    // Map the database user to model user:
    if (entity != null) {
        User user = BackendApiResource.getInstance().getUsersResource().getUserResource(entity.getId().toString()).get();
        /**
         * TODO: It's enough to set user ID and href, we don't have to set also domain, please consider this
         * when moving to API version 5.
         */
        if (user != null) {
            session.getUser().setId(user.getId());
            session.getUser().setHref(user.getHref());
            session.getUser().getDomain().setId(user.getDomain().getId());
            session.getUser().getDomain().setHref(user.getDomain().getHref());
        }
    }
}
Also used : DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) User(org.ovirt.engine.api.model.User) GetDbUserByUserNameAndDomainQueryParameters(org.ovirt.engine.core.common.queries.GetDbUserByUserNameAndDomainQueryParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 85 with DbUser

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

the class BackendUsersResource method mapDbUserCollection.

protected Users mapDbUserCollection(List<DbUser> entities) {
    Users collection = new Users();
    for (DbUser entity : entities) {
        User user = map(entity);
        user = populate(user, entity);
        user = addLinks(user, BaseResource.class);
        collection.getUsers().add(user);
    }
    return collection;
}
Also used : User(org.ovirt.engine.api.model.User) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) BaseResource(org.ovirt.engine.api.model.BaseResource) Users(org.ovirt.engine.api.model.Users) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)109 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)18 Guid (org.ovirt.engine.core.compat.Guid)18 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)13 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)10 HashSet (java.util.HashSet)9 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)9 HashMap (java.util.HashMap)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)8 Collection (java.util.Collection)7 Before (org.junit.Before)7 Permission (org.ovirt.engine.core.common.businessentities.Permission)7 List (java.util.List)5 Map (java.util.Map)5 AttachEntityToTagParameters (org.ovirt.engine.core.common.action.AttachEntityToTagParameters)5 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)5 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)5 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)5 TagListModel (org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel)5