Search in sources :

Example 1 with CredentialsProvider

use of io.quarkus.credentials.CredentialsProvider in project quarkus by quarkusio.

the class DB2PoolRecorder method toConnectOptions.

private DB2ConnectOptions toConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveDB2Config dataSourceReactiveDB2Config) {
    DB2ConnectOptions connectOptions;
    if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
        String url = dataSourceReactiveRuntimeConfig.url.get();
        // clean up the URL to make migrations easier
        if (url.matches("^vertx-reactive:db2://.*$")) {
            url = url.substring("vertx-reactive:".length());
        }
        connectOptions = DB2ConnectOptions.fromUri(url);
    } else {
        connectOptions = new DB2ConnectOptions();
    }
    if (dataSourceRuntimeConfig.username.isPresent()) {
        connectOptions.setUser(dataSourceRuntimeConfig.username.get());
    }
    if (dataSourceRuntimeConfig.password.isPresent()) {
        connectOptions.setPassword(dataSourceRuntimeConfig.password.get());
    }
    // credentials provider
    if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
        String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
        CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
        String name = dataSourceRuntimeConfig.credentialsProvider.get();
        Map<String, String> credentials = credentialsProvider.getCredentials(name);
        String user = credentials.get(USER_PROPERTY_NAME);
        String password = credentials.get(PASSWORD_PROPERTY_NAME);
        if (user != null) {
            connectOptions.setUser(user);
        }
        if (password != null) {
            connectOptions.setPassword(user);
        }
    }
    if (dataSourceReactiveDB2Config.cachePreparedStatements.isPresent()) {
        log.warn("datasource.reactive.db2.cache-prepared-statements is deprecated, use datasource.reactive.cache-prepared-statements instead");
        connectOptions.setCachePreparedStatements(dataSourceReactiveDB2Config.cachePreparedStatements.get());
    } else {
        connectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements);
    }
    connectOptions.setSsl(dataSourceReactiveDB2Config.ssl);
    connectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll);
    configurePemTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePem);
    configureJksTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificateJks);
    configurePfxTrustOptions(connectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePfx);
    configurePemKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePem);
    configureJksKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
    configurePfxKeyCertOptions(connectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);
    connectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);
    connectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());
    if (dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent()) {
        connectOptions.setHostnameVerificationAlgorithm(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get());
    }
    return connectOptions;
}
Also used : DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 2 with CredentialsProvider

use of io.quarkus.credentials.CredentialsProvider in project quarkus by quarkusio.

the class PgPoolRecorder method toPgConnectOptions.

private PgConnectOptions toPgConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactivePostgreSQLConfig dataSourceReactivePostgreSQLConfig) {
    PgConnectOptions pgConnectOptions;
    if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
        String url = dataSourceReactiveRuntimeConfig.url.get();
        // clean up the URL to make migrations easier
        if (url.matches("^vertx-reactive:postgre(?:s|sql)://.*$")) {
            url = url.substring("vertx-reactive:".length());
        }
        pgConnectOptions = PgConnectOptions.fromUri(url);
    } else {
        pgConnectOptions = new PgConnectOptions();
    }
    if (dataSourceRuntimeConfig.username.isPresent()) {
        pgConnectOptions.setUser(dataSourceRuntimeConfig.username.get());
    }
    if (dataSourceRuntimeConfig.password.isPresent()) {
        pgConnectOptions.setPassword(dataSourceRuntimeConfig.password.get());
    }
    // credentials provider
    if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
        String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
        CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
        String name = dataSourceRuntimeConfig.credentialsProvider.get();
        Map<String, String> credentials = credentialsProvider.getCredentials(name);
        String user = credentials.get(USER_PROPERTY_NAME);
        String password = credentials.get(PASSWORD_PROPERTY_NAME);
        if (user != null) {
            pgConnectOptions.setUser(user);
        }
        if (password != null) {
            pgConnectOptions.setPassword(password);
        }
    }
    if (dataSourceReactivePostgreSQLConfig.cachePreparedStatements.isPresent()) {
        log.warn("datasource.reactive.postgresql.cache-prepared-statements is deprecated, use datasource.reactive.cache-prepared-statements instead");
        pgConnectOptions.setCachePreparedStatements(dataSourceReactivePostgreSQLConfig.cachePreparedStatements.get());
    } else {
        pgConnectOptions.setCachePreparedStatements(dataSourceReactiveRuntimeConfig.cachePreparedStatements);
    }
    if (dataSourceReactivePostgreSQLConfig.pipeliningLimit.isPresent()) {
        pgConnectOptions.setPipeliningLimit(dataSourceReactivePostgreSQLConfig.pipeliningLimit.getAsInt());
    }
    if (dataSourceReactivePostgreSQLConfig.sslMode.isPresent()) {
        final SslMode sslMode = dataSourceReactivePostgreSQLConfig.sslMode.get();
        pgConnectOptions.setSslMode(sslMode);
        // If sslMode is verify-full, we also need a hostname verification algorithm
        if (sslMode == SslMode.VERIFY_FULL && (!dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent() || "".equals(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get()))) {
            throw new IllegalArgumentException("quarkus.datasource.reactive.hostname-verification-algorithm must be specified under verify-full sslmode");
        }
    }
    pgConnectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll);
    configurePemTrustOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePem);
    configureJksTrustOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificateJks);
    configurePfxTrustOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePfx);
    configurePemKeyCertOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePem);
    configureJksKeyCertOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
    configurePfxKeyCertOptions(pgConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);
    pgConnectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);
    pgConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());
    if (dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent()) {
        pgConnectOptions.setHostnameVerificationAlgorithm(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get());
    }
    return pgConnectOptions;
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) SslMode(io.vertx.pgclient.SslMode) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 3 with CredentialsProvider

use of io.quarkus.credentials.CredentialsProvider in project quarkus by quarkusio.

the class MSSQLPoolRecorder method toMSSQLConnectOptions.

private MSSQLConnectOptions toMSSQLConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveMSSQLConfig dataSourceReactiveMSSQLConfig) {
    MSSQLConnectOptions mssqlConnectOptions;
    if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
        String url = dataSourceReactiveRuntimeConfig.url.get();
        // clean up the URL to make migrations easier
        if (url.startsWith("vertx-reactive:sqlserver://")) {
            url = url.substring("vertx-reactive:".length());
        }
        mssqlConnectOptions = MSSQLConnectOptions.fromUri(url);
    } else {
        mssqlConnectOptions = new MSSQLConnectOptions();
    }
    if (dataSourceReactiveMSSQLConfig.packetSize.isPresent()) {
        mssqlConnectOptions.setPacketSize(dataSourceReactiveMSSQLConfig.packetSize.getAsInt());
    }
    if (dataSourceRuntimeConfig.username.isPresent()) {
        mssqlConnectOptions.setUser(dataSourceRuntimeConfig.username.get());
    }
    if (dataSourceRuntimeConfig.password.isPresent()) {
        mssqlConnectOptions.setPassword(dataSourceRuntimeConfig.password.get());
    }
    // credentials provider
    if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
        String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
        CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
        String name = dataSourceRuntimeConfig.credentialsProvider.get();
        Map<String, String> credentials = credentialsProvider.getCredentials(name);
        String user = credentials.get(USER_PROPERTY_NAME);
        String password = credentials.get(PASSWORD_PROPERTY_NAME);
        if (user != null) {
            mssqlConnectOptions.setUser(user);
        }
        if (password != null) {
            mssqlConnectOptions.setPassword(password);
        }
    }
    mssqlConnectOptions.setReconnectAttempts(dataSourceReactiveRuntimeConfig.reconnectAttempts);
    mssqlConnectOptions.setReconnectInterval(dataSourceReactiveRuntimeConfig.reconnectInterval.toMillis());
    mssqlConnectOptions.setSsl(dataSourceReactiveMSSQLConfig.ssl);
    mssqlConnectOptions.setTrustAll(dataSourceReactiveRuntimeConfig.trustAll);
    configurePemTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePem);
    configureJksTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificateJks);
    configurePfxTrustOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.trustCertificatePfx);
    configurePemKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePem);
    configureJksKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificateJks);
    configurePfxKeyCertOptions(mssqlConnectOptions, dataSourceReactiveRuntimeConfig.keyCertificatePfx);
    if (dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.isPresent()) {
        mssqlConnectOptions.setHostnameVerificationAlgorithm(dataSourceReactiveRuntimeConfig.hostnameVerificationAlgorithm.get());
    }
    return mssqlConnectOptions;
}
Also used : MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 4 with CredentialsProvider

use of io.quarkus.credentials.CredentialsProvider in project quarkus by quarkusio.

the class OidcCommonUtils method fromCredentialsProvider.

private static Supplier<? extends String> fromCredentialsProvider(Provider provider) {
    return new Supplier<String>() {

        @Override
        public String get() {
            if (provider.key.isPresent()) {
                String providerName = provider.name.orElse(null);
                CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(providerName);
                if (credentialsProvider != null) {
                    return credentialsProvider.getCredentials(providerName).get(provider.key.get());
                }
            }
            return null;
        }
    };
}
Also used : Supplier(java.util.function.Supplier) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Example 5 with CredentialsProvider

use of io.quarkus.credentials.CredentialsProvider in project quarkus by quarkusio.

the class OraclePoolRecorder method toOracleConnectOptions.

private OracleConnectOptions toOracleConnectOptions(DataSourceRuntimeConfig dataSourceRuntimeConfig, DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig, DataSourceReactiveOracleConfig dataSourceReactiveOracleConfig) {
    OracleConnectOptions oracleConnectOptions;
    if (dataSourceReactiveRuntimeConfig.url.isPresent()) {
        String url = dataSourceReactiveRuntimeConfig.url.get();
        // clean up the URL to make migrations easier
        if (url.startsWith("vertx-reactive:oracle:")) {
            url = url.substring("vertx-reactive:".length());
        }
        oracleConnectOptions = OracleConnectOptions.fromUri(url);
    } else {
        oracleConnectOptions = new OracleConnectOptions();
    }
    if (dataSourceRuntimeConfig.username.isPresent()) {
        oracleConnectOptions.setUser(dataSourceRuntimeConfig.username.get());
    }
    if (dataSourceRuntimeConfig.password.isPresent()) {
        oracleConnectOptions.setPassword(dataSourceRuntimeConfig.password.get());
    }
    // credentials provider
    if (dataSourceRuntimeConfig.credentialsProvider.isPresent()) {
        String beanName = dataSourceRuntimeConfig.credentialsProviderName.orElse(null);
        CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(beanName);
        String name = dataSourceRuntimeConfig.credentialsProvider.get();
        Map<String, String> credentials = credentialsProvider.getCredentials(name);
        String user = credentials.get(USER_PROPERTY_NAME);
        String password = credentials.get(PASSWORD_PROPERTY_NAME);
        if (user != null) {
            oracleConnectOptions.setUser(user);
        }
        if (password != null) {
            oracleConnectOptions.setPassword(password);
        }
    }
    return oracleConnectOptions;
}
Also used : OracleConnectOptions(io.vertx.oracleclient.OracleConnectOptions) CredentialsProvider(io.quarkus.credentials.CredentialsProvider)

Aggregations

CredentialsProvider (io.quarkus.credentials.CredentialsProvider)8 ConnectionValidator (io.agroal.api.configuration.AgroalConnectionPoolConfiguration.ConnectionValidator)1 NamePrincipal (io.agroal.api.security.NamePrincipal)1 SimplePassword (io.agroal.api.security.SimplePassword)1 TransactionIntegration (io.agroal.api.transaction.TransactionIntegration)1 NarayanaTransactionIntegration (io.agroal.narayana.NarayanaTransactionIntegration)1 ArcContainer (io.quarkus.arc.ArcContainer)1 DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)1 MSSQLConnectOptions (io.vertx.mssqlclient.MSSQLConnectOptions)1 MySQLConnectOptions (io.vertx.mysqlclient.MySQLConnectOptions)1 SslMode (io.vertx.mysqlclient.SslMode)1 OracleConnectOptions (io.vertx.oracleclient.OracleConnectOptions)1 PgConnectOptions (io.vertx.pgclient.PgConnectOptions)1 SslMode (io.vertx.pgclient.SslMode)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Supplier (java.util.function.Supplier)1