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");
}
}
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()));
}
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()));
}
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;
}
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;
}
Aggregations