[jboss-user] [Datasource Configuration] - How to get this dataSourceConfig in java code?

Rella Guo do-not-reply at jboss.com
Wed Aug 1 02:39:06 EDT 2012


Rella Guo [https://community.jboss.org/people/rella] created the discussion

"How to get this dataSourceConfig in java code?"

To view the discussion, visit: https://community.jboss.org/message/751391#751391

--------------------------------------------------------------
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
[https://community.jboss.org/message/751391#751391]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120801/7941f548/attachment-0001.html 


More information about the jboss-user mailing list