Search in sources :

Example 6 with LdapUserResponse

use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.

the class LdapImportUsersCmdTest method successfulResponseFromExecute.

@Test
public void successfulResponseFromExecute() throws Exception {
    List<LdapUser> users = new ArrayList();
    users.add(new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,ou=engineering,dc=cloudstack,dc=org", "engineering", false, null));
    users.add(new LdapUser("bob", "bob@test.com", "Robert", "Young", "cn=bob,ou=engineering,dc=cloudstack,dc=org", "engineering", false, null));
    when(ldapManager.getUsers(null)).thenReturn(users);
    LdapUserResponse response1 = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,ou=engineering,dc=cloudstack,dc=org", "engineering");
    LdapUserResponse response2 = new LdapUserResponse("bob", "bob@test.com", "Robert", "Young", "cn=bob,ou=engineering,dc=cloudstack,dc=org", "engineering");
    when(ldapManager.createLdapUserResponse(any(LdapUser.class))).thenReturn(response1).thenReturn(response2);
    Domain domain = new DomainVO("engineering", 1L, 1L, "engineering", UUID.randomUUID().toString());
    when(domainService.getDomainByName("engineering", 1L)).thenReturn(null, domain);
    when(domainService.createDomain(eq("engineering"), eq(1L), eq("engineering"), anyString())).thenReturn(domain);
    ldapImportUsersCmd.execute();
    ListResponse<LdapUserResponse> resp = (ListResponse<LdapUserResponse>) ldapImportUsersCmd.getResponseObject();
    assertEquals(" when LdapListUsersCmd is executed, a list of size 2 should be returned", 2, resp.getResponses().size());
}
Also used : DomainVO(com.cloud.domain.DomainVO) LdapUser(org.apache.cloudstack.ldap.LdapUser) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse) Test(org.junit.Test)

Example 7 with LdapUserResponse

use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.

the class LdapUserSearchCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapUserResponses = new ArrayList<LdapUserResponse>();
    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(org.apache.cloudstack.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 8 with LdapUserResponse

use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.

the class LdapImportUsersCmd method createLdapUserResponse.

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

Example 9 with LdapUserResponse

use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.

the class LdapListUsersCmd method filterAnyDomain.

/**
 * filter the list of ldap users. no users visible to the caller should be in the returned list
 * @param input ldap response list of users
 * @return a list of ldap users not already in ACS
 */
public List<LdapUserResponse> filterAnyDomain(List<LdapUserResponse> input) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("filtering existing users");
    }
    final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
    for (final LdapUserResponse user : input) {
        if (isNotAlreadyImportedInTheCurrentDomain(user)) {
            ldapResponses.add(user);
        }
    }
    annotateUserListWithSources(ldapResponses);
    return ldapResponses;
}
Also used : ArrayList(java.util.ArrayList) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 10 with LdapUserResponse

use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.

the class LdapListUsersCmd method createLdapUserResponse.

/**
 * (as a check for isACloudstackUser is done) only non cloudstack users should be shown
 * @param users a list of {@code LdapUser}s
 * @return a (filtered?) list of user response objects
 */
private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
    for (final LdapUser user : users) {
        final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
        ldapResponse.setObjectName("LdapUser");
        ldapResponses.add(ldapResponse);
    }
    return ldapResponses;
}
Also used : LdapUser(org.apache.cloudstack.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Aggregations

LdapUserResponse (org.apache.cloudstack.api.response.LdapUserResponse)12 ArrayList (java.util.ArrayList)8 LdapUser (org.apache.cloudstack.ldap.LdapUser)6 ListResponse (org.apache.cloudstack.api.response.ListResponse)3 UserResponse (org.apache.cloudstack.api.response.UserResponse)3 Domain (com.cloud.domain.Domain)2 Test (org.junit.Test)2 DomainVO (com.cloud.domain.DomainVO)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResponseObject (org.apache.cloudstack.api.ResponseObject)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 NoLdapUserMatchingQueryException (org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1