JBoss Community

How to get this dataSourceConfig in java code?

created by Rella Guo in Datasource Configuration - View the full discussion

I want to get the masked password in java code and I found some java code. But I don't understand how to get this dataSourceConfig. Who know it?

 

{code:lang=xml}

<subsystem xmlns="urn:jboss:domain:datasources:1.0">

            <datasources>

                <datasource jndi-name="java:jboss/datasources/ExampleDS" enabled="true" use-java-context="true" pool-name="H2DS">

                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>

                    <driver>h2</driver>

                    <pool></pool>

                    <security>

                        <user-name>sa</user-name>

                        <password>${VAULT::ds_ExampleDS::password::N2NhZDYzOTMtNWE0OS00ZGQ0LWE4MmEtMWNlMDMyNDdmNmI2TElORV9CUkVBS3ZhdWx0}</password>

                    </security>

                </datasource>

                <drivers>

                    <driver name="h2" module="com.h2database.h2">

                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

                    </driver>

                </drivers>

            </datasources>

        </subsystem>{code}

 

 

{code}import org.jboss.as.server.services.security.VaultUtil;
import org.jboss.security.vault.SecurityVaultException;

final DsSecurity security = dataSourceConfig.getSecurity();
            if (security != null) {
                if (security.getUserName() != null) {
                    managedConnectionFactory.setUserName(security.getUserName());
                }
                if (security.getPassword() != null) {
                    String password = security.getPassword();
                    if (VaultUtil.isVaultFormat(password)) {
                        try {
                            password = VaultUtil.getValueAsString(password);
                        } catch (SecurityVaultException e) {
                            throw new RuntimeException(e); // TODO: use bundle from IJ
                        }
                    }
                    managedConnectionFactory.setPassword(password);
                }
            }{code}

Reply to this message by going to Community

Start a new discussion in Datasource Configuration at Community