Wednesday, August 4, 2010

Dynamic JCA Connection Factory Substitution

JCA connection factories can be categorized logically into two sections. One that manages connection details and other interaction details. In websphere (and I presume the same with other application servers) you have to configure connection details on these factories as part administrative action. I had a requirement where connection host was fixed but authentication information for the host was different based on scenarios. Unless there was a way to dynamically substitute security information you would end up creating multiple connection factories.

In websphere you can set custom properties using the prefix "CP" to your resource property within your application. Ofcourse this will involve using IBM specific API within your application code to lookup connection factory and dynamically substituting connection details. Most of JCA Connection properties can be set using this approach except the hostname.

For example, to you may have a Connection factory marked against a file resource adapter, with JNDI com/eis/myFileCF dedicated for I/O write operations. Supposing, there are many folders that are operated by certain users who have privilige to delete while others have only write access it may become a daunting task to create dedicated connection factories to isolate these set of users. Instead application developers can lookup the connection factory by JNDI and inject any property variances such as username and password, in this case, like
                 conn.setProperty("CPuserName", "user");
                 conn.setProperty("CPpassword", "{xor}49dksdldk");

   Note, the password is masked using xor alogrithm. Websphere encodes J2C credentials while saving into file system and later decodes when sending them out to appropriate endpoints; your dynamic injection should encode the same way for proper processing.

No comments:

Post a Comment