Search in sources :

Example 16 with UserResponse

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

the class LdapListUsersCmdTest method mockACSUserSearch.

private void mockACSUserSearch() {
    UserResponse rmurphy = createMockUserResponse("rmurphy", User.Source.NATIVE);
    UserResponse rohit = createMockUserResponse("rohit", User.Source.SAML2);
    UserResponse abhi = createMockUserResponse("abhi", User.Source.LDAP);
    ArrayList<UserResponse> responses = new ArrayList<>();
    responses.add(rmurphy);
    responses.add(rohit);
    responses.add(abhi);
    ListResponse<UserResponse> queryServiceResponse = new ListResponse<>();
    queryServiceResponse.setResponses(responses);
    doReturn(queryServiceResponse).when(queryService).searchForUsers(nullable(Long.class), nullable(Boolean.class));
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList)

Example 17 with UserResponse

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

the class LdapListUsersCmdTest method createMockUserResponse.

private UserResponse createMockUserResponse(String uid, User.Source source) {
    UserResponse userResponse = new UserResponse();
    userResponse.setUsername(uid);
    userResponse.setUserSource(source);
    // for now:
    userResponse.setDomainId(LOCAL_DOMAIN_ID);
    userResponse.setDomainName(LOCAL_DOMAIN_NAME);
    return userResponse;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 18 with UserResponse

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

the class LdapListUsersCmd method traceUserList.

private void traceUserList() {
    if (s_logger.isTraceEnabled()) {
        StringBuilder users = new StringBuilder();
        for (UserResponse user : cloudstackUsers) {
            if (users.length() > 0) {
                users.append(", ");
            }
            users.append(user.getUsername());
        }
        s_logger.trace(String.format("checking against %d cloudstackusers: %s.", this.cloudstackUsers.size(), users.toString()));
    }
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 19 with UserResponse

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

the class LdapListUsersCmd method filterLocalDomain.

/**
 * filter the list of ldap users. no users visible to the caller already in the domain specified 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> filterLocalDomain(List<LdapUserResponse> input) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("filtering local domain users");
    }
    final List<LdapUserResponse> ldapResponses = new ArrayList<LdapUserResponse>();
    String domainId = getCurrentDomainId();
    for (final LdapUserResponse user : input) {
        UserResponse cloudstackUser = getCloudstackUser(user);
        if (cloudstackUser == null || /*doesn't exist in cloudstack*/
        !domainId.equals(cloudstackUser.getDomainId()) || /* doesn't exist in this domain */
        !cloudstackUser.getUserSource().equalsIgnoreCase(User.Source.LDAP.toString())) /* is from another source */
        {
            ldapResponses.add(user);
        }
    }
    annotateUserListWithSources(ldapResponses);
    return ldapResponses;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse) ArrayList(java.util.ArrayList) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 20 with UserResponse

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

the class LdapListUsersCmd method isACloudstackUser.

boolean isACloudstackUser(final LdapUser ldapUser) {
    boolean rc = false;
    final List<UserResponse> cloudstackUsers = getCloudstackUsers();
    if (cloudstackUsers != null) {
        for (final UserResponse cloudstackUser : cloudstackUsers) {
            if (ldapUser.getUsername().equals(cloudstackUser.getUsername())) {
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace(String.format("found user %s in cloudstack", ldapUser.getUsername()));
                }
                rc = true;
            } else {
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername()));
                }
            }
        }
    }
    return rc;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Aggregations

UserResponse (org.apache.cloudstack.api.response.UserResponse)20 LdapUserResponse (org.apache.cloudstack.api.response.LdapUserResponse)8 UserAccount (com.cloud.user.UserAccount)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)3 ArrayList (java.util.ArrayList)3 AccountResponse (org.apache.cloudstack.api.response.AccountResponse)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceIcon (com.cloud.server.ResourceIcon)1 Account (com.cloud.user.Account)1 User (com.cloud.user.User)1 List (java.util.List)1 Role (org.apache.cloudstack.acl.Role)1 ResourceIconResponse (org.apache.cloudstack.api.response.ResourceIconResponse)1 LdapUser (org.apache.cloudstack.ldap.LdapUser)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1