Search in sources :

Example 6 with UserResponse

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

the class UpdateUserCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("UserId: " + getId());
    final UserAccount user = _regionService.updateUser(this);
    if (user != null) {
        final UserResponse response = _responseGenerator.createUserResponse(user);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update user");
    }
}
Also used : UserResponse(com.cloud.api.response.UserResponse) ServerApiException(com.cloud.api.ServerApiException) UserAccount(com.cloud.user.UserAccount)

Example 7 with UserResponse

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

the class GetUserCmdTest method testExecuteWithDefault.

@Test
public void testExecuteWithDefault() {
    final String secretKey = "Very secret key";
    UserResponse response = new UserResponse();
    response.setSecretKey(secretKey);
    when(accountService.getUserByApiKey(null)).thenReturn(userAccount);
    when(responseGenerator.createUserResponse(userAccount)).thenReturn(response);
    getUserCmd.execute();
    response = (UserResponse) getUserCmd.getResponseObject();
    assertFalse("SecretKey was revealed in ResponseObject, wasn't masked", secretKey.equals(response.getSecretKey()));
}
Also used : UserResponse(com.cloud.api.response.UserResponse) Test(org.junit.Test)

Example 8 with UserResponse

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

the class ListUsersCmdTest method testExecuteWithEmptySecretKey.

@Test
public void testExecuteWithEmptySecretKey() {
    ListResponse<UserResponse> responseList = new ListResponse<>();
    UserResponse response = new UserResponse();
    responseList.setResponses(Arrays.asList(response));
    when(queryService.searchForUsers(listUsersCmd)).thenReturn(responseList);
    listUsersCmd.execute();
    responseList = (ListResponse) listUsersCmd.getResponseObject();
    response = responseList.getResponses().get(0);
    assertFalse("Empty SecretKey should be left empty", StringUtils.isNotBlank(response.getSecretKey()));
}
Also used : UserResponse(com.cloud.api.response.UserResponse) ListResponse(com.cloud.api.response.ListResponse) Test(org.junit.Test)

Example 9 with UserResponse

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

the class LdapListUsersCmd method isACloudstackUser.

private boolean isACloudstackUser(final LdapUser ldapUser) {
    final ListResponse<UserResponse> response = _queryService.searchForUsers(new ListUsersCmd());
    final List<UserResponse> cloudstackUsers = response.getResponses();
    if (cloudstackUsers != null && cloudstackUsers.size() != 0) {
        for (final UserResponse cloudstackUser : response.getResponses()) {
            if (ldapUser.getUsername().equals(cloudstackUser.getUsername())) {
                return true;
            }
        }
    }
    return false;
}
Also used : UserResponse(com.cloud.api.response.UserResponse) LdapUserResponse(com.cloud.api.response.LdapUserResponse) ListUsersCmd(com.cloud.api.command.admin.user.ListUsersCmd)

Example 10 with UserResponse

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

the class AccountJoinDaoImpl method newAccountResponse.

@Override
public AccountResponse newAccountResponse(final ResponseView view, final AccountJoinVO account) {
    final AccountResponse accountResponse = new AccountResponse();
    accountResponse.setId(account.getUuid());
    accountResponse.setName(account.getAccountName());
    accountResponse.setAccountType(account.getType());
    accountResponse.setDomainId(account.getDomainUuid());
    accountResponse.setDomainName(account.getDomainName());
    accountResponse.setState(account.getState().toString());
    accountResponse.setNetworkDomain(account.getNetworkDomain());
    accountResponse.setDefaultZone(account.getDataCenterUuid());
    accountResponse.setIsDefault(account.isDefault());
    // get network stat
    accountResponse.setBytesReceived(account.getBytesReceived());
    accountResponse.setBytesSent(account.getBytesSent());
    final boolean fullView = (view == ResponseView.Full && _acctMgr.isRootAdmin(account.getId()));
    setResourceLimits(account, fullView, accountResponse);
    // get resource limits for projects
    final long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
    final String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
    final long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
    final String projectAvail = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
    accountResponse.setProjectLimit(projectLimitDisplay);
    accountResponse.setProjectTotal(projectTotal);
    accountResponse.setProjectAvailable(projectAvail);
    // set async job
    if (account.getJobId() != null) {
        accountResponse.setJobId(account.getJobUuid());
        accountResponse.setJobStatus(account.getJobStatus());
    }
    // adding all the users for an account as part of the response obj
    final List<UserAccountJoinVO> usersForAccount = ApiDBUtils.findUserViewByAccountId(account.getId());
    final List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(usersForAccount.toArray(new UserAccountJoinVO[usersForAccount.size()]));
    accountResponse.setUsers(userResponses);
    // set details
    accountResponse.setDetails(ApiDBUtils.getAccountDetails(account.getId()));
    accountResponse.setObjectName("account");
    return accountResponse;
}
Also used : UserResponse(com.cloud.api.response.UserResponse) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) AccountResponse(com.cloud.api.response.AccountResponse)

Aggregations

UserResponse (com.cloud.api.response.UserResponse)19 ServerApiException (com.cloud.api.ServerApiException)10 UserAccount (com.cloud.user.UserAccount)10 ListResponse (com.cloud.api.response.ListResponse)3 Test (org.junit.Test)3 User (com.cloud.user.User)2 ListUsersCmd (com.cloud.api.command.admin.user.ListUsersCmd)1 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)1 AccountResponse (com.cloud.api.response.AccountResponse)1 LdapUserResponse (com.cloud.api.response.LdapUserResponse)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 ArrayList (java.util.ArrayList)1