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;
}
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;
}
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);
}
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());
}
}
}
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;
}
Aggregations