Search code examples
javaoraclejbossdatasourcejndi

Find Where Data Source retrieved by InitialContext.lookup is defined?


I have some Java code written by someone else (long gone, no way to contact them) running on a JBoss server that I'm debugging. It's getting a javax.sql.DataSource with this one line of code:

DataSource ds = new InitialContext().lookup("java:/jdbc/WPDS");

However, when they use ds.getConnection() on the next line, this shows up in the logs:

...

javax.resource.ResourceException: Unable to get managed connection for jdbc/WPDS

...

Caused by: org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: ORA-01017: invalid username/password; logon denied)

I've looked around and found a file named oracle-xa-ds.xml. It contains this:

<datasources>
  <xa-datasource>
    <jndi-name>jdbc/WPDS</jndi-name>
    <!-- uncomment to enable interleaving <interleaving/> -->
    <isSameRM-override-value>false</isSameRM-override-value>
    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    <xa-datasource-property name="URL">jdbc:oracle:thin:@hostname.hidden.com:1621:HIDE</xa-datasource-property>
    <xa-datasource-property name="User">hidden</xa-datasource-property>
    <xa-datasource-property name="Password">hidden</xa-datasource-property>
    <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
    <!-- Checks the Oracle error codes and messages for fatal errors -->
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
    <no-tx-separate-pools/>

    <max-pool-size>50</max-pool-size>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
      <metadata>
         <type-mapping>Oracle9i</type-mapping>
      </metadata>
  </xa-datasource>

  <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter"
         name="jboss.jca:service=OracleXAExceptionFormatter">
    <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
  </mbean>

</datasources>

I've verified that all these settings are right. I can connect to the database using the hostname, port, SID, username, and password given in this file.

I suspect that maybe it's loading the DataSource from somewhere else, but I don't know how I could check that theory (and if it's true, how would I find out where it's actually getting it from?) Is there some kind of JNDI logging I can enable, or maybe I can somehow get it to tell me what username/password it's trying to use (so I can see if it's using what's in the file or not?)


Solution

  • ORA-01017: invalid username/password; logon denied

    Cause:

    • An invalid username or password was entered in an attempt to log on to Oracle. The username and password must be the same as was specified in a GRANT CONNECT statement. If the username and password are entered together, the format is: username/password.

    • The core issue with an ORA-01017 error is an invalid user ID and passwords combination, but other than an incorrect password, there are user ID issues

    • It may be that the user ID is invalid for the target system - The user ID exists as the username column in the dba_users view.

    • Check your $ORACLE_SID environmental parameter. If your $ORACLE_SID is set to the wrong system ID then you may get a ORA-01017 error because you are connecting to the wrong database.

    • Check your tnsnames.ora to ensure that the TNS service name points to the correct server and instance name. If you specify an incorrect tnsnames.ora service name, then the user ID and password may not exist in that database.

    Action:

    • Enter a valid username and password combination in the correct format.

    • The user and password are DEFINITELY incorrect.

    • Try ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = FALSE; and alter password.

    http://oracle-base.com/articles/11g/case-sensitive-passwords-11gr1.php