Search in sources :

Example 6 with CredStashGetCredentialFailedException

use of org.finra.herd.dao.exception.CredStashGetCredentialFailedException in project herd by FINRAOS.

the class JestClientFactory method getJestClient.

/**
 * Builds and returns a JEST client.
 *
 * @return the configured JEST client
 */
public JestClient getJestClient() {
    // Retrieve the configuration values used for setting up an Elasticsearch JEST client.
    final String hostname = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_HOSTNAME);
    final int port = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_PORT, Integer.class);
    final String scheme = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_SCHEME);
    final String serverUri = String.format("%s://%s:%d", scheme, hostname, port);
    final int connectionTimeout = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_CONNECTION_TIMEOUT, Integer.class);
    final int readTimeout = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_READ_TIMEOUT, Integer.class);
    LOGGER.info("Elasticsearch REST Client Settings:  scheme={}, hostname={}, port={}, serverUri={}", scheme, hostname, port, serverUri);
    io.searchbox.client.JestClientFactory jestClientFactory = new io.searchbox.client.JestClientFactory();
    if (StringUtils.equalsIgnoreCase(scheme, "https")) {
        final String userName = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_USERNAME);
        final String credentialName = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_USERCREDENTIALNAME);
        final String credstashEncryptionContext = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_ENCRYPTION_CONTEXT);
        String password;
        try {
            password = credStashHelper.getCredentialFromCredStash(credstashEncryptionContext, credentialName);
        } catch (CredStashGetCredentialFailedException e) {
            throw new IllegalStateException(e);
        }
        SSLConnectionSocketFactory sslSocketFactory;
        try {
            sslSocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(), NoopHostnameVerifier.INSTANCE);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        }
        jestClientFactory.setHttpClientConfig(new HttpClientConfig.Builder(serverUri).connTimeout(connectionTimeout).readTimeout(readTimeout).defaultCredentials(userName, password).sslSocketFactory(sslSocketFactory).multiThreaded(true).build());
    } else {
        jestClientFactory.setHttpClientConfig(new HttpClientConfig.Builder(serverUri).connTimeout(connectionTimeout).readTimeout(readTimeout).multiThreaded(true).build());
    }
    return jestClientFactory.getObject();
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) CredStashGetCredentialFailedException(org.finra.herd.dao.exception.CredStashGetCredentialFailedException)

Aggregations

CredStashGetCredentialFailedException (org.finra.herd.dao.exception.CredStashGetCredentialFailedException)6 Test (org.junit.Test)4 ClientConfiguration (com.amazonaws.ClientConfiguration)3 CredStash (org.finra.herd.dao.credstash.CredStash)3 HashMap (java.util.HashMap)2 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)2 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)2 HttpClientConfig (io.searchbox.client.config.HttpClientConfig)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 RelationalStorageAttributesDto (org.finra.herd.model.dto.RelationalStorageAttributesDto)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 Retryable (org.springframework.retry.annotation.Retryable)1