use of com.cloud.api.response.LinkDomainToLdapResponse in project cosmic by MissionCriticalCloud.
the class LinkDomainToLdapCmd method execute.
@Override
public void execute() throws ServerApiException {
try {
final LinkDomainToLdapResponse response = _ldapManager.linkDomainToLdap(domainId, type, name, accountType);
if (admin != null) {
LdapUser ldapUser = null;
try {
ldapUser = _ldapManager.getUser(admin, type, name);
} catch (final NoLdapUserMatchingQueryException e) {
s_logger.debug("no ldap user matching username " + admin + " in the given group/ou", e);
}
if (ldapUser != null && !ldapUser.isDisabled()) {
final Account account = _accountService.getActiveAccountByName(admin, domainId);
if (account == null) {
try {
final UserAccount userAccount = _accountService.createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.ACCOUNT_TYPE_DOMAIN_ADMIN, domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP);
response.setAdminId(String.valueOf(userAccount.getAccountId()));
s_logger.info("created an account with name " + admin + " in the given domain " + domainId);
} catch (final Exception e) {
s_logger.info("an exception occurred while creating account with name " + admin + " in domain " + domainId, e);
}
} else {
s_logger.debug("an account with name " + admin + " already exists in the domain " + domainId);
}
} else {
s_logger.debug("ldap user with username " + admin + " is disabled in the given group/ou");
}
}
response.setObjectName("LinkDomainToLdap");
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (final InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
}
}
use of com.cloud.api.response.LinkDomainToLdapResponse in project cosmic by MissionCriticalCloud.
the class ListDomainLdapLinkCmd method execute.
@Override
public void execute() throws ServerApiException {
try {
final LinkDomainToLdapResponse response = _ldapManager.listLinkDomainToLdap(domainId);
response.setObjectName("LinkDomainToLdap");
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (final InvalidParameterValueException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
}
}
use of com.cloud.api.response.LinkDomainToLdapResponse in project cosmic by MissionCriticalCloud.
the class LdapManagerImpl method linkDomainToLdap.
@Override
public LinkDomainToLdapResponse linkDomainToLdap(final Long domainId, final String type, final String name, final short accountType) {
Validate.notNull(type, "type cannot be null. It should either be GROUP or OU");
Validate.notNull(domainId, "domainId cannot be null.");
Validate.notEmpty(name, "GROUP or OU name cannot be empty");
// Account type should be 0 or 2. check the constants in com.cloud.user.Account
Validate.isTrue(accountType == 0 || accountType == 2, "accountype should be either 0(normal user) or 2(domain admin)");
final Domain domain = _domainManager.getDomain(domainId);
final LinkType linkType = LdapManager.LinkType.valueOf(type.toUpperCase());
final LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, linkType, name, accountType));
final LinkDomainToLdapResponse response = new LinkDomainToLdapResponse(domain.getUuid(), vo.getType().toString(), vo.getName(), vo.getAccountType());
return response;
}
use of com.cloud.api.response.LinkDomainToLdapResponse in project cosmic by MissionCriticalCloud.
the class LdapManagerImpl method listLinkDomainToLdap.
@Override
public LinkDomainToLdapResponse listLinkDomainToLdap(final Long domainId) {
Validate.notNull(domainId, "domainId cannot be null.");
final LdapTrustMapVO ldapTrustMap = _ldapManager.getDomainLinkedToLdap(domainId);
final Domain domain = _domainManager.getDomain(domainId);
final LinkDomainToLdapResponse response;
if (!_ldapManager.isLdapEnabled()) {
return new LinkDomainToLdapResponse(domain.getUuid());
}
if (ldapTrustMap != null) {
response = new LinkDomainToLdapResponse(domain.getUuid(), ldapTrustMap.getType().toString(), ldapTrustMap.getName(), ldapTrustMap.getAccountType());
} else {
response = new LinkDomainToLdapResponse(domain.getUuid());
}
return response;
}
Aggregations