use of org.apache.cloudstack.ldap.LdapUser in project cloudstack by apache.
the class LdapCreateAccountCmdTest method failedCreationDueToANullResponseFromCloudstackAccountCreator.
@Test(expected = ServerApiException.class)
public void failedCreationDueToANullResponseFromCloudstackAccountCreator() throws Exception {
// We have an LdapManager, AccountService and LdapCreateAccountCmd
LdapUser mrMurphy = new LdapUser("rmurphy", "rmurphy@cloudstack.org", "Ryan", "Murphy", "cn=rmurphy,ou=engineering,dc=cloudstack,dc=org", "engineering", false, null);
when(ldapManager.getUser(nullable(String.class), isNull())).thenReturn(mrMurphy).thenReturn(mrMurphy);
ldapCreateAccountCmd.execute();
fail("An exception should have been thrown: " + ServerApiException.class);
}
use of org.apache.cloudstack.ldap.LdapUser 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.ldap.LdapUser 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.ldap.LdapUser in project cloudstack by apache.
the class LinkDomainToLdapCmdTest method execute.
@Test
public void execute() throws Exception {
// test with valid params and with admin who doesnt exist in cloudstack
Long domainId = 1L;
String type = "GROUP";
String ldapDomain = "CN=test,DC=ccp,DC=Citrix,DC=com";
short accountType = Account.ACCOUNT_TYPE_DOMAIN_ADMIN;
String username = "admin";
long accountId = 24;
setHiddenField(linkDomainToLdapCmd, "ldapDomain", ldapDomain);
setHiddenField(linkDomainToLdapCmd, "admin", username);
setHiddenField(linkDomainToLdapCmd, "type", type);
setHiddenField(linkDomainToLdapCmd, "domainId", domainId);
setHiddenField(linkDomainToLdapCmd, "accountType", accountType);
LinkDomainToLdapResponse response = new LinkDomainToLdapResponse(domainId.toString(), type, ldapDomain, (short) accountType);
when(ldapManager.linkDomainToLdap(linkDomainToLdapCmd)).thenReturn(response);
when(ldapManager.getUser(username, type, ldapDomain, 1L)).thenReturn(new LdapUser(username, "admin@ccp.citrix.com", "Admin", "Admin", ldapDomain, "ccp", false, null));
when(accountService.getActiveAccountByName(username, domainId)).thenReturn(null);
UserAccountVO userAccount = new UserAccountVO();
userAccount.setAccountId(24);
when(accountService.createUserAccount(eq(username), eq(""), eq("Admin"), eq("Admin"), eq("admin@ccp.citrix.com"), isNull(String.class), eq(username), eq(Account.ACCOUNT_TYPE_DOMAIN_ADMIN), eq(RoleType.DomainAdmin.getId()), eq(domainId), isNull(String.class), (java.util.Map<String, String>) isNull(), anyString(), anyString(), eq(User.Source.LDAP))).thenReturn(userAccount);
linkDomainToLdapCmd.execute();
LinkDomainToLdapResponse result = (LinkDomainToLdapResponse) linkDomainToLdapCmd.getResponseObject();
assertEquals("objectName", "LinkDomainToLdap", result.getObjectName());
assertEquals("commandName", linkDomainToLdapCmd.getCommandName(), result.getResponseName());
assertEquals("domainId", domainId.toString(), result.getDomainId());
assertEquals("type", type, result.getType());
assertEquals("name", ldapDomain, result.getLdapDomain());
assertEquals("accountId", String.valueOf(accountId), result.getAdminId());
}
use of org.apache.cloudstack.ldap.LdapUser in project cloudstack by apache.
the class LinkAccountToLdapCmd method execute.
@Override
public void execute() throws ServerApiException {
try {
LinkAccountToLdapResponse response = _ldapManager.linkAccountToLdap(this);
if (admin != null) {
LdapUser ldapUser = null;
try {
ldapUser = _ldapManager.getUser(admin, type, ldapDomain, domainId);
} catch (NoLdapUserMatchingQueryException e) {
LOGGER.debug("no ldap user matching username " + admin + " in the given group/ou", e);
}
if (ldapUser != null && !ldapUser.isDisabled()) {
Account account = _accountService.getActiveAccountByName(admin, domainId);
if (account == null) {
try {
UserAccount userAccount = _accountService.createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.ACCOUNT_TYPE_DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP);
response.setAdminId(String.valueOf(userAccount.getAccountId()));
LOGGER.info("created an account with name " + admin + " in the given domain " + domainId);
} catch (Exception e) {
LOGGER.info("an exception occurred while creating account with name " + admin + " in domain " + domainId, e);
}
} else {
LOGGER.debug("an account with name " + admin + " already exists in the domain " + domainId);
}
} else {
LOGGER.debug("ldap user with username " + admin + " is disabled in the given group/ou");
}
}
response.setObjectName(APINAME);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (final InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
}
}
Aggregations