use of com.torodb.packaging.config.model.protocol.mongo.AuthMode 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();
}
Aggregations