use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.
the class LdapListUsersCmdTest method applyAnyDomain.
/**
* filter all acs users
*
* @throws NoSuchFieldException
* @throws IllegalAccessException
*/
@Test
public void applyAnyDomain() throws NoSuchFieldException, IllegalAccessException, NoLdapUserMatchingQueryException {
mockACSUserSearch();
mockResponseCreation();
useSubdomain();
setHiddenField(ldapListUsersCmd, "userFilter", "AnyDomain");
setHiddenField(ldapListUsersCmd, "domainId", 2l);
ldapListUsersCmd.execute();
// 'rmurphy' annotated with native
// 'bob' still in
// 'abhi' is filtered out
List<ResponseObject> responses = ((ListResponse) ldapListUsersCmd.getResponseObject()).getResponses();
assertEquals(2, responses.size());
for (ResponseObject response : responses) {
if (!(response instanceof LdapUserResponse)) {
fail("unexpected return-type from API backend method");
} else {
LdapUserResponse userResponse = (LdapUserResponse) response;
// further validate this user
if ("rmurphy".equals(userResponse.getUsername()) && !User.Source.NATIVE.toString().equalsIgnoreCase(userResponse.getUserSource())) {
fail("expected murphy from ldap");
}
if ("bob".equals(userResponse.getUsername()) && !"".equals(userResponse.getUserSource())) {
fail("expected bob from without usersource");
}
}
}
}
use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.
the class LdapListUsersCmdTest method mockResponseCreation.
private void mockResponseCreation() throws NoLdapUserMatchingQueryException {
List<LdapUser> users = new ArrayList();
LdapUser murphy = new LdapUser("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org", "mythical", false, null);
LdapUser bob = new LdapUser("bob", "bob@test.com", "Robert", "Young", "cn=bob,ou=engineering,dc=cloudstack,dc=org", LOCAL_DOMAIN_NAME, false, null);
LdapUser abhi = new LdapUser("abhi", "abhi@test.com", "Abhi", "YoungOrOld", "cn=abhi,ou=engineering,dc=cloudstack,dc=org", LOCAL_DOMAIN_NAME, false, null);
users.add(murphy);
users.add(bob);
users.add(abhi);
doReturn(users).when(ldapManager).getUsers(any());
LdapUserResponse response = new LdapUserResponse("rmurphy", "rmurphy@test.com", "Ryan", "Murphy", "cn=rmurphy,dc=cloudstack,dc=org", null);
doReturn(response).when(ldapManager).createLdapUserResponse(murphy);
LdapUserResponse bobResponse = new LdapUserResponse("bob", "bob@test.com", "Robert", "Young", "cn=bob,ou=engineering,dc=cloudstack,dc=org", LOCAL_DOMAIN_NAME);
doReturn(bobResponse).when(ldapManager).createLdapUserResponse(bob);
LdapUserResponse abhiResponse = new LdapUserResponse("abhi", "abhi@test.com", "Abhi", "YoungOrOld", "cn=abhi,ou=engineering,dc=cloudstack,dc=org", LOCAL_DOMAIN_NAME);
doReturn(abhiResponse).when(ldapManager).createLdapUserResponse(abhi);
}
use of org.apache.cloudstack.api.response.LdapUserResponse in project cloudstack by apache.
the class LdapImportUsersCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
if (getAccountType() == null && getRoleId() == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Both account type and role ID are not provided");
}
List<LdapUser> users;
try {
if (StringUtils.isNotBlank(groupName)) {
users = _ldapManager.getUsersInGroup(groupName, domainId);
} else {
users = _ldapManager.getUsers(domainId);
}
} catch (NoLdapUserMatchingQueryException ex) {
users = new ArrayList<LdapUser>();
s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage());
}
List<LdapUser> addedUsers = new ArrayList<LdapUser>();
for (LdapUser user : users) {
Domain domain = getDomain(user);
try {
createCloudstackUserAccount(user, getAccountName(user), domain);
addedUsers.add(user);
} catch (InvalidParameterValueException ex) {
s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage());
}
}
ListResponse<LdapUserResponse> response = new ListResponse<LdapUserResponse>();
response.setResponses(createLdapUserResponse(addedUsers));
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.LdapUserResponse 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.LdapUserResponse 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