use of com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration in project torodb by torodb.
the class MongoClientConfigurationFactory method getMongoAuthenticationConfiguration.
private static MongoAuthenticationConfiguration getMongoAuthenticationConfiguration(Auth auth, Ssl ssl) {
AuthMode authMode = auth.getMode();
MongoAuthenticationConfiguration.Builder mongoAuthenticationConfigurationBuilder = new MongoAuthenticationConfiguration.Builder(mongoAuthenticationMechanismConverter.get(authMode).apply(authMode));
mongoAuthenticationConfigurationBuilder.setUser(auth.getUser());
mongoAuthenticationConfigurationBuilder.setSource(auth.getSource());
mongoAuthenticationConfigurationBuilder.setPassword(auth.getPassword());
if (authMode == AuthMode.x509 && auth.getUser() == null) {
try {
KeyStore ks = getKeyStore(ssl);
X509Certificate certificate = (X509Certificate) ks.getCertificate(ks.aliases().nextElement());
mongoAuthenticationConfigurationBuilder.setUser(Arrays.asList(certificate.getSubjectDN().getName().split(",")).stream().map(dn -> dn.trim()).collect(Collectors.joining(",")));
} catch (CertificateException | KeyStoreException | NoSuchAlgorithmException | IOException exception) {
throw new SystemException(exception);
}
}
return mongoAuthenticationConfigurationBuilder.build();
}
use of com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration 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();
}
Aggregations