Search in sources :

Example 1 with Ssl

use of com.torodb.packaging.config.model.protocol.mongo.Ssl in project torodb by torodb.

the class MongoClientConfigurationFactory method getMongoClientConfiguration.

public static MongoClientConfiguration getMongoClientConfiguration(AbstractReplication replication) {
    HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
    MongoClientConfiguration.Builder mongoClientConfigurationBuilder = new MongoClientConfiguration.Builder(syncSource);
    Ssl ssl = replication.getSsl();
    mongoClientConfigurationBuilder.setSslEnabled(ssl.getEnabled());
    if (ssl.getEnabled()) {
        try {
            mongoClientConfigurationBuilder.setSslAllowInvalidHostnames(ssl.getAllowInvalidHostnames());
            TrustManager[] tms = getTrustManagers(ssl);
            KeyManager[] kms = getKeyManagers(ssl);
            SSLContext sslContext;
            if (ssl.getFipsMode()) {
                sslContext = SSLContext.getInstance("TLS", "SunPKCS11-NSS");
            } else {
                sslContext = SSLContext.getInstance("TLS");
            }
            sslContext.init(kms, tms, null);
            mongoClientConfigurationBuilder.setSocketFactory(sslContext.getSocketFactory());
        } catch (CertificateException | KeyManagementException | KeyStoreException | UnrecoverableKeyException | NoSuchProviderException | NoSuchAlgorithmException | IOException exception) {
            throw new SystemException(exception);
        }
    }
    Auth auth = replication.getAuth();
    if (auth.getMode().isEnabled()) {
        MongoAuthenticationConfiguration mongoAuthenticationConfiguration = getMongoAuthenticationConfiguration(auth, ssl);
        mongoClientConfigurationBuilder.addAuthenticationConfiguration(mongoAuthenticationConfiguration);
    }
    return mongoClientConfigurationBuilder.build();
}
Also used : MongoAuthenticationConfiguration(com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MongoClientConfiguration(com.eightkdata.mongowp.client.wrapper.MongoClientConfiguration) Ssl(com.torodb.packaging.config.model.protocol.mongo.Ssl) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) HostAndPort(com.google.common.net.HostAndPort) UnrecoverableKeyException(java.security.UnrecoverableKeyException) SystemException(com.torodb.core.exceptions.SystemException) Auth(com.torodb.packaging.config.model.protocol.mongo.Auth) NoSuchProviderException(java.security.NoSuchProviderException) KeyManager(javax.net.ssl.KeyManager)

Aggregations

MongoAuthenticationConfiguration (com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration)1 MongoClientConfiguration (com.eightkdata.mongowp.client.wrapper.MongoClientConfiguration)1 HostAndPort (com.google.common.net.HostAndPort)1 SystemException (com.torodb.core.exceptions.SystemException)1 Auth (com.torodb.packaging.config.model.protocol.mongo.Auth)1 Ssl (com.torodb.packaging.config.model.protocol.mongo.Ssl)1 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1