my dog learned polymorphism*
The moose likes JDBC and the fly likes Retrieve DB2 credentials configured on websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retrieve DB2 credentials configured on websphere" Watch "Retrieve DB2 credentials configured on websphere" New topic

Retrieve DB2 credentials configured on websphere

Natraj Muthu

Joined: Jul 07, 2011
Posts: 2

i have a java batch client ( Application client) that reads the DB2 user Id and Password from the property file and establishes the connection to perform database operations.
I have been requested not to put the user id and password explicitly on the property file for security purpose. So, i have to find a way to retrieve the credentials from the websphere. I tried the follwoing 2 options

1. Trying to read the jaasAliasName and get teh user id and Password, But we got an exception while running it . This is not helping me. Looks like the jaasAlias name is not visible to the application client. securityConfig =;
Properties authProperties = securityConfig.getAuthData("jaasAliasName");
String id= authProperties.getProperty("username");
String pwd= authProperties.getProperty("password")

2. Tried adding the credential details under datasource custom properties in admin console. Not sure how to retrieve this from application client.

Can someone suggest me a best way to read it though application client?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

No, that's not what you want to do. Configure the credentials in Websphere, yes. Retrieve the credentials in your application, no. Instead, configure a data source in Websphere, have it use those credentials, and then use the data source in your application.
Natraj Muthu

Joined: Jul 07, 2011
Posts: 2
My batch program uses hiberante to for DB2. It needs the user id and password to make a connectivity at runtime( when run though a launch client approach). Right now my program reads the user id and password from the property file and dose the connection.

// Reading from the property file
String userName = SPMUWPropertyProvider.getProperty("sp.muw.sics.hibernate.connection.username");
String password = SPMUWPropertyProvider.getProperty("sp.muw.sics.hibernate.connection.password");

// Setting user id and pass to the hibernate config

sessionFactory = cfg.buildSessionFactory();

In websphere, under datasource ( Resources--> jdbc provide --> datasource), i have created a data source and provide a jndi name. I was thinking, if there is a way to retrive the user id and password from the datasource configured on the websphere so that i can pass it to the above block of code.

Is it possible?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Retrieve DB2 credentials configured on websphere
Similar Threads
long post IBM.158
Accessing DataSource outside container
JAAS and Websphere
Why the value of my bean's property is always null
Help needed to call a web service after TAM authentication - (401)Unauthorized