Search in sources :

Example 1 with LdapUserResponse

use of com.cloud.api.response.LdapUserResponse in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    List<LdapUser> users;
    try {
        if (StringUtils.isNotBlank(groupName)) {
            users = _ldapManager.getUsersInGroup(groupName);
        } else {
            users = _ldapManager.getUsers();
        }
    } catch (final NoLdapUserMatchingQueryException ex) {
        users = new ArrayList<>();
        s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage());
    }
    final List<LdapUser> addedUsers = new ArrayList<>();
    for (final LdapUser user : users) {
        final Domain domain = getDomain(user);
        try {
            createCloudstackUserAccount(user, getAccountName(user), domain);
            addedUsers.add(user);
        } catch (final InvalidParameterValueException ex) {
            s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage());
        }
    }
    final ListResponse<LdapUserResponse> response = new ListResponse<>();
    response.setResponses(createLdapUserResponse(addedUsers));
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 2 with LdapUserResponse

use of com.cloud.api.response.LdapUserResponse in project cosmic by MissionCriticalCloud.

the class LdapUserSearchCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapUserResponses = new ArrayList<>();
    if (users != null) {
        for (final LdapUser user : users) {
            final LdapUserResponse ldapUserResponse = _ldapManager.createLdapUserResponse(user);
            ldapUserResponse.setObjectName("LdapUser");
            ldapUserResponses.add(ldapUserResponse);
        }
    }
    return ldapUserResponses;
}
Also used : LdapUser(com.cloud.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 3 with LdapUserResponse

use of com.cloud.api.response.LdapUserResponse in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapResponses = new ArrayList<>();
    for (final LdapUser user : users) {
        final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
        ldapResponse.setObjectName("LdapUser");
        ldapResponses.add(ldapResponse);
    }
    return ldapResponses;
}
Also used : LdapUser(com.cloud.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 4 with LdapUserResponse

use of com.cloud.api.response.LdapUserResponse in project cosmic by MissionCriticalCloud.

the class LdapListUsersCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapResponses = new ArrayList<>();
    for (final LdapUser user : users) {
        if (getListType().equals("all") || !isACloudstackUser(user)) {
            final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
            ldapResponse.setObjectName("LdapUser");
            ldapResponses.add(ldapResponse);
        }
    }
    return ldapResponses;
}
Also used : LdapUser(com.cloud.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 5 with LdapUserResponse

use of com.cloud.api.response.LdapUserResponse in project cosmic by MissionCriticalCloud.

the class LdapManagerImpl method createLdapUserResponse.

@Override
public LdapUserResponse createLdapUserResponse(final LdapUser user) {
    final LdapUserResponse response = new LdapUserResponse();
    response.setUsername(user.getUsername());
    response.setFirstname(user.getFirstname());
    response.setLastname(user.getLastname());
    response.setEmail(user.getEmail());
    response.setPrincipal(user.getPrincipal());
    response.setDomain(user.getDomain());
    return response;
}
Also used : LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Aggregations

LdapUserResponse (com.cloud.api.response.LdapUserResponse)5 LdapUser (com.cloud.ldap.LdapUser)4 ArrayList (java.util.ArrayList)4 ListResponse (com.cloud.api.response.ListResponse)1 Domain (com.cloud.domain.Domain)1 NoLdapUserMatchingQueryException (com.cloud.ldap.NoLdapUserMatchingQueryException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1