Search in sources :

Example 1 with AuthMode

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();
}
Also used : MongoAuthenticationConfiguration(com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration) SystemException(com.torodb.core.exceptions.SystemException) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) AuthMode(com.torodb.packaging.config.model.protocol.mongo.AuthMode) X509Certificate(java.security.cert.X509Certificate)

Aggregations

MongoAuthenticationConfiguration (com.eightkdata.mongowp.client.wrapper.MongoAuthenticationConfiguration)1 SystemException (com.torodb.core.exceptions.SystemException)1 AuthMode (com.torodb.packaging.config.model.protocol.mongo.AuthMode)1 IOException (java.io.IOException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1