-
1. Re: Setting username and password on existing datasource
dheinecke Apr 7, 2004 5:52 PM (in response to dheinecke)Ok, what we did seems to have worked, but if anyone has a better way to do this, or can see any potential problems, please let me know.
First, we made our deployer MBean depend on the ManagedConnectionFactory service for our datasource. Without this dependency, our MBean was starting up and trying to modify the settings of the MCF before it was up and running.
In our MBean, as soon as we read the encrypted username and password, we lookup and call the setManagedConnectionFactoryAttribute method of the MCF. This is illustrated by the following code...
EncryptedProperties props = new EncryptedProperties("enc.properties");
MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next();
ObjectName objectName = new ObjectName("jboss.jca:service=ManagedConnectionFactory,name=EsmDS");
server.invoke(objectName, "setManagedConnectionFactoryAttribute",
new Object[] { "UserName", String.class, props.getProperty(BridgeProperties.DB_ACCOUNT_NAME) },
new String[] { "java.lang.String", "java.lang.Class", "java.lang.Object" });
server.invoke(objectName, "setManagedConnectionFactoryAttribute",
new Object[] { "Password", String.class, props.getProperty(BridgeProperties.DB_ACCOUNT_PASSWORD) },
new String[] { "java.lang.String", "java.lang.Class", "java.lang.Object" });
This approach appears to work since we are able to lookup the connection in jndi and obtain connections from it (without having to pass credentials to the ds in the getConnection call).
Even though it works, the solution feels a little dirty to me. For starters, I don't like the dependency that has been created between the datasource and our deployer service. I am also worried that in the future this model will be broken when we move over to supporting the DB2 8.1 XADatasource.
Any ideas, or is this the best that we can do?