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;
}
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;
}
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);
}
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;
}
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 */
}
Aggregations