Search in sources :

Example 1 with DsSecurity

use of org.jboss.as.connector.metadata.api.ds.DsSecurity in project wildfly by wildfly.

the class DataSourceModelNodeUtil method from.

static ModifiableDataSource from(final OperationContext operationContext, final ModelNode dataSourceNode, final String dsName, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier) throws OperationFailedException, ValidateException {
    final Map<String, String> connectionProperties = Collections.emptyMap();
    final String connectionUrl = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTION_URL);
    final String driverClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DRIVER_CLASS);
    final String dataSourceClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_CLASS);
    final String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, JNDI_NAME);
    final String driver = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_DRIVER);
    final String newConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, NEW_CONNECTION_SQL);
    final String poolName = dsName;
    final String urlDelimiter = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_DELIMITER);
    final String urlSelectorStrategyClassName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_SELECTOR_STRATEGY_CLASS_NAME);
    final boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_JAVA_CONTEXT);
    final boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENABLED);
    final boolean connectable = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTABLE);
    final Boolean tracking = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, TRACKING);
    final Boolean enlistmentTrace = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENLISTMENT_TRACE);
    final String mcp = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, MCP);
    final boolean jta = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, JTA);
    final Integer maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MAX_POOL_SIZE);
    final Integer minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MIN_POOL_SIZE);
    final Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, INITIAL_POOL_SIZE);
    final boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_PREFILL);
    final boolean fair = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FAIR);
    final boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_USE_STRICT_MIN);
    final String flushStrategyString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FLUSH_STRATEGY);
    // TODO relax case sensitivity
    final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString);
    final Boolean allowMultipleUsers = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ALLOW_MULTIPLE_USERS);
    Extension incrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES);
    Extension decrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES);
    final Capacity capacity = new Capacity(incrementer, decrementer);
    final Extension connectionListener = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES);
    final DsPool pool = new DsPoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, allowMultipleUsers, capacity, fair, connectionListener);
    final String username = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, USERNAME);
    final String password = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, PASSWORD);
    final String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, SECURITY_DOMAIN);
    final boolean elytronEnabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ELYTRON_ENABLED);
    final String authenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, AUTHENTICATION_CONTEXT);
    final Extension reauthPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES);
    final DsSecurity security = new DsSecurityImpl(username, password, elytronEnabled ? authenticationContext : securityDomain, elytronEnabled, credentialSourceSupplier, reauthPlugin);
    final boolean sharePreparedStatements = SHARE_PREPARED_STATEMENTS.resolveModelAttribute(operationContext, dataSourceNode).asBoolean();
    final Long preparedStatementsCacheSize = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, PREPARED_STATEMENTS_CACHE_SIZE);
    final String trackStatementsString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRACK_STATEMENTS);
    final Statement.TrackStatementsEnum trackStatements = Statement.TrackStatementsEnum.valueOf(trackStatementsString.toUpperCase(Locale.ENGLISH));
    final Statement statement = new StatementImpl(sharePreparedStatements, preparedStatementsCacheSize, trackStatements);
    final Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY);
    final Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY_WAIT_MILLIS);
    final Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BLOCKING_TIMEOUT_WAIT_MILLIS);
    final Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, IDLETIMEOUTMINUTES);
    final Long queryTimeout = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, QUERY_TIMEOUT);
    final Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, XA_RESOURCE_TIMEOUT);
    final Long useTryLock = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, USE_TRY_LOCK);
    final boolean setTxQueryTimeout = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SET_TX_QUERY_TIMEOUT);
    final TimeOut timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock);
    final String transactionIsolationString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRANSACTION_ISOLATION);
    TransactionIsolation transactionIsolation = null;
    if (transactionIsolationString != null) {
        // TODO relax case sensitivity
        transactionIsolation = TransactionIsolation.forName(transactionIsolationString);
        if (transactionIsolation == null) {
            transactionIsolation = TransactionIsolation.customLevel(transactionIsolationString);
        }
    }
    final String checkValidConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CHECK_VALID_CONNECTION_SQL);
    final Extension exceptionSorter = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_PROPERTIES);
    final Extension staleConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_PROPERTIES);
    final Extension validConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_PROPERTIES);
    Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATIONMILLIS);
    final Boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATION);
    boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_FAST_FAIL);
    final Boolean validateOnMatch = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, VALIDATE_ON_MATCH);
    final boolean spy = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SPY);
    final boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_CCM);
    final Validation validation = new ValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail, validConnectionChecker, checkValidConnectionSql, validateOnMatch, staleConnectionChecker, exceptionSorter);
    return new ModifiableDataSource(connectionUrl, driverClass, dataSourceClass, driver, transactionIsolation, connectionProperties, timeOut, security, statement, validation, urlDelimiter, urlSelectorStrategyClassName, newConnectionSql, useJavaContext, poolName, enabled, jndiName, spy, useCcm, jta, connectable, tracking, mcp, enlistmentTrace, pool);
}
Also used : Validation(org.jboss.jca.common.api.metadata.ds.Validation) DsSecurity(org.jboss.as.connector.metadata.api.ds.DsSecurity) Statement(org.jboss.jca.common.api.metadata.ds.Statement) TimeOut(org.jboss.jca.common.api.metadata.ds.TimeOut) TransactionIsolation(org.jboss.jca.common.api.metadata.ds.TransactionIsolation) DsPool(org.jboss.jca.common.api.metadata.ds.DsPool) ValidationImpl(org.jboss.jca.common.metadata.ds.ValidationImpl) Extension(org.jboss.jca.common.api.metadata.common.Extension) Capacity(org.jboss.jca.common.api.metadata.common.Capacity) FlushStrategy(org.jboss.jca.common.api.metadata.common.FlushStrategy) DsSecurityImpl(org.jboss.as.connector.metadata.ds.DsSecurityImpl) StatementImpl(org.jboss.jca.common.metadata.ds.StatementImpl) DsPoolImpl(org.jboss.jca.common.metadata.ds.DsPoolImpl) TimeOutImpl(org.jboss.jca.common.metadata.ds.TimeOutImpl)

Example 2 with DsSecurity

use of org.jboss.as.connector.metadata.api.ds.DsSecurity in project wildfly by wildfly.

the class DataSourceModelNodeUtil method xaFrom.

static ModifiableXaDataSource xaFrom(final OperationContext operationContext, final ModelNode dataSourceNode, final String dsName, final ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier, final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceSupplier) throws OperationFailedException, ValidateException {
    final Map<String, String> xaDataSourceProperty;
    xaDataSourceProperty = Collections.emptyMap();
    final String xaDataSourceClass = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, XA_DATASOURCE_CLASS);
    final String jndiName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, JNDI_NAME);
    final String module = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, DATASOURCE_DRIVER);
    final String newConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, NEW_CONNECTION_SQL);
    final String poolName = dsName;
    final String urlDelimiter = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_DELIMITER);
    final String urlSelectorStrategyClassName = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_SELECTOR_STRATEGY_CLASS_NAME);
    final Boolean useJavaContext = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_JAVA_CONTEXT);
    final Boolean enabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENABLED);
    final boolean connectable = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, CONNECTABLE);
    final Boolean tracking = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, TRACKING);
    final Boolean enlistmentTrace = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ENLISTMENT_TRACE);
    final String mcp = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, MCP);
    final Integer maxPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MAX_POOL_SIZE);
    final Integer minPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, MIN_POOL_SIZE);
    final Integer initialPoolSize = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, INITIAL_POOL_SIZE);
    final Boolean prefill = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_PREFILL);
    final Boolean fair = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FAIR);
    final Boolean useStrictMin = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, POOL_USE_STRICT_MIN);
    final Boolean interleaving = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, INTERLEAVING);
    final Boolean noTxSeparatePool = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, NO_TX_SEPARATE_POOL);
    final Boolean padXid = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, PAD_XID);
    final Boolean isSameRmOverride = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SAME_RM_OVERRIDE);
    final Boolean wrapXaDataSource = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, WRAP_XA_RESOURCE);
    final String flushStrategyString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, POOL_FLUSH_STRATEGY);
    // TODO relax case sensitivity
    final FlushStrategy flushStrategy = FlushStrategy.forName(flushStrategyString);
    final Boolean allowMultipleUsers = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ALLOW_MULTIPLE_USERS);
    Extension incrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_INCREMENTER_CLASS, CAPACITY_INCREMENTER_PROPERTIES);
    Extension decrementer = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CAPACITY_DECREMENTER_CLASS, CAPACITY_DECREMENTER_PROPERTIES);
    final Capacity capacity = new Capacity(incrementer, decrementer);
    final Extension connectionListener = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, CONNECTION_LISTENER_CLASS, CONNECTION_LISTENER_PROPERTIES);
    final DsXaPool xaPool = new DsXaPoolImpl(minPoolSize, initialPoolSize, maxPoolSize, prefill, useStrictMin, flushStrategy, isSameRmOverride, interleaving, padXid, wrapXaDataSource, noTxSeparatePool, allowMultipleUsers, capacity, fair, connectionListener);
    final String username = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, USERNAME);
    final String password = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, PASSWORD);
    final String securityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, SECURITY_DOMAIN);
    final boolean elytronEnabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, ELYTRON_ENABLED);
    final String authenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, AUTHENTICATION_CONTEXT);
    final Extension reauthPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, REAUTH_PLUGIN_CLASSNAME, REAUTHPLUGIN_PROPERTIES);
    final DsSecurity security = new DsSecurityImpl(username, password, elytronEnabled ? authenticationContext : securityDomain, elytronEnabled, credentialSourceSupplier, reauthPlugin);
    final boolean sharePreparedStatements = SHARE_PREPARED_STATEMENTS.resolveModelAttribute(operationContext, dataSourceNode).asBoolean();
    final Long preparedStatementsCacheSize = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, PREPARED_STATEMENTS_CACHE_SIZE);
    final String trackStatementsString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRACK_STATEMENTS);
    final Statement.TrackStatementsEnum trackStatements = Statement.TrackStatementsEnum.valueOf(trackStatementsString.toUpperCase(Locale.ENGLISH));
    final Statement statement = new StatementImpl(sharePreparedStatements, preparedStatementsCacheSize, trackStatements);
    final Integer allocationRetry = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY);
    final Long allocationRetryWaitMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, ALLOCATION_RETRY_WAIT_MILLIS);
    final Long blockingTimeoutMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BLOCKING_TIMEOUT_WAIT_MILLIS);
    final Long idleTimeoutMinutes = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, IDLETIMEOUTMINUTES);
    final Long queryTimeout = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, QUERY_TIMEOUT);
    final Integer xaResourceTimeout = ModelNodeUtil.getIntIfSetOrGetDefault(operationContext, dataSourceNode, XA_RESOURCE_TIMEOUT);
    final Long useTryLock = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, USE_TRY_LOCK);
    final Boolean setTxQueryTimeout = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SET_TX_QUERY_TIMEOUT);
    final TimeOut timeOut = new TimeOutImpl(blockingTimeoutMillis, idleTimeoutMinutes, allocationRetry, allocationRetryWaitMillis, xaResourceTimeout, setTxQueryTimeout, queryTimeout, useTryLock);
    final String transactionIsolationString = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, TRANSACTION_ISOLATION);
    TransactionIsolation transactionIsolation = null;
    if (transactionIsolationString != null) {
        // TODO relax case sensitivity
        transactionIsolation = TransactionIsolation.forName(transactionIsolationString);
        if (transactionIsolation == null) {
            transactionIsolation = TransactionIsolation.customLevel(transactionIsolationString);
        }
    }
    final String checkValidConnectionSql = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, CHECK_VALID_CONNECTION_SQL);
    final Extension exceptionSorter = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, EXCEPTION_SORTER_CLASSNAME, EXCEPTION_SORTER_PROPERTIES);
    final Extension staleConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, STALE_CONNECTION_CHECKER_CLASSNAME, STALE_CONNECTION_CHECKER_PROPERTIES);
    final Extension validConnectionChecker = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, VALID_CONNECTION_CHECKER_CLASSNAME, VALID_CONNECTION_CHECKER_PROPERTIES);
    Long backgroundValidationMillis = ModelNodeUtil.getLongIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATIONMILLIS);
    final Boolean backgroundValidation = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, BACKGROUNDVALIDATION);
    boolean useFastFail = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_FAST_FAIL);
    final Boolean validateOnMatch = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, VALIDATE_ON_MATCH);
    final Boolean spy = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, SPY);
    final Boolean useCcm = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, USE_CCM);
    final Validation validation = new ValidationImpl(backgroundValidation, backgroundValidationMillis, useFastFail, validConnectionChecker, checkValidConnectionSql, validateOnMatch, staleConnectionChecker, exceptionSorter);
    final String recoveryUsername = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_USERNAME);
    final String recoveryPassword = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_PASSWORD);
    final String recoverySecurityDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_SECURITY_DOMAIN);
    final boolean recoveryElytronEnabled = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_ELYTRON_ENABLED);
    final String recoveryAuthenticationContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, RECOVERY_AUTHENTICATION_CONTEXT);
    Boolean noRecovery = ModelNodeUtil.getBooleanIfSetOrGetDefault(operationContext, dataSourceNode, NO_RECOVERY);
    final String urlProperty = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(operationContext, dataSourceNode, URL_PROPERTY);
    Recovery recovery = null;
    if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoverySecurityDomain != null || noRecovery != null) {
        Credential credential = null;
        if ((recoveryUsername != null && (recoveryPassword != null || recoveryCredentialSourceSupplier != null)) || recoverySecurityDomain != null)
            credential = new CredentialImpl(recoveryUsername, recoveryPassword, recoveryElytronEnabled ? recoveryAuthenticationContext : recoverySecurityDomain, elytronEnabled, recoveryCredentialSourceSupplier);
        Extension recoverPlugin = ModelNodeUtil.extractExtension(operationContext, dataSourceNode, RECOVER_PLUGIN_CLASSNAME, RECOVER_PLUGIN_PROPERTIES);
        if (noRecovery == null)
            noRecovery = Boolean.FALSE;
        recovery = new Recovery(credential, recoverPlugin, noRecovery);
    }
    return new ModifiableXaDataSource(transactionIsolation, timeOut, security, statement, validation, urlDelimiter, urlProperty, urlSelectorStrategyClassName, useJavaContext, poolName, enabled, jndiName, spy, useCcm, connectable, tracking, mcp, enlistmentTrace, xaDataSourceProperty, xaDataSourceClass, module, newConnectionSql, xaPool, recovery);
}
Also used : TimeOut(org.jboss.jca.common.api.metadata.ds.TimeOut) TransactionIsolation(org.jboss.jca.common.api.metadata.ds.TransactionIsolation) Recovery(org.jboss.jca.common.api.metadata.common.Recovery) ValidationImpl(org.jboss.jca.common.metadata.ds.ValidationImpl) Capacity(org.jboss.jca.common.api.metadata.common.Capacity) DsXaPool(org.jboss.jca.common.api.metadata.ds.DsXaPool) StatementImpl(org.jboss.jca.common.metadata.ds.StatementImpl) Validation(org.jboss.jca.common.api.metadata.ds.Validation) Credential(org.jboss.as.connector.metadata.api.common.Credential) DsSecurity(org.jboss.as.connector.metadata.api.ds.DsSecurity) Statement(org.jboss.jca.common.api.metadata.ds.Statement) Extension(org.jboss.jca.common.api.metadata.common.Extension) CredentialImpl(org.jboss.as.connector.metadata.common.CredentialImpl) FlushStrategy(org.jboss.jca.common.api.metadata.common.FlushStrategy) DsSecurityImpl(org.jboss.as.connector.metadata.ds.DsSecurityImpl) DsXaPoolImpl(org.jboss.jca.common.metadata.ds.DsXaPoolImpl) TimeOutImpl(org.jboss.jca.common.metadata.ds.TimeOutImpl)

Example 3 with DsSecurity

use of org.jboss.as.connector.metadata.api.ds.DsSecurity in project wildfly by wildfly.

the class XMLXaDataSourceRuntimeHandler method handleDatasourceAttribute.

private void handleDatasourceAttribute(final String attributeName, final OperationContext context, final XaDataSource dataSource) {
    if (attributeName.equals(Constants.XA_DATASOURCE_CLASS.getName())) {
        setStringIfNotNull(context, dataSource.getXaDataSourceClass());
    } else if (attributeName.equals(Constants.JNDI_NAME.getName())) {
        setStringIfNotNull(context, dataSource.getJndiName());
    } else if (attributeName.equals(Constants.DATASOURCE_DRIVER.getName())) {
        setStringIfNotNull(context, dataSource.getDriver());
    } else if (attributeName.equals(Constants.NEW_CONNECTION_SQL.getName())) {
        setStringIfNotNull(context, dataSource.getNewConnectionSql());
    } else if (attributeName.equals(Constants.URL_DELIMITER.getName())) {
        setStringIfNotNull(context, dataSource.getUrlDelimiter());
    } else if (attributeName.equals(Constants.URL_PROPERTY.getName())) {
        setStringIfNotNull(context, dataSource.getUrlProperty());
    } else if (attributeName.equals(Constants.URL_SELECTOR_STRATEGY_CLASS_NAME.getName())) {
        setStringIfNotNull(context, dataSource.getUrlSelectorStrategyClassName());
    } else if (attributeName.equals(Constants.USE_JAVA_CONTEXT.getName())) {
        setBooleanIfNotNull(context, dataSource.isUseJavaContext());
    } else if (attributeName.equals(Constants.ENABLED.getName())) {
        setBooleanIfNotNull(context, dataSource.isEnabled());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getXaPool().getMaxPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getXaPool().getInitialPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getXaPool().getMinPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isPrefill());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isFair());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isUseStrictMin());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        if (dataSource.getXaPool().getFlushStrategy() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getXaPool().getFlushStrategy().getName());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS.getName())) {
        if (dataSource.getXaPool() == null || dataSource.getXaPool().getCapacity() == null || dataSource.getXaPool().getCapacity().getIncrementer() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getXaPool().getCapacity().getIncrementer().getClassName());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS.getName())) {
        if (dataSource.getXaPool() == null || dataSource.getXaPool().getCapacity() == null || dataSource.getXaPool().getCapacity().getDecrementer() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getXaPool().getCapacity().getDecrementer().getClassName());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES.getName())) {
        XaPool pool = dataSource.getXaPool();
        if (pool == null || pool.getCapacity() == null || pool.getCapacity().getIncrementer() == null)
            return;
        final Map<String, String> propertiesMap = pool.getCapacity().getIncrementer().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES.getName())) {
        XaPool pool = dataSource.getXaPool();
        if (pool == null || pool.getCapacity() == null || pool.getCapacity().getDecrementer() == null)
            return;
        final Map<String, String> propertiesMap = pool.getCapacity().getDecrementer().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.INTERLEAVING.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isInterleaving());
    } else if (attributeName.equals(Constants.NO_TX_SEPARATE_POOL.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isNoTxSeparatePool());
    } else if (attributeName.equals(Constants.PAD_XID.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isPadXid());
    } else if (attributeName.equals(Constants.SAME_RM_OVERRIDE.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isSameRmOverride());
    } else if (attributeName.equals(Constants.WRAP_XA_RESOURCE.getName())) {
        if (dataSource.getXaPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getXaPool().isWrapXaResource());
    } else if (attributeName.equals(Constants.PREPARED_STATEMENTS_CACHE_SIZE.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getStatement().getPreparedStatementsCacheSize());
    } else if (attributeName.equals(Constants.SHARE_PREPARED_STATEMENTS.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getStatement().isSharePreparedStatements());
    } else if (attributeName.equals(Constants.TRACK_STATEMENTS.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        if (dataSource.getStatement().getTrackStatements() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getStatement().getTrackStatements().name());
    } else if (attributeName.equals(Constants.ALLOCATION_RETRY.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getTimeOut().getAllocationRetry());
    } else if (attributeName.equals(Constants.ALLOCATION_RETRY_WAIT_MILLIS.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getAllocationRetryWaitMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getBlockingTimeoutMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getIdleTimeoutMinutes());
    } else if (attributeName.equals(Constants.XA_RESOURCE_TIMEOUT.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getTimeOut().getXaResourceTimeout());
    } else if (attributeName.equals(Constants.RECOVERY_USERNAME.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getCredential() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getRecovery().getCredential().getUserName());
    } else if (attributeName.equals(Constants.RECOVERY_PASSWORD.getName())) {
    // don't display the password
    } else if (attributeName.equals(Constants.RECOVERY_SECURITY_DOMAIN.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getCredential() == null) {
            return;
        }
        // safe assertion because all parsers create jboss Credential
        assert dataSource.getRecovery().getCredential() instanceof Credential;
        if (((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getRecovery().getCredential().getSecurityDomain());
    } else if (attributeName.equals(Constants.RECOVERY_ELYTRON_ENABLED.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getCredential() == null) {
            return;
        }
        // safe assertion because all parsers create jboss Credential
        assert dataSource.getRecovery().getCredential() instanceof Credential;
        if (!((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
            return;
        }
        setBooleanIfNotNull(context, ((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled());
    } else if (attributeName.equals(Constants.RECOVERY_CREDENTIAL_REFERENCE.getName())) {
    // don't give out the credential-reference
    } else if (attributeName.equals(Constants.RECOVERY_AUTHENTICATION_CONTEXT.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getCredential() == null) {
            return;
        }
        // safe assertion because all parsers create jboss Credential
        assert dataSource.getRecovery().getCredential() instanceof Credential;
        if (!((Credential) dataSource.getRecovery().getCredential()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getRecovery().getCredential().getSecurityDomain());
    } else if (attributeName.equals(Constants.RECOVER_PLUGIN_CLASSNAME.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getRecoverPlugin() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getRecovery().getRecoverPlugin().getClassName());
    } else if (attributeName.equals(Constants.RECOVER_PLUGIN_PROPERTIES.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        if (dataSource.getRecovery().getRecoverPlugin() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getRecovery().getRecoverPlugin().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.NO_RECOVERY.getName())) {
        if (dataSource.getRecovery() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getRecovery().getNoRecovery());
    } else if (attributeName.equals(Constants.CHECK_VALID_CONNECTION_SQL.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getCheckValidConnectionSql());
    } else if (attributeName.equals(Constants.EXCEPTION_SORTER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getExceptionSorter() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getExceptionSorter().getClassName());
    } else if (attributeName.equals(Constants.EXCEPTION_SORTER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getExceptionSorter() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getExceptionSorter().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getStaleConnectionChecker() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getStaleConnectionChecker().getClassName());
    } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getStaleConnectionChecker() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getStaleConnectionChecker().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getValidConnectionChecker() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getValidConnectionChecker().getClassName());
    } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getValidConnectionChecker() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getValidConnectionChecker().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getValidation().getBackgroundValidationMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isBackgroundValidation());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isUseFastFail());
    } else if (attributeName.equals(Constants.VALIDATE_ON_MATCH.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isValidateOnMatch());
    } else if (attributeName.equals(Constants.USERNAME.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getUserName());
    } else if (attributeName.equals(Constants.PASSWORD.getName())) {
    // don't give out the password
    } else if (attributeName.equals(Constants.CREDENTIAL_REFERENCE.getName())) {
    // don't give out the credential-reference
    } else if (attributeName.equals(Constants.SECURITY_DOMAIN.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain());
    } else if (attributeName.equals(Constants.ELYTRON_ENABLED.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setBooleanIfNotNull(context, ((DsSecurity) dataSource.getSecurity()).isElytronEnabled());
    } else if (attributeName.equals(Constants.AUTHENTICATION_CONTEXT.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain());
    } else if (attributeName.equals(Constants.REAUTH_PLUGIN_CLASSNAME.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        if (dataSource.getSecurity().getReauthPlugin() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getReauthPlugin().getClassName());
    } else if (attributeName.equals(Constants.REAUTHPLUGIN_PROPERTIES.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        if (dataSource.getSecurity().getReauthPlugin() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getSecurity().getReauthPlugin().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.QUERY_TIMEOUT.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getQueryTimeout());
    } else if (attributeName.equals(Constants.USE_TRY_LOCK.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getUseTryLock());
    } else if (attributeName.equals(Constants.SET_TX_QUERY_TIMEOUT.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getTimeOut().isSetTxQueryTimeout());
    } else if (attributeName.equals(Constants.TRANSACTION_ISOLATION.getName())) {
        if (dataSource.getTransactionIsolation() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getTransactionIsolation().name());
    } else if (attributeName.equals(Constants.SPY.getName())) {
        setBooleanIfNotNull(context, dataSource.isSpy());
    } else if (attributeName.equals(Constants.USE_CCM.getName())) {
        setBooleanIfNotNull(context, dataSource.isUseCcm());
    } else if (attributeName.equals(Constants.JTA.getName())) {
        setBooleanIfNotNull(context, true);
    } else if (attributeName.equals(Constants.ALLOW_MULTIPLE_USERS.getName())) {
        XaPool pool = dataSource.getXaPool();
        if (!(pool instanceof DsXaPool)) {
            return;
        }
        setBooleanIfNotNull(context, ((DsXaPool) pool).isAllowMultipleUsers());
    } else if (attributeName.equals(Constants.CONNECTION_LISTENER_CLASS.getName())) {
        XaPool pool = dataSource.getXaPool();
        if (!(pool instanceof DsXaPool) || ((DsXaPool) pool).getConnectionListener() == null) {
            return;
        }
        setStringIfNotNull(context, ((DsXaPool) pool).getConnectionListener().getClassName());
    } else if (attributeName.equals(Constants.CONNECTION_LISTENER_PROPERTIES.getName())) {
        XaPool pool = dataSource.getXaPool();
        if (!(pool instanceof DsXaPool) || ((DsXaPool) pool).getConnectionListener() == null) {
            return;
        }
        final Map<String, String> propertiesMap = ((DsXaPool) pool).getConnectionListener().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.CONNECTABLE.getName())) {
        // Just set to false
        context.getResult().set(false);
    } else if (attributeName.equals(Constants.STATISTICS_ENABLED.getName())) {
        // Just set to false
        context.getResult().set(false);
    } else if (attributeName.equals(Constants.TRACKING.getName())) {
        // Just return w/o setting a result
        return;
    } else if (attributeName.equals(Constants.MCP.getName())) {
        // Just return w/o setting a result
        return;
    } else if (attributeName.equals(Constants.ENLISTMENT_TRACE.getName())) {
        // Just return w/o setting a result
        return;
    } else {
        throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName);
    }
}
Also used : DsXaPool(org.jboss.jca.common.api.metadata.ds.DsXaPool) XaPool(org.jboss.jca.common.api.metadata.common.XaPool) Credential(org.jboss.as.connector.metadata.api.common.Credential) DsSecurity(org.jboss.as.connector.metadata.api.ds.DsSecurity) DsXaPool(org.jboss.jca.common.api.metadata.ds.DsXaPool) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 4 with DsSecurity

use of org.jboss.as.connector.metadata.api.ds.DsSecurity in project wildfly by wildfly.

the class XMLDataSourceRuntimeHandler method handleDatasourceAttribute.

private void handleDatasourceAttribute(final String attributeName, final OperationContext context, final DataSource dataSource) {
    if (attributeName.equals(Constants.CONNECTION_URL.getName())) {
        setStringIfNotNull(context, dataSource.getConnectionUrl());
    } else if (attributeName.equals(Constants.CONNECTION_PROPERTIES.getName())) {
        final Map<String, String> propertiesMap = dataSource.getConnectionProperties();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.DRIVER_CLASS.getName())) {
        setStringIfNotNull(context, dataSource.getDriverClass());
    } else if (attributeName.equals(Constants.DATASOURCE_CLASS.getName())) {
        setStringIfNotNull(context, dataSource.getDataSourceClass());
    } else if (attributeName.equals(Constants.JNDI_NAME.getName())) {
        setStringIfNotNull(context, dataSource.getJndiName());
    } else if (attributeName.equals(Constants.DATASOURCE_DRIVER.getName())) {
        setStringIfNotNull(context, dataSource.getDriver());
    } else if (attributeName.equals(Constants.NEW_CONNECTION_SQL.getName())) {
        setStringIfNotNull(context, dataSource.getNewConnectionSql());
    } else if (attributeName.equals(Constants.URL_DELIMITER.getName())) {
        setStringIfNotNull(context, dataSource.getUrlDelimiter());
    } else if (attributeName.equals(Constants.URL_SELECTOR_STRATEGY_CLASS_NAME.getName())) {
        setStringIfNotNull(context, dataSource.getUrlSelectorStrategyClassName());
    } else if (attributeName.equals(Constants.USE_JAVA_CONTEXT.getName())) {
        setBooleanIfNotNull(context, dataSource.isUseJavaContext());
    } else if (attributeName.equals(Constants.JTA.getName())) {
        setBooleanIfNotNull(context, dataSource.isJTA());
    } else if (attributeName.equals(Constants.ENABLED.getName())) {
        setBooleanIfNotNull(context, dataSource.isEnabled());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MAX_POOL_SIZE.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getPool().getMaxPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.INITIAL_POOL_SIZE.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getPool().getInitialPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.MIN_POOL_SIZE.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getPool().getMinPoolSize());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_PREFILL.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getPool().isPrefill());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FAIR.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getPool().isFair());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_USE_STRICT_MIN.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getPool().isUseStrictMin());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_CLASS.getName())) {
        if (dataSource.getPool() == null || dataSource.getPool().getCapacity() == null || dataSource.getPool().getCapacity().getIncrementer() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getPool().getCapacity().getIncrementer().getClassName());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_CLASS.getName())) {
        if (dataSource.getPool() == null || dataSource.getPool().getCapacity() == null || dataSource.getPool().getCapacity().getDecrementer() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getPool().getCapacity().getDecrementer().getClassName());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES.getName())) {
        Pool pool = dataSource.getPool();
        if (pool == null || pool.getCapacity() == null || pool.getCapacity().getIncrementer() == null)
            return;
        final Map<String, String> propertiesMap = pool.getCapacity().getIncrementer().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES.getName())) {
        Pool pool = dataSource.getPool();
        if (pool == null || pool.getCapacity() == null || pool.getCapacity().getDecrementer() == null)
            return;
        final Map<String, String> propertiesMap = pool.getCapacity().getDecrementer().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.USERNAME.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getUserName());
    } else if (attributeName.equals(Constants.PASSWORD.getName())) {
    // don't give out the password
    } else if (attributeName.equals(Constants.CREDENTIAL_REFERENCE.getName())) {
    // don't give out the credential-reference
    } else if (attributeName.equals(Constants.SECURITY_DOMAIN.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain());
    } else if (attributeName.equals(Constants.ELYTRON_ENABLED.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setBooleanIfNotNull(context, ((DsSecurity) dataSource.getSecurity()).isElytronEnabled());
    } else if (attributeName.equals(Constants.AUTHENTICATION_CONTEXT.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        // this is a safe assert because DsXmlParser will always create a wildfly DsSecurity metadata
        assert dataSource.getSecurity() instanceof DsSecurity;
        if (!((DsSecurity) dataSource.getSecurity()).isElytronEnabled()) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getSecurityDomain());
    } else if (attributeName.equals(Constants.REAUTH_PLUGIN_CLASSNAME.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        if (dataSource.getSecurity().getReauthPlugin() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getSecurity().getReauthPlugin().getClassName());
    } else if (attributeName.equals(Constants.REAUTHPLUGIN_PROPERTIES.getName())) {
        if (dataSource.getSecurity() == null) {
            return;
        }
        if (dataSource.getSecurity().getReauthPlugin() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getSecurity().getReauthPlugin().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_FLUSH_STRATEGY.getName())) {
        if (dataSource.getPool() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getPool().getFlushStrategy().getName());
    } else if (attributeName.equals(Constants.PREPARED_STATEMENTS_CACHE_SIZE.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getStatement().getPreparedStatementsCacheSize());
    } else if (attributeName.equals(Constants.SHARE_PREPARED_STATEMENTS.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getStatement().isSharePreparedStatements());
    } else if (attributeName.equals(Constants.TRACK_STATEMENTS.getName())) {
        if (dataSource.getStatement() == null) {
            return;
        }
        if (dataSource.getStatement().getTrackStatements() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getStatement().getTrackStatements().name());
    } else if (attributeName.equals(Constants.ALLOCATION_RETRY.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setIntIfNotNull(context, dataSource.getTimeOut().getAllocationRetry());
    } else if (attributeName.equals(Constants.ALLOCATION_RETRY_WAIT_MILLIS.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getAllocationRetryWaitMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BLOCKING_TIMEOUT_WAIT_MILLIS.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getBlockingTimeoutMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.IDLETIMEOUTMINUTES.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getIdleTimeoutMinutes());
    } else if (attributeName.equals(Constants.QUERY_TIMEOUT.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getQueryTimeout());
    } else if (attributeName.equals(Constants.USE_TRY_LOCK.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getTimeOut().getUseTryLock());
    } else if (attributeName.equals(Constants.SET_TX_QUERY_TIMEOUT.getName())) {
        if (dataSource.getTimeOut() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getTimeOut().isSetTxQueryTimeout());
    } else if (attributeName.equals(Constants.TRANSACTION_ISOLATION.getName())) {
        if (dataSource.getTransactionIsolation() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getTransactionIsolation().name());
    } else if (attributeName.equals(Constants.CHECK_VALID_CONNECTION_SQL.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getCheckValidConnectionSql());
    } else if (attributeName.equals(Constants.EXCEPTION_SORTER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getExceptionSorter() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getExceptionSorter().getClassName());
    } else if (attributeName.equals(Constants.EXCEPTION_SORTER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getExceptionSorter() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getExceptionSorter().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getStaleConnectionChecker() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getStaleConnectionChecker().getClassName());
    } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getStaleConnectionChecker() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getStaleConnectionChecker().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_CLASSNAME.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getValidConnectionChecker() == null) {
            return;
        }
        setStringIfNotNull(context, dataSource.getValidation().getValidConnectionChecker().getClassName());
    } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_PROPERTIES.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        if (dataSource.getValidation().getValidConnectionChecker() == null) {
            return;
        }
        final Map<String, String> propertiesMap = dataSource.getValidation().getValidConnectionChecker().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATIONMILLIS.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setLongIfNotNull(context, dataSource.getValidation().getBackgroundValidationMillis());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.BACKGROUNDVALIDATION.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isBackgroundValidation());
    } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.USE_FAST_FAIL.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isUseFastFail());
    } else if (attributeName.equals(Constants.VALIDATE_ON_MATCH.getName())) {
        if (dataSource.getValidation() == null) {
            return;
        }
        setBooleanIfNotNull(context, dataSource.getValidation().isValidateOnMatch());
    } else if (attributeName.equals(Constants.SPY.getName())) {
        setBooleanIfNotNull(context, dataSource.isSpy());
    } else if (attributeName.equals(Constants.USE_CCM.getName())) {
        setBooleanIfNotNull(context, dataSource.isUseCcm());
    } else if (attributeName.equals(Constants.ALLOW_MULTIPLE_USERS.getName())) {
        Pool pool = dataSource.getPool();
        if (!(pool instanceof DsPool)) {
            return;
        }
        setBooleanIfNotNull(context, ((DsPool) pool).isAllowMultipleUsers());
    } else if (attributeName.equals(Constants.CONNECTION_LISTENER_CLASS.getName())) {
        Pool pool = dataSource.getPool();
        if (!(pool instanceof DsPool) || ((DsPool) pool).getConnectionListener() == null) {
            return;
        }
        setStringIfNotNull(context, ((DsPool) pool).getConnectionListener().getClassName());
    } else if (attributeName.equals(Constants.CONNECTION_LISTENER_PROPERTIES.getName())) {
        Pool pool = dataSource.getPool();
        if (!(pool instanceof DsPool) || ((DsPool) pool).getConnectionListener() == null) {
            return;
        }
        final Map<String, String> propertiesMap = ((DsPool) pool).getConnectionListener().getConfigPropertiesMap();
        if (propertiesMap == null) {
            return;
        }
        for (final Map.Entry<String, String> entry : propertiesMap.entrySet()) {
            context.getResult().asPropertyList().add(new ModelNode().set(entry.getKey(), entry.getValue()).asProperty());
        }
    } else if (attributeName.equals(Constants.CONNECTABLE.getName())) {
        // Just set to false
        context.getResult().set(false);
    } else if (attributeName.equals(Constants.STATISTICS_ENABLED.getName())) {
        // Just set to false
        context.getResult().set(false);
    } else if (attributeName.equals(Constants.TRACKING.getName())) {
        // Just return w/o setting a result
        return;
    } else if (attributeName.equals(Constants.MCP.getName())) {
        // Just return w/o setting a result
        return;
    } else if (attributeName.equals(Constants.ENLISTMENT_TRACE.getName())) {
        // Just return w/o setting a result
        return;
    } else {
        throw ConnectorLogger.ROOT_LOGGER.unknownAttribute(attributeName);
    }
}
Also used : DsSecurity(org.jboss.as.connector.metadata.api.ds.DsSecurity) Pool(org.jboss.jca.common.api.metadata.common.Pool) DsPool(org.jboss.jca.common.api.metadata.ds.DsPool) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map) DsPool(org.jboss.jca.common.api.metadata.ds.DsPool)

Aggregations

DsSecurity (org.jboss.as.connector.metadata.api.ds.DsSecurity)4 Map (java.util.Map)2 Credential (org.jboss.as.connector.metadata.api.common.Credential)2 DsSecurityImpl (org.jboss.as.connector.metadata.ds.DsSecurityImpl)2 ModelNode (org.jboss.dmr.ModelNode)2 Capacity (org.jboss.jca.common.api.metadata.common.Capacity)2 Extension (org.jboss.jca.common.api.metadata.common.Extension)2 FlushStrategy (org.jboss.jca.common.api.metadata.common.FlushStrategy)2 DsPool (org.jboss.jca.common.api.metadata.ds.DsPool)2 DsXaPool (org.jboss.jca.common.api.metadata.ds.DsXaPool)2 Statement (org.jboss.jca.common.api.metadata.ds.Statement)2 TimeOut (org.jboss.jca.common.api.metadata.ds.TimeOut)2 TransactionIsolation (org.jboss.jca.common.api.metadata.ds.TransactionIsolation)2 Validation (org.jboss.jca.common.api.metadata.ds.Validation)2 StatementImpl (org.jboss.jca.common.metadata.ds.StatementImpl)2 TimeOutImpl (org.jboss.jca.common.metadata.ds.TimeOutImpl)2 ValidationImpl (org.jboss.jca.common.metadata.ds.ValidationImpl)2 CredentialImpl (org.jboss.as.connector.metadata.common.CredentialImpl)1 Pool (org.jboss.jca.common.api.metadata.common.Pool)1 Recovery (org.jboss.jca.common.api.metadata.common.Recovery)1