Search in sources :

Example 1 with LDAPConfigResponse

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

the class LDAPConfigCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    if (getListAll()) {
        // return the existing conf
        LdapListConfigurationCmd listConfigurationCmd = new LdapListConfigurationCmd(_ldapManager);
        Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(listConfigurationCmd);
        ListResponse<LDAPConfigResponse> response = new ListResponse<LDAPConfigResponse>();
        List<LDAPConfigResponse> responses = new ArrayList<LDAPConfigResponse>();
        if (result.second() > 0) {
            boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
            String searchBaseConfig = _ldapConfiguration.getBaseDn();
            String bindDnConfig = _ldapConfiguration.getBindPrincipal();
            for (LdapConfigurationVO ldapConfigurationVO : result.first()) {
                responses.add(createLDAPConfigResponse(ldapConfigurationVO.getHostname(), ldapConfigurationVO.getPort(), useSSlConfig, null, searchBaseConfig, bindDnConfig));
            }
        }
        response.setResponses(responses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else if (getHostname() == null || getPort() == null) {
        throw new InvalidParameterValueException("You need to provide hostname, port to configure your LDAP server");
    } else {
        boolean result = updateLDAP();
        if (result) {
            LDAPConfigResponse lr = createLDAPConfigResponse(getHostname(), getPort(), getUseSSL(), getQueryFilter(), getSearchBase(), getBindDN());
            lr.setResponseName(getCommandName());
            setResponseObject(lr);
        }
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LdapConfigurationVO(org.apache.cloudstack.ldap.LdapConfigurationVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LDAPConfigResponse(org.apache.cloudstack.api.response.LDAPConfigResponse) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with LDAPConfigResponse

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

the class LDAPConfigCmd method createLDAPConfigResponse.

private LDAPConfigResponse createLDAPConfigResponse(String hostname, Integer port, Boolean useSSL, String queryFilter, String searchBase, String bindDN) {
    LDAPConfigResponse lr = new LDAPConfigResponse();
    lr.setHostname(hostname);
    lr.setPort(port.toString());
    lr.setUseSSL(useSSL.toString());
    lr.setQueryFilter(queryFilter);
    lr.setBindDN(bindDN);
    lr.setSearchBase(searchBase);
    lr.setObjectName("ldapconfig");
    return lr;
}
Also used : LDAPConfigResponse(org.apache.cloudstack.api.response.LDAPConfigResponse)

Aggregations

LDAPConfigResponse (org.apache.cloudstack.api.response.LDAPConfigResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 LdapConfigurationVO (org.apache.cloudstack.ldap.LdapConfigurationVO)1