Encrypted password in Resource configuration

1,009 views
Skip to first unread message

Prashant Potluri

unread,
Mar 3, 2015, 11:03:37 PM3/3/15
to hika...@googlegroups.com
Hi,

I'm using HikariJNDIFactory for the DB Resource configuration in tomcat:

              <Resource name="jdbc/myapp" auth="Container"
                 factory="com.zaxxer.hikari.HikariJNDIFactory"
                 type="javax.sql.DataSource"
                 minimumIdle="5"
                 maximumPoolSize="10"
                 connectionTimeout="300000"
                 dataSourceClassName="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
                 dataSource.user="abc"
                 dataSource.password="xyz"
                 dataSource.url="jdbc:mysql://localhost:3306/myapp"/>

I would like to use encrypted password in above configuration instead of putting plain text password. Please suggest how to proceed on this.

I am using Spring data jpa framework and datasource bean is created as follows:

@Bean(destroyMethod = "close")
    public DataSource dataSource() {
        HikariConfig dataSourceConfig = new HikariConfig();          
        final JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        dataSourceLookup.setResourceRef(true);
        DataSource dataSourceTemp = null;
        try {
            dataSourceTemp = dataSourceLookup.getDataSource("java:comp/env/jdbc/myapp");
        } catch (DataSourceLookupFailureException e) {
            e.printStackTrace();
        }
        dataSourceConfig.setDataSource(dataSourceTemp);
        return new HikariDataSource(dataSourceConfig);
    }


Brett Wooldridge

unread,
Mar 3, 2015, 11:35:01 PM3/3/15
to hika...@googlegroups.com
See the Tomcat wiki for solutions:


This falls outside of the functions provided by a connection pool (or should do) and is squarely in the realm of the application container.

-Brett

Prashant Potluri

unread,
Mar 9, 2015, 12:08:53 AM3/9/15
to hika...@googlegroups.com
Can something like this be done:

http://www.jdev.it/encrypting-passwords-in-tomcat/

The author has extended "org.apache.tomcat.jdbc.pool.DataSourceFactory".

Brett Wooldridge

unread,
Mar 9, 2015, 8:28:01 PM3/9/15
to hika...@googlegroups.com
Why don't you give it a try and let us know?  :-)

-Brett
Reply all
Reply to author
Forward
0 new messages