Search in sources :

Example 1 with DirectoryUser

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;
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) GetDirectoryUserByPrincipalParameters(org.ovirt.engine.core.common.queries.GetDirectoryUserByPrincipalParameters)

Example 2 with DirectoryUser

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);
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Guid(org.ovirt.engine.core.compat.Guid) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 3 with DirectoryUser

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;
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) ExtMap(org.ovirt.engine.api.extensions.ExtMap) QueryData(org.ovirt.engine.core.aaa.QueryData) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 4 with DirectoryUser

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;
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) User(org.ovirt.engine.api.model.User) Users(org.ovirt.engine.api.model.Users)

Example 5 with DirectoryUser

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;
}
Also used : Group(org.ovirt.engine.api.model.Group) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) User(org.ovirt.engine.api.model.User) DirectoryGroup(org.ovirt.engine.core.aaa.DirectoryGroup) Groups(org.ovirt.engine.api.model.Groups) Domain(org.ovirt.engine.api.model.Domain)

Aggregations

DirectoryUser (org.ovirt.engine.core.aaa.DirectoryUser)8 ArrayList (java.util.ArrayList)3 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)3 ExtMap (org.ovirt.engine.api.extensions.ExtMap)2 User (org.ovirt.engine.api.model.User)2 DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)2 Collection (java.util.Collection)1 List (java.util.List)1 Domain (org.ovirt.engine.api.model.Domain)1 Group (org.ovirt.engine.api.model.Group)1 Groups (org.ovirt.engine.api.model.Groups)1 Users (org.ovirt.engine.api.model.Users)1 QueryData (org.ovirt.engine.core.aaa.QueryData)1 AddUserParameters (org.ovirt.engine.core.common.action.AddUserParameters)1 Queryable (org.ovirt.engine.core.common.businessentities.Queryable)1 DirectoryIdQueryParameters (org.ovirt.engine.core.common.queries.DirectoryIdQueryParameters)1 GetDirectoryUserByPrincipalParameters (org.ovirt.engine.core.common.queries.GetDirectoryUserByPrincipalParameters)1 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)1 Guid (org.ovirt.engine.core.compat.Guid)1 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)1