Search in sources :

Example 1 with LdapConfigurationResponse

use of com.cloud.api.response.LdapConfigurationResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.api.response.LdapConfigurationResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 2 with LdapConfigurationResponse

use of com.cloud.api.response.LdapConfigurationResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.api.response.LdapConfigurationResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 3 with LdapConfigurationResponse

use of com.cloud.api.response.LdapConfigurationResponse in project cosmic by MissionCriticalCloud.

the class LdapListConfigurationCmd method createLdapConfigurationResponses.

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

Example 4 with LdapConfigurationResponse

use of com.cloud.api.response.LdapConfigurationResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.api.response.LdapConfigurationResponse)

Example 5 with LdapConfigurationResponse

use of com.cloud.api.response.LdapConfigurationResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.api.response.LdapConfigurationResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NamingException(javax.naming.NamingException) IOException(java.io.IOException) LdapContext(javax.naming.ldap.LdapContext)

Aggregations

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