use of org.ovirt.engine.core.aaa.DirectoryUser in project ovirt-engine by oVirt.
the class BackendUsersResource method findDirectoryUser.
/**
* Find the directory user that corresponds to the given model.
*
* @param directoryName the name of the directory where to perform the search
* @param user the user model
* @return the requested directory group or {@code null} if no such group exists
*/
private DirectoryUser findDirectoryUser(String directoryName, User user) {
DirectoryUser result = null;
String namespace = user.getNamespace();
if (user.isSetDomainEntryId()) {
result = getUserById(directoryName, namespace, user.getDomainEntryId());
} else if (user.isSetId()) {
result = getUserById(directoryName, namespace, user.getId());
} else if (user.isSetPrincipal()) {
result = getEntity(DirectoryUser.class, QueryType.GetDirectoryUserByPrincipal, new GetDirectoryUserByPrincipalParameters(directoryName, user.getPrincipal()), user.getPrincipal());
} else if (user.isSetUserName()) {
result = getEntity(DirectoryUser.class, SearchType.DirectoryUser, getDirectoryUserSearchPattern(AuthzUtils.getEntityNameWithoutAuthz(user.getUserName(), directoryName), user.getNamespace(), directoryName));
}
return result;
}
use of org.ovirt.engine.core.aaa.DirectoryUser in project ovirt-engine by oVirt.
the class BackendUsersResource method add.
@Override
public Response add(User user) {
validateParameters(user, "userName");
List<String> authzProvidersNames = getBackendCollection(String.class, QueryType.GetDomainList, new QueryParametersBase());
if (AuthzUtils.getAuthzNameFromEntityName(user.getUserName(), authzProvidersNames) == null) {
// user-name may contain the domain (e.g: oliel@xxx.yyy)
validateParameters(user, "domain.id|name");
}
String domain = getAuthzProviderName(user, authzProvidersNames);
DirectoryUser directoryUser = findDirectoryUser(domain, user);
if (directoryUser == null) {
return Response.status(Status.BAD_REQUEST).entity("No such user: " + user.getUserName() + " in domain " + domain).build();
}
AddUserParameters parameters = new AddUserParameters(new DbUser(directoryUser));
QueryIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetDbUserByUserId, IdQueryParameters.class);
return performCreate(ActionType.AddUser, parameters, resolver, BaseResource.class);
}
use of org.ovirt.engine.core.aaa.DirectoryUser in project ovirt-engine by oVirt.
the class SearchQuery method searchDirectoryUsers.
private List<DirectoryUser> searchDirectoryUsers() {
// Parse the query:
QueryData data = initQueryData(true);
if (data == null) {
return Collections.emptyList();
}
List<DirectoryUser> results = new ArrayList<>();
Map<String, Object> response = SsoOAuthServiceUtils.searchUsers(sessionDataContainer.getSsoAccessToken(getParameters().getSessionId()), getParamsMap(data));
if (response.containsKey("result")) {
Collection<ExtMap> users = (Collection<ExtMap>) response.get("result");
results = users.stream().map((ExtMap u) -> directoryUtils.mapPrincipalRecordToDirectoryUser(data.getAuthz(), u)).collect(Collectors.toList());
}
return results;
}
use of org.ovirt.engine.core.aaa.DirectoryUser in project ovirt-engine by oVirt.
the class BackendDomainUsersResource method mapUsers.
private Users mapUsers(List<DirectoryUser> entities) {
Users collection = new Users();
for (DirectoryUser entity : entities) {
User user = map(entity);
user = populate(user, entity);
user = addLinks(user, true);
collection.getUsers().add(user);
}
return collection;
}
use of org.ovirt.engine.core.aaa.DirectoryUser in project ovirt-engine by oVirt.
the class UserMapper method map.
@Mapping(from = DirectoryUser.class, to = User.class)
public static User map(DirectoryUser entity, User template) {
User model = template != null ? template : new User();
model.setName(entity.getFirstName());
model.setUserName(entity.getName() + "@" + entity.getDirectoryName());
model.setId(DirectoryEntryIdUtils.encode(entity.getId()));
model.setLastName(entity.getLastName());
model.setEmail(entity.getEmail());
model.setDepartment(entity.getDepartment());
model.setPrincipal(entity.getPrincipal());
model.setNamespace(entity.getNamespace());
if (entity.getGroups() != null) {
model.setGroups(new Groups());
for (DirectoryGroup directoryGroup : entity.getGroups()) {
Group group = new Group();
group.setName(directoryGroup.getName());
model.getGroups().getGroups().add(group);
}
}
if (!StringUtils.isEmpty(entity.getDirectoryName())) {
Domain dom = new Domain();
dom.setName(entity.getDirectoryName());
dom.setId(DirectoryEntryIdUtils.encode(dom.getName()));
model.setDomain(dom);
}
return model;
}
Aggregations