Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve DB2 credentials configured on websphere

 
Natraj Muthu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

com.ibm.ws.security.core.SecurityConfig securityConfig = com.ibm.ws.security.core.SecurityConfig.getConfig();
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
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
cfg.setProperty("hibernate.connection.username",userName);
cfg.setProperty("hibernate.connection.password",password);

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic