Search in sources :

Example 1 with UserResponse

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

the class QueryManagerImpl method searchForUsers.

public ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursive) throws PermissionDeniedException {
    Account caller = CallContext.current().getCallingAccount();
    List<Long> permittedAccounts = new ArrayList<Long>();
    boolean listAll = true;
    Long id = null;
    if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
        long currentId = CallContext.current().getCallingUser().getId();
        if (id != null && currentId != id.longValue()) {
            throw new PermissionDeniedException("Calling user is not authorized to see the user requested by id");
        }
        id = currentId;
    }
    Object username = null;
    Object type = null;
    String accountName = null;
    Object state = null;
    Object keyword = null;
    Pair<List<UserAccountJoinVO>, Integer> result = getUserListInternal(caller, permittedAccounts, listAll, id, username, type, accountName, state, keyword, domainId, recursive, null);
    ListResponse<UserResponse> response = new ListResponse<UserResponse>();
    List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(CallContext.current().getCallingAccount().getDomainId(), result.first().toArray(new UserAccountJoinVO[result.first().size()]));
    response.setResponses(userResponses, result.second());
    return response;
}
Also used : Account(com.cloud.user.Account) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) UserResponse(org.apache.cloudstack.api.response.UserResponse) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with UserResponse

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

the class UserAccountJoinDaoImpl method newUserResponse.

@Override
public UserResponse newUserResponse(UserAccountJoinVO usr) {
    UserResponse userResponse = new UserResponse();
    userResponse.setAccountId(usr.getAccountUuid());
    userResponse.setAccountName(usr.getAccountName());
    userResponse.setAccountType(usr.getAccountType());
    userResponse.setUserSource(usr.getSource());
    userResponse.setCreated(usr.getCreated());
    userResponse.setDomainId(usr.getDomainUuid());
    userResponse.setDomainName(usr.getDomainName());
    userResponse.setEmail(usr.getEmail());
    userResponse.setFirstname(usr.getFirstname());
    userResponse.setId(usr.getUuid());
    userResponse.setLastname(usr.getLastname());
    userResponse.setState(usr.getState().toString());
    userResponse.setTimezone(usr.getTimezone());
    userResponse.setUsername(usr.getUsername());
    userResponse.setApiKey(usr.getApiKey());
    userResponse.setSecretKey(usr.getSecretKey());
    userResponse.setIsDefault(usr.isDefault());
    // set async job
    if (usr.getJobId() != null) {
        userResponse.setJobId(usr.getJobUuid());
        userResponse.setJobStatus(usr.getJobStatus());
    }
    userResponse.setObjectName("user");
    return userResponse;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse)

Example 3 with UserResponse

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

the class LdapListUsersCmdTest method isNotACloudstackUser.

/**
 * given: "We have an LdapUser and not a matching CloudstackUser"
 *  when: "isACloudstackUser is executed"
 *  then: "The result is false"
 */
@Test
public void isNotACloudstackUser() {
    doReturn(new ListResponse<UserResponse>()).when(queryService).searchForUsers(nullable(Long.class), nullable(Boolean.class));
    LdapUser ldapUser = new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org", null, false, null);
    boolean result = ldapListUsersCmd.isACloudstackUser(ldapUser);
    assertFalse(result);
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse) LdapUser(org.apache.cloudstack.ldap.LdapUser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with UserResponse

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

the class LdapListUsersCmd method getCloudstackUser.

private UserResponse getCloudstackUser(LdapUserResponse user) {
    UserResponse returnObject = null;
    final List<UserResponse> cloudstackUsers = getCloudstackUsers();
    if (cloudstackUsers != null) {
        for (final UserResponse cloudstackUser : cloudstackUsers) {
            if (user.getUsername().equals(cloudstackUser.getUsername())) {
                returnObject = cloudstackUser;
                if (returnObject.getDomainId() == this.getCurrentDomainId()) {
                    break;
                }
            }
        }
    }
    return returnObject;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) LdapUserResponse(org.apache.cloudstack.api.response.LdapUserResponse)

Example 5 with UserResponse

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

the class LdapListUsersCmd method isNotAlreadyImportedInTheCurrentDomain.

/**
 * @return true unless the the user is imported in the specified cloudstack domain from LDAP
 */
private boolean isNotAlreadyImportedInTheCurrentDomain(LdapUserResponse user) {
    UserResponse cloudstackUser = getCloudstackUser(user);
    String domainId = getCurrentDomainId();
    return cloudstackUser == null || /*doesn't exist in cloudstack*/
    !(cloudstackUser.getUserSource().equalsIgnoreCase(User.Source.LDAP.toString()) && domainId.equals(cloudstackUser.getDomainId()));
/* is from another source */
}
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