Example usage for javax.net.ssl KeyManagerFactory getDefaultAlgorithm

List of usage examples for javax.net.ssl KeyManagerFactory getDefaultAlgorithm

Introduction

In this page you can find the example usage for javax.net.ssl KeyManagerFactory getDefaultAlgorithm.

Prototype

public static final String getDefaultAlgorithm() 

Source Link

Document

Obtains the default KeyManagerFactory algorithm name.

Usage

From source file:org.wisdom.framework.vertx.ServerTest.java

/**
 * This methods checks HTTP, HTTPS and HTTPS with Mutual Authentication.
 *///  w w  w  .ja  va  2  s.co m
@Test
public void testCreationOfThreeServersFromConfiguration()
        throws InterruptedException, IOException, KeyStoreException, CertificateException,
        NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException {
    FakeConfiguration s1 = new FakeConfiguration(ImmutableMap.<String, Object>builder().put("port", 0)
            .put("ssl", false).put("authentication", false).build());

    FakeConfiguration s2 = new FakeConfiguration(ImmutableMap.<String, Object>builder().put("port", 0)
            .put("ssl", true).put("authentication", false).build());

    FakeConfiguration s3 = new FakeConfiguration(ImmutableMap.<String, Object>builder().put("port", 0)
            .put("ssl", true).put("authentication", true).build());

    // Server HTTPS
    File root = new File("");
    final File serverKeyStore = new File(
            root.getAbsolutePath() + "/src/test/resources/keystore/server/server.jks");
    assertThat(serverKeyStore).isFile();
    when(application.get("https.keyStore")).thenReturn(serverKeyStore.getAbsolutePath());
    when(application.get("https.trustStore"))
            .thenReturn(new File(root.getAbsolutePath() + "/src/test/resources/keystore/server/server.jks")
                    .getAbsolutePath());
    when(application.getWithDefault("https.keyStoreType", "JKS")).thenReturn("JKS");
    when(application.getWithDefault("https.trustStoreType", "JKS")).thenReturn("JKS");
    when(application.getWithDefault("https.keyStorePassword", "")).thenReturn("wisdom");
    when(application.getWithDefault("https.trustStorePassword", "")).thenReturn("wisdom");

    when(application.getWithDefault("https.keyStoreAlgorithm", KeyManagerFactory.getDefaultAlgorithm()))
            .thenReturn(KeyManagerFactory.getDefaultAlgorithm());
    when(application.getWithDefault("https.trustStoreAlgorithm", KeyManagerFactory.getDefaultAlgorithm()))
            .thenReturn(KeyManagerFactory.getDefaultAlgorithm());
    when(application.getConfiguration("vertx.servers"))
            .thenReturn(new FakeConfiguration(ImmutableMap.<String, Object>of("s1", s1, "s2", s2, "s3", s3)));

    Controller controller = new DefaultController() {
        @SuppressWarnings("unused")
        public Result index() {
            return ok("Alright");
        }
    };
    Route route = new RouteBuilder().route(HttpMethod.GET).on("/").to(controller, "index");
    when(router.getRouteFor(anyString(), anyString(), any(Request.class))).thenReturn(route);

    wisdom.start();
    waitForStart(wisdom);
    waitForHttpsStart(wisdom);

    assertThat(wisdom.servers).hasSize(3);

    // Check rendering
    for (Server server : wisdom.servers) {
        String r;
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        FileInputStream instream = new FileInputStream("src/test/resources/keystore/client/client1.jks");
        trustStore.load(instream, "wisdom".toCharArray());

        // Trust own CA and all self-signed certs
        SSLContext sslcontext = SSLContexts.custom()
                .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
                .loadKeyMaterial(trustStore, "wisdom".toCharArray()).build();

        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,
                new String[] { "TLSv1", "SSLv3" }, null,
                SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

        if (server.ssl()) {
            HttpGet httpget = new HttpGet("https://localhost:" + server.port());
            final CloseableHttpResponse response = httpclient.execute(httpget);
            r = EntityUtils.toString(response.getEntity());
        } else {
            r = org.apache.http.client.fluent.Request.Get("http://localhost:" + server.port()).execute()
                    .returnContent().asString();
        }

        assertThat(r).isEqualToIgnoringCase("Alright");
    }
}

From source file:nl.nn.adapterframework.http.AuthSSLProtocolSocketFactory.java

private static KeyManager[] createKeyManagers(final KeyStore keystore, final String password, String algorithm)
        throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
    if (keystore == null) {
        throw new IllegalArgumentException("Keystore may not be null");
    }/*from   ww  w . ja  v  a2  s  .  c o  m*/
    log.debug("Initializing key manager");
    if (StringUtils.isEmpty(algorithm)) {
        algorithm = KeyManagerFactory.getDefaultAlgorithm();
        log.debug("using default KeyManager algorithm [" + algorithm + "]");
    } else {
        log.debug("using configured KeyManager algorithm [" + algorithm + "]");
    }
    KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(algorithm);
    kmfactory.init(keystore, password != null ? password.toCharArray() : null);
    return kmfactory.getKeyManagers();
}

From source file:org.wso2.carbon.extension.analytics.receiver.rabbitmq.internal.util.RabbitMQAdapterListener.java

public RabbitMQAdapterListener(RabbitMQBrokerConnectionConfiguration rabbitmqBrokerConnectionConfiguration,
        InputEventAdapterConfiguration eventAdapterConfiguration,
        InputEventAdapterListener inputEventAdapterListener) {

    connectionFactory = new ConnectionFactory();
    this.rabbitmqBrokerConnectionConfiguration = rabbitmqBrokerConnectionConfiguration;
    this.queueName = eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_QUEUE_NAME);
    this.exchangeName = eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_EXCHANGE_NAME);
    this.exchangeType = eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_EXCHANGE_TYPE);
    this.routeKey = eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_QUEUE_ROUTING_KEY);
    this.consumerTagString = eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.CONSUMER_TAG);
    this.adapterName = eventAdapterConfiguration.getName();
    this.eventAdapterListener = inputEventAdapterListener;
    this.tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    workerState = STATE_STOPPED;//www .j av a2s .c o  m
    STATE_STARTED = 1;
    if (routeKey == null) {
        routeKey = queueName;
    }
    if (!eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_ENABLED).equals("false")) {
        try {
            boolean sslEnabled = Boolean.parseBoolean(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_ENABLED));
            if (sslEnabled) {
                String keyStoreLocation = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_LOCATION);
                String keyStoreType = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_TYPE);
                String keyStorePassword = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_PASSWORD);
                String trustStoreLocation = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_LOCATION);
                String trustStoreType = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_TYPE);
                String trustStorePassword = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_PASSWORD);
                String sslVersion = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_SSL_VERSION);

                if (StringUtils.isEmpty(keyStoreLocation) || StringUtils.isEmpty(keyStoreType)
                        || StringUtils.isEmpty(keyStorePassword) || StringUtils.isEmpty(trustStoreLocation)
                        || StringUtils.isEmpty(trustStoreType) || StringUtils.isEmpty(trustStorePassword)) {
                    log.debug("Truststore and keystore information is not provided");
                    if (StringUtils.isNotEmpty(sslVersion)) {
                        connectionFactory.useSslProtocol(sslVersion);
                    } else {
                        log.info("Proceeding with default SSL configuration");
                        connectionFactory.useSslProtocol();
                    }
                } else {
                    char[] keyPassphrase = keyStorePassword.toCharArray();
                    KeyStore ks = KeyStore.getInstance(keyStoreType);
                    ks.load(new FileInputStream(keyStoreLocation), keyPassphrase);

                    KeyManagerFactory kmf = KeyManagerFactory
                            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    kmf.init(ks, keyPassphrase);

                    char[] trustPassphrase = trustStorePassword.toCharArray();
                    KeyStore tks = KeyStore.getInstance(trustStoreType);
                    tks.load(new FileInputStream(trustStoreLocation), trustPassphrase);

                    TrustManagerFactory tmf = TrustManagerFactory
                            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    tmf.init(tks);

                    SSLContext c = SSLContext.getInstance(sslVersion);
                    c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

                    connectionFactory.useSslProtocol(c);
                }
            }
        } catch (IOException e) {
            handleException("TrustStore or KeyStore File path is incorrect. Specify KeyStore location or "
                    + "TrustStore location Correctly.", e);
        } catch (CertificateException e) {
            handleException("TrustStore or keyStore is not specified. So Security certificate"
                    + " Exception happened.  ", e);
        } catch (NoSuchAlgorithmException e) {
            handleException("Algorithm is not available in KeyManagerFactory class.", e);
        } catch (UnrecoverableKeyException e) {
            handleException("Unable to recover Key", e);
        } catch (KeyStoreException e) {
            handleException("Error in KeyStore or TrustStore Type", e);
        } catch (KeyManagementException e) {
            handleException("Error in Key Management", e);
        }
    }

    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_FACTORY_HEARTBEAT))) {
        try {
            int heartbeatValue = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQEventAdapterConstants.RABBITMQ_FACTORY_HEARTBEAT));
            connectionFactory.setRequestedHeartbeat(heartbeatValue);
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading heartbeat value. Proceeding with default");
        }
    }
    connectionFactory.setHost(rabbitmqBrokerConnectionConfiguration.getHostName());
    try {
        int port = Integer.parseInt(rabbitmqBrokerConnectionConfiguration.getPort());
        if (port > 0) {
            connectionFactory.setPort(port);
        }
    } catch (NumberFormatException e) {
        handleException("Number format error in port number", e);
    }
    connectionFactory.setUsername(rabbitmqBrokerConnectionConfiguration.getUsername());
    connectionFactory.setPassword(rabbitmqBrokerConnectionConfiguration.getPassword());
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_SERVER_VIRTUAL_HOST))) {
        connectionFactory.setVirtualHost(eventAdapterConfiguration.getProperties()
                .get(RabbitMQEventAdapterConstants.RABBITMQ_SERVER_VIRTUAL_HOST));
    }
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_COUNT))) {
        try {
            retryCountMax = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_COUNT));
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading retry count value. Proceeding with default value (3)", e);
        }
    }
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_INTERVAL))) {
        try {
            retryInterval = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_INTERVAL));
        } catch (NumberFormatException e) {
            log.warn(
                    "Number format error in reading retry interval value. Proceeding with default value (30000ms)",
                    e);
        }
    }
}

From source file:com.alphabetbloc.accessmrs.utilities.NetworkUtils.java

public static SSLContext createSslContext() throws GeneralSecurityException, IOException {

    // TrustStore
    KeyStore trustStore = FileUtils.loadSslStore(FileUtils.MY_TRUSTSTORE);
    if (trustStore == null)
        throw new IOException("Access denied. Ensure credential storage is available.");
    MyTrustManager myTrustManager = new MyTrustManager(trustStore);
    TrustManager[] tms = new TrustManager[] { myTrustManager };

    // KeyStore//from   www  . j  ava  2  s . co  m
    KeyManager[] kms = null;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
    boolean useClientAuth = prefs.getBoolean(App.getApp().getString(R.string.key_client_auth), false);
    if (useClientAuth) {
        KeyStore keyStore = FileUtils.loadSslStore(FileUtils.MY_KEYSTORE);
        if (keyStore == null)
            throw new IOException("Access denied. Ensure credential storage is available.");
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(keyStore, EncryptionUtil.getPassword().toCharArray());
        kms = kmf.getKeyManagers();
    }

    SSLContext context = SSLContext.getInstance("TLS");
    context.init(kms, tms, null);
    return context;
}

From source file:io.hops.hopsworks.api.util.CustomSSLProtocolSocketFactory.java

private KeyManager[] createKeyManagers(final KeyStore keyStore, final String keyPassword)
        throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    if (keyStore == null) {
        LOG.log(Level.SEVERE, "Creating SSL socket but key store is null");
        throw new IllegalArgumentException("KeyStore cannot be null");
    }/*from  w  ww  .  ja  va 2 s .  c om*/
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keyStore, keyPassword != null ? keyPassword.toCharArray() : null);

    return kmf.getKeyManagers();
}

From source file:org.wisdom.engine.ssl.SSLServerContext.java

private TrustManagerFactory getTrustManagerFactoryFromKeyStore(final File maybeRoot, final String path)
        throws KeyStoreException {
    final TrustManagerFactory tmf;
    File file = new File(path);
    if (!file.isFile()) {
        // Second chance.
        file = new File(maybeRoot, path);
    }//from   w w  w . j  a  va  2  s  .c  om

    LOGGER.info("\t trust store: " + file.getAbsolutePath());
    final KeyStore trustStore = KeyStore
            .getInstance(accessor.getConfiguration().getWithDefault("https.trustStoreType", "JKS"));
    LOGGER.info("\t trust store type: " + trustStore.getType());
    LOGGER.info("\t trust store provider: " + trustStore.getProvider());
    final char[] password = accessor.getConfiguration().getWithDefault("https.trustStorePassword", "")
            .toCharArray();
    LOGGER.info("\t trust store password length: " + password.length);
    final String algorithm = accessor.getConfiguration().getWithDefault("https.trustStoreAlgorithm",
            KeyManagerFactory.getDefaultAlgorithm());
    LOGGER.info("\t trust store algorithm: " + algorithm);
    if (file.isFile()) {
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(file);
            trustStore.load(stream, password);
            tmf = TrustManagerFactory.getInstance(algorithm);
            tmf.init(trustStore);
        } catch (final Exception e) {
            throw new RuntimeException(HTTPSFAIL + e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(stream);
        }
    } else {
        throw new RuntimeException(
                "Cannot load trust store from '" + file.getAbsolutePath() + "', " + "the file does not exist");
    }
    return tmf;
}

From source file:org.hyperic.hq.bizapp.agent.server.CommandsServer.java

private KeyManager[] getKeyManagers(KeyStore useStore, String filePass) throws AgentStartException {
    KeyManagerFactory res;/*from   ww  w.j ava  2 s .com*/
    String alg;

    alg = KeyManagerFactory.getDefaultAlgorithm();
    try {
        res = KeyManagerFactory.getInstance(alg);
        res.init(useStore, filePass.toCharArray());
    } catch (Exception exc) {
        throw new AgentStartException("Unable to get default key " + "manager: " + exc.getMessage());
    }
    return res.getKeyManagers();
}

From source file:org.elasticsearch.hadoop.rest.commonshttp.SSLSocketFactory.java

private KeyManager[] loadKeyManagers() throws GeneralSecurityException, IOException {
    if (!StringUtils.hasText(keyStoreLocation)) {
        return null;
    }/*  w w w  .ja v a2  s .  c o m*/

    char[] pass = (StringUtils.hasText(keyStorePass) ? keyStorePass.trim().toCharArray() : null);
    KeyStore keyStore = loadKeyStore(keyStoreLocation, pass);
    KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmFactory.init(keyStore, pass);
    return kmFactory.getKeyManagers();
}

From source file:com.sonatype.nexus.ssl.plugin.internal.TrustStoreImpl.java

private static KeyManager[] getSystemKeyManagers() throws Exception {
    KeyManagerFactory keyManagerFactory;

    String keyAlgorithm = System.getProperty("ssl.KeyManagerFactory.algorithm");
    if (keyAlgorithm == null) {
        keyAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
    }//from  ww w.java2 s. c  o m
    String keyStoreType = System.getProperty("javax.net.ssl.keyStoreType");
    if (keyStoreType == null) {
        keyStoreType = KeyStore.getDefaultType();
    }
    if ("none".equalsIgnoreCase(keyStoreType)) {
        keyManagerFactory = KeyManagerFactory.getInstance(keyAlgorithm);
    } else {
        final String keyStoreFileName = System.getProperty("javax.net.ssl.keyStore");
        if (keyStoreFileName != null) {
            File keyStoreFile = new File(keyStoreFileName);
            keyManagerFactory = KeyManagerFactory.getInstance(keyAlgorithm);
            String keyStoreProvider = System.getProperty("javax.net.ssl.keyStoreProvider");
            KeyStore keyStore;
            if (keyStoreProvider != null) {
                keyStore = KeyStore.getInstance(keyStoreType, keyStoreProvider);
            } else {
                keyStore = KeyStore.getInstance(keyStoreType);
            }
            String password = System.getProperty("javax.net.ssl.keyStorePassword");
            try (FileInputStream in = new FileInputStream(keyStoreFile)) {
                keyStore.load(in, password != null ? password.toCharArray() : null);
            }
            keyManagerFactory.init(keyStore, password != null ? password.toCharArray() : null);
        } else {
            return null;
        }
    }

    return keyManagerFactory.getKeyManagers();
}

From source file:org.wso2.carbon.event.adapter.rabbitmq.internal.util.RabbitMQInputEventAdapterListener.java

public RabbitMQInputEventAdapterListener(
        RabbitMQInputEventAdapterConnectionConfiguration rabbitMQInputEventAdapterConnectionConfiguration,
        InputEventAdapterConfiguration eventAdapterConfiguration,
        InputEventAdapterListener inputEventAdapterListener) {

    connectionFactory = new ConnectionFactory();
    this.rabbitMQInputEventAdapterConnectionConfiguration = rabbitMQInputEventAdapterConnectionConfiguration;
    this.queueName = eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_QUEUE_NAME);
    this.exchangeName = eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_EXCHANGE_NAME);
    this.exchangeType = eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_EXCHANGE_TYPE);
    this.routeKey = eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_QUEUE_ROUTING_KEY);
    this.consumerTagString = eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.CONSUMER_TAG);
    this.adapterName = eventAdapterConfiguration.getName();
    this.eventAdapterListener = inputEventAdapterListener;
    this.tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    workerState = STATE_STOPPED;//from  w  ww  .j  a v a2s  . c o m
    STATE_STARTED = 1;
    if (routeKey == null) {
        routeKey = queueName;
    }
    if (!eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_ENABLED).equals("false")) {
        try {
            boolean sslEnabled = Boolean.parseBoolean(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_ENABLED));
            if (sslEnabled) {
                String keyStoreLocation = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_LOCATION);
                String keyStoreType = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_TYPE);
                String keyStorePassword = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_KEYSTORE_PASSWORD);
                String trustStoreLocation = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_LOCATION);
                String trustStoreType = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_TYPE);
                String trustStorePassword = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_TRUSTSTORE_PASSWORD);
                String sslVersion = eventAdapterConfiguration.getProperties()
                        .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_SSL_VERSION);

                if (StringUtils.isEmpty(keyStoreLocation) || StringUtils.isEmpty(keyStoreType)
                        || StringUtils.isEmpty(keyStorePassword) || StringUtils.isEmpty(trustStoreLocation)
                        || StringUtils.isEmpty(trustStoreType) || StringUtils.isEmpty(trustStorePassword)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Truststore and keystore information is not provided");
                    }
                    if (StringUtils.isNotEmpty(sslVersion)) {
                        connectionFactory.useSslProtocol(sslVersion);
                    } else {
                        log.info("Proceeding with default SSL configuration");
                        connectionFactory.useSslProtocol();
                    }
                } else {
                    char[] keyPassphrase = keyStorePassword.toCharArray();
                    KeyStore ks = KeyStore.getInstance(keyStoreType);
                    ks.load(new FileInputStream(keyStoreLocation), keyPassphrase);

                    KeyManagerFactory kmf = KeyManagerFactory
                            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    kmf.init(ks, keyPassphrase);

                    char[] trustPassphrase = trustStorePassword.toCharArray();
                    KeyStore tks = KeyStore.getInstance(trustStoreType);
                    tks.load(new FileInputStream(trustStoreLocation), trustPassphrase);

                    TrustManagerFactory tmf = TrustManagerFactory
                            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    tmf.init(tks);

                    SSLContext context = SSLContext.getInstance(sslVersion);
                    context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

                    connectionFactory.useSslProtocol(context);
                }
            }
        } catch (IOException e) {
            handleException("TrustStore or KeyStore File path is incorrect. Specify KeyStore location or "
                    + "TrustStore location Correctly.", e);
        } catch (CertificateException e) {
            handleException("TrustStore or keyStore is not specified. So Security certificate"
                    + " Exception happened.  ", e);
        } catch (NoSuchAlgorithmException e) {
            handleException("Algorithm is not available in KeyManagerFactory class.", e);
        } catch (UnrecoverableKeyException e) {
            handleException("Unable to recover Key", e);
        } catch (KeyStoreException e) {
            handleException("Error in KeyStore or TrustStore Type", e);
        } catch (KeyManagementException e) {
            handleException("Error in Key Management", e);
        }
    }

    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_FACTORY_HEARTBEAT))) {
        try {
            int heartbeatValue = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQInputEventAdapterConstants.RABBITMQ_FACTORY_HEARTBEAT));
            connectionFactory.setRequestedHeartbeat(heartbeatValue);
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading heartbeat value. Proceeding with default");
        }
    }
    connectionFactory.setHost(rabbitMQInputEventAdapterConnectionConfiguration.getHostName());
    try {
        int port = Integer.parseInt(rabbitMQInputEventAdapterConnectionConfiguration.getPort());
        if (port > 0) {
            connectionFactory.setPort(port);
        }
    } catch (NumberFormatException e) {
        handleException("Number format error in port number", e);
    }
    connectionFactory.setUsername(rabbitMQInputEventAdapterConnectionConfiguration.getUsername());
    connectionFactory.setPassword(rabbitMQInputEventAdapterConnectionConfiguration.getPassword());
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_SERVER_VIRTUAL_HOST))) {
        connectionFactory.setVirtualHost(eventAdapterConfiguration.getProperties()
                .get(RabbitMQInputEventAdapterConstants.RABBITMQ_SERVER_VIRTUAL_HOST));
    }
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_COUNT))) {
        try {
            retryCountMax = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_COUNT));
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading retry count value. Proceeding with default value (3)", e);
        }
    }
    if (!StringUtils.isEmpty(eventAdapterConfiguration.getProperties()
            .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_INTERVAL))) {
        try {
            retryInterval = Integer.parseInt(eventAdapterConfiguration.getProperties()
                    .get(RabbitMQInputEventAdapterConstants.RABBITMQ_CONNECTION_RETRY_INTERVAL));
        } catch (NumberFormatException e) {
            log.warn("Number format error in reading retry interval value. Proceeding with default value"
                    + " (30000ms)", e);
        }
    }
}