Skip to content
Advertisement

How to get a connection from Java DataSource without a username and password?

In an ejb after I look up a secured javax.sql.DataSource using its global JNDI name e.g. jdbc/MyDS (not resource reference) is there a way to get a connection via getConnection().

This is on WAS 8.5.5 and the data source has both a container managed and component managed authentication alias with “Mapping-configuration alias” of none and test connection is successful in the WAS admin console.

Advertisement

Answer

Direct lookups (when no resource reference is used) default to application-managed authentication (sometimes also referred to as component managed authentication), which means that the application is responsible for supplying or not supplying the the user/password. You should be able to use both getConnection methods: getConnection() without a user/password if you do not wish to supply user/password, and getConnection(user, password) if you do wish to supply user/password.

The other way to get application-managed authentication is to use a resource reference and configured it with res-auth=Application. If a resource reference does not specify, the default is Container.

If you don’t supply a user/password on the getConnection request when using application managed authentication and your DataSource requires a user/password (which you have indicated is the case here), then you will need to either have the component managed authentication alias or a user/password configured as custom data source properties (most JDBC vendors tend to support user/password as data source properties)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement