0
votes

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?)

3
@ElliottFrisch - It shows a Datasource named jdbc/WPDS with type XA Datasource and status UP. I can verify it is loading from this file, because it initially said that Available Connection Count was 50 (as it is in the file in my original post), and when I changed the file to have 60 and restarted the server, it followed accordingly.ArtOfWarfare
@ravthiru - I'm not familiar with what you're talking about right now... care to explain? What's the security context? How can I find out what username/password it's using and how can I change it?ArtOfWarfare

3 Answers

1
votes

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

0
votes

You can try getting information like this , but not password.

  if (dataSource instanceof  oracle.jdbc.xa.client.OracleXADataSource) {
      oracle.jdbc.xa.client.OracleXADataSource oracleXADataSource = (oracle.jdbc.xa.client.OracleXADataSource)dataSource;
      logger.info(oracleXADataSource.getUrl());
      logger.info(oracleXADataSource.getUsername());
  }
0
votes

I ended up writing a method which recursively reflects on an object and prints a lot about it.

I ultimately found it was using the exact same password from oracle-xa-ds.xml - the issue was that that file had the incorrect password in it. So I wasted two entire days on having the incorrect password.

Hopefully this code will help someone else end their wild goose chase quickly and get them back to looking in the right direction:

public static final void logFields(Object o, String prefix, int depth) {
    if (depth <= 0) {
        logger.debug(prefix + "No deeper because max depth reached.");
        return;
    }

    if (o == null) {
        return;
    }

    Class  c         = o.getClass();
    String className = c.getName();
    if (className.startsWith("java.lang")) {
        logger.debug(prefix + "No deeper because class is " + className);
        return;
    }

    logger.debug(prefix + "Class Name: " + className);
    for (Field f : c.getDeclaredFields()) {
        logger.debug(prefix + "Field Name: " + f.getName());
        logger.debug(prefix + "Field Type: " + f.getType());
        try {
            if (!f.isAccessible()) {
                logger.debug(prefix + "  Not accessible - fixing that.");
                f.setAccessible(true);
                logger.debug(prefix + "  Should now be accessible.");
            }
            Object o2 = f.get(o);
            logger.debug(prefix + "Field Value: " + o2);
            logFields(o2, prefix + "    ", depth - 1);
        } catch (Throwable t) {
            logger.debug(prefix + "Caught Throwable trying to get Field Value: " + t);
            logger.error(t, t);
        }
    }
}

To use it, just do something like:

logFields(ds, "", 7);