Search in sources :

Example 1 with LinkDomainToLdapResponse

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());
    }
}
Also used : Account(com.cloud.user.Account) UserAccount(com.cloud.user.UserAccount) NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) UserAccount(com.cloud.user.UserAccount) NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 2 with LinkDomainToLdapResponse

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());
    }
}
Also used : LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 3 with LinkDomainToLdapResponse

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;
}
Also used : LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) Domain(com.cloud.domain.Domain)

Example 4 with LinkDomainToLdapResponse

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;
}
Also used : LinkDomainToLdapResponse(com.cloud.api.response.LinkDomainToLdapResponse) Domain(com.cloud.domain.Domain)

Aggregations

LinkDomainToLdapResponse (com.cloud.api.response.LinkDomainToLdapResponse)4 ServerApiException (com.cloud.api.ServerApiException)2 Domain (com.cloud.domain.Domain)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 LdapUser (com.cloud.ldap.LdapUser)1 NoLdapUserMatchingQueryException (com.cloud.ldap.NoLdapUserMatchingQueryException)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1