Search in sources :

Example 1 with LdapConfigurationResponse

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

the class LdapManagerImpl method addConfiguration.

@Override
public LdapConfigurationResponse addConfiguration(final String hostname, final int port) throws InvalidParameterValueException {
    LdapConfigurationVO configuration = _ldapConfigurationDao.findByHostname(hostname);
    if (configuration == null) {
        LdapContext context = null;
        try {
            final String providerUrl = "ldap://" + hostname + ":" + port;
            context = _ldapContextFactory.createBindContext(providerUrl);
            configuration = new LdapConfigurationVO(hostname, port);
            _ldapConfigurationDao.persist(configuration);
            s_logger.info("Added new ldap server with hostname: " + hostname);
            return new LdapConfigurationResponse(hostname, port);
        } catch (NamingException | IOException e) {
            s_logger.debug("NamingException while doing an LDAP bind", e);
            throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
        } finally {
            closeContext(context);
        }
    } else {
        throw new InvalidParameterValueException("Duplicate configuration");
    }
}
Also used : LdapConfigurationResponse(org.apache.cloudstack.api.response.LdapConfigurationResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NamingException(javax.naming.NamingException) IOException(java.io.IOException) LdapContext(javax.naming.ldap.LdapContext)

Example 2 with LdapConfigurationResponse

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

the class LdapAddConfigurationCmd method execute.

@Override
public void execute() throws ServerApiException {
    try {
        final LdapConfigurationResponse response = _ldapManager.addConfiguration(hostname, port);
        response.setObjectName("LdapAddConfiguration");
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (final InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
    }
}
Also used : LdapConfigurationResponse(org.apache.cloudstack.api.response.LdapConfigurationResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 3 with LdapConfigurationResponse

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

the class LdapDeleteConfigurationCmd method execute.

@Override
public void execute() throws ServerApiException {
    try {
        final LdapConfigurationResponse response = _ldapManager.deleteConfiguration(hostname);
        response.setObjectName("LdapDeleteConfiguration");
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (final InvalidParameterValueException e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.toString());
    }
}
Also used : LdapConfigurationResponse(org.apache.cloudstack.api.response.LdapConfigurationResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 4 with LdapConfigurationResponse

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

the class LdapManagerImpl method createLdapConfigurationResponse.

@Override
public LdapConfigurationResponse createLdapConfigurationResponse(final LdapConfigurationVO configuration) {
    final LdapConfigurationResponse response = new LdapConfigurationResponse();
    response.setHostname(configuration.getHostname());
    response.setPort(configuration.getPort());
    return response;
}
Also used : LdapConfigurationResponse(org.apache.cloudstack.api.response.LdapConfigurationResponse)

Example 5 with LdapConfigurationResponse

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

the class LdapListConfigurationCmd method createLdapConfigurationResponses.

private List<LdapConfigurationResponse> createLdapConfigurationResponses(final List<? extends LdapConfigurationVO> configurations) {
    final List<LdapConfigurationResponse> responses = new ArrayList<LdapConfigurationResponse>();
    for (final LdapConfigurationVO resource : configurations) {
        final LdapConfigurationResponse configurationResponse = _ldapManager.createLdapConfigurationResponse(resource);
        configurationResponse.setObjectName("LdapConfiguration");
        responses.add(configurationResponse);
    }
    return responses;
}
Also used : LdapConfigurationResponse(org.apache.cloudstack.api.response.LdapConfigurationResponse) LdapConfigurationVO(org.apache.cloudstack.ldap.LdapConfigurationVO) ArrayList(java.util.ArrayList)

Aggregations

LdapConfigurationResponse (org.apache.cloudstack.api.response.LdapConfigurationResponse)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NamingException (javax.naming.NamingException)1 LdapContext (javax.naming.ldap.LdapContext)1 LdapConfigurationVO (org.apache.cloudstack.ldap.LdapConfigurationVO)1