Search in sources :

Example 1 with LinkDomainToLdapResponse

use of org.apache.cloudstack.api.response.LinkDomainToLdapResponse in project cloudstack by apache.

the class LinkDomainToLdapCmd method execute.

@Override
public void execute() throws ServerApiException {
    try {
        LinkDomainToLdapResponse response = _ldapManager.linkDomainToLdap(domainId, type, name, accountType);
        if (admin != null) {
            LdapUser ldapUser = null;
            try {
                ldapUser = _ldapManager.getUser(admin, type, name);
            } catch (NoLdapUserMatchingQueryException e) {
                s_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()));
                        s_logger.info("created an account with name " + admin + " in the given domain " + domainId);
                    } catch (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(org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException) LdapUser(org.apache.cloudstack.ldap.LdapUser) LinkDomainToLdapResponse(org.apache.cloudstack.api.response.LinkDomainToLdapResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserAccount(com.cloud.user.UserAccount) ServerApiException(org.apache.cloudstack.api.ServerApiException) NoLdapUserMatchingQueryException(org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 2 with LinkDomainToLdapResponse

use of org.apache.cloudstack.api.response.LinkDomainToLdapResponse in project cloudstack by apache.

the class LdapManagerImpl method linkDomainToLdap.

@Override
public LinkDomainToLdapResponse linkDomainToLdap(Long domainId, String type, String name, 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)");
    LinkType linkType = LdapManager.LinkType.valueOf(type.toUpperCase());
    LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(domainId, linkType, name, accountType));
    LinkDomainToLdapResponse response = new LinkDomainToLdapResponse(vo.getDomainId(), vo.getType().toString(), vo.getName(), vo.getAccountType());
    return response;
}
Also used : LinkDomainToLdapResponse(org.apache.cloudstack.api.response.LinkDomainToLdapResponse)

Aggregations

LinkDomainToLdapResponse (org.apache.cloudstack.api.response.LinkDomainToLdapResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 LdapUser (org.apache.cloudstack.ldap.LdapUser)1 NoLdapUserMatchingQueryException (org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException)1