0

I have a server.xml with jndi configuration that works and can connect to database (validated with small program using @Resource), but when I try to use an application that is spring based, I can never login to the database. I am successfully getting the jndi reference, but it just never logs in and gives me invalid username/password.

I have searched this to death on google, and haven't found anything that can point in the right direction.

2 Answers2

0

You should post the specific details about your configuration and resource references. One way to cause the error you are seeing would be to configure a dataSource with the user/password specified only within the default container authdata (dataSource with nested containerAuthData element, or with a containerAuthDataRef specified). When you use @Resource, you are getting container authentication by default, and the user/password would be used. However, if Spring is directly looking up the data source (no resource reference) or specifies a resource reference with application authentication, then the user/password of the default container authdata would not apply. However, if instead you configure user/password on the vendor properties element that is nested under dataSource, then it will reply regardless of the authentication type.

Example of data source configuration where user/password will only be used for container authentication:

<dataSource id="DefaultDataSource" jndiName="jdbc/oracle">
    <containerAuthData user="user1" password="pwd1"/>
    <jdbcDriver libraryRef="OracleLib"/>
    <properties.oracle URL="jdbc:oracle:thin:@//localhost:1521/SAMPLEDB"/>
</dataSource>

Example of data source configuration where user/password apply regardless of whether container or application authentication are used,

<dataSource id="DefaultDataSource" jndiName="jdbc/oracle">
    <jdbcDriver libraryRef="OracleLib"/>
    <properties.oracle URL="jdbc:oracle:thin:@//localhost:1521/SAMPLEDB" user="user1" password="pwd1"/>
</dataSource>
njr
  • 3,399
  • 9
  • 7
  • Here is my database definition (server.xml) – Lonnie Phillips May 15 '17 at 18:16
  • Spring application.context – Lonnie Phillips May 15 '17 at 18:17
  • @LonniePhillips please update your question with that information as properly formatted text instead of posting it as a comment. No one is going to read it as the unreadable blob it currently is, and future readers may not see this info – Andy Guibert May 17 '17 at 03:39
  • Thanks for posting the configured dataSource info. Note that by specifying containerAuthDataRef, you have only set the user/password for the scenario where container authentication is being used. If we assume that Spring is not using container authentication, that would be why user/password are not applied. Please try out adding user/password to properties.oracle (see my second example under this answer). If it works, that should confirm this is the case. – njr May 17 '17 at 14:25
0

invalid username/password is an oracle error message, so you may be:

  1. pointing to the wrong DB (where user does not live)
  2. using the wrong user
  3. using the wrong password

Try the connection in SQL Plus, if it works there, then problem in the code/configuration.

Roger Cornejo
  • 1,507
  • 1
  • 8
  • 7
  • Everything is good, but for some reason when doing spring, the username/password are not being pulled in the jndi call (I have verified it is getting the jndi name info, but not username/password) – Lonnie Phillips May 15 '17 at 18:19