Search in sources :

Example 1 with LdapUser

use of com.cloud.ldap.LdapUser in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    List<LdapUser> users;
    try {
        if (StringUtils.isNotBlank(groupName)) {
            users = _ldapManager.getUsersInGroup(groupName);
        } else {
            users = _ldapManager.getUsers();
        }
    } catch (final NoLdapUserMatchingQueryException ex) {
        users = new ArrayList<>();
        s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage());
    }
    final List<LdapUser> addedUsers = new ArrayList<>();
    for (final LdapUser user : users) {
        final Domain domain = getDomain(user);
        try {
            createCloudstackUserAccount(user, getAccountName(user), domain);
            addedUsers.add(user);
        } catch (final InvalidParameterValueException ex) {
            s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage());
        }
    }
    final ListResponse<LdapUserResponse> response = new ListResponse<>();
    response.setResponses(createLdapUserResponse(addedUsers));
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) Domain(com.cloud.domain.Domain) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 2 with LdapUser

use of com.cloud.ldap.LdapUser in project cosmic by MissionCriticalCloud.

the class LdapUserSearchCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapUserResponses = new ArrayList<>();
    if (users != null) {
        for (final LdapUser user : users) {
            final LdapUserResponse ldapUserResponse = _ldapManager.createLdapUserResponse(user);
            ldapUserResponse.setObjectName("LdapUser");
            ldapUserResponses.add(ldapUserResponse);
        }
    }
    return ldapUserResponses;
}
Also used : LdapUser(com.cloud.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Example 3 with LdapUser

use of com.cloud.ldap.LdapUser 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 4 with LdapUser

use of com.cloud.ldap.LdapUser in project cosmic by MissionCriticalCloud.

the class LdapCreateAccountCmd method execute.

@Override
public void execute() throws ServerApiException {
    final CallContext callContext = getCurrentContext();
    final String finalAccountName = getAccountName();
    final Long finalDomainId = getDomainId();
    callContext.setEventDetails("Account Name: " + finalAccountName + ", Domain Id:" + finalDomainId);
    try {
        final LdapUser user = _ldapManager.getUser(username);
        validateUser(user);
        final UserAccount userAccount = createCloudstackUserAccount(user, finalAccountName, finalDomainId);
        if (userAccount != null) {
            final AccountResponse response = _responseGenerator.createUserAccountResponse(ResponseView.Full, userAccount);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account");
        }
    } catch (final NoLdapUserMatchingQueryException e) {
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, "No LDAP user exists with the username of " + username);
    }
}
Also used : NoLdapUserMatchingQueryException(com.cloud.ldap.NoLdapUserMatchingQueryException) LdapUser(com.cloud.ldap.LdapUser) ServerApiException(com.cloud.api.ServerApiException) AccountResponse(com.cloud.api.response.AccountResponse) CallContext(com.cloud.context.CallContext) UserAccount(com.cloud.user.UserAccount)

Example 5 with LdapUser

use of com.cloud.ldap.LdapUser in project cosmic by MissionCriticalCloud.

the class LdapImportUsersCmd method createLdapUserResponse.

private List<LdapUserResponse> createLdapUserResponse(final List<LdapUser> users) {
    final List<LdapUserResponse> ldapResponses = new ArrayList<>();
    for (final LdapUser user : users) {
        final LdapUserResponse ldapResponse = _ldapManager.createLdapUserResponse(user);
        ldapResponse.setObjectName("LdapUser");
        ldapResponses.add(ldapResponse);
    }
    return ldapResponses;
}
Also used : LdapUser(com.cloud.ldap.LdapUser) ArrayList(java.util.ArrayList) LdapUserResponse(com.cloud.api.response.LdapUserResponse)

Aggregations

LdapUser (com.cloud.ldap.LdapUser)6 LdapUserResponse (com.cloud.api.response.LdapUserResponse)4 ArrayList (java.util.ArrayList)4 NoLdapUserMatchingQueryException (com.cloud.ldap.NoLdapUserMatchingQueryException)3 ServerApiException (com.cloud.api.ServerApiException)2 UserAccount (com.cloud.user.UserAccount)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 AccountResponse (com.cloud.api.response.AccountResponse)1 LinkDomainToLdapResponse (com.cloud.api.response.LinkDomainToLdapResponse)1 ListResponse (com.cloud.api.response.ListResponse)1 CallContext (com.cloud.context.CallContext)1 Domain (com.cloud.domain.Domain)1 Account (com.cloud.user.Account)1