This discussion is archived
3 Replies Latest reply: Nov 26, 2012 8:06 AM by rp0428 RSS

In ojdbc6, connection properties makes the password non readable

975920 Newbie
Currently Being Moderated
I am using ojdbc6 and the code is as below:

OracleDataSource ods = null;
ods = new OracleDataSource();

Properties props = new Properties();
props.setProperty("user", "abc");
props.setProperty("password", "abc34");
props.setProperty("schemaPrefix", "abc");

ods.setConnectionProperties(props);

Now, when I do ods.getConnectionProperties().getProperty("password") it returns me null. This means that the connection properties overrides the password and make it non readable.
Though this used to work perfectly fine with ojdbc14.

Please suggest, if there is a way to read password property. I want to create an instance of hibernate session factory from the oracleDataSource provided by client.

Thanks and Regards,
  • 1. Re: In ojdbc6, connection properties makes the password non readable
    rp0428 Guru
    Currently Being Moderated
    >
    I am using ojdbc6 and the code is as below:

    OracleDataSource ods = null;
    ods = new OracleDataSource();

    Properties props = new Properties();
    props.setProperty("user", "abc");
    props.setProperty("password", "abc34");
    props.setProperty("schemaPrefix", "abc");

    ods.setConnectionProperties(props);

    Now, when I do ods.getConnectionProperties().getProperty("password") it returns me null. This means that the connection properties overrides the password and make it non readable.
    Though this used to work perfectly fine with ojdbc14.
    >
    Correct - the password property is filtered out when you call the 'getProperty' method of the Oracle datasource. If you use the 'setPassword' method to set the password you can retrieve the password by using the 'getPassword' method.
    dataSource.setPassword("tiger");
    dataSource.setUser("SCOTT");
    . . .
    System.out.println(dataSource.getPassword());
    
    tiger
    That filtering began with the OJDBC5.jar file.
    >
    Please suggest, if there is a way to read password property. I want to create an instance of hibernate session factory from the oracleDataSource provided by client.
    >
    What is stopping you from doing that? Oracle still has the password available to use when creating connections. You haven't indicated that you have gotten any error or exception.
  • 2. Re: In ojdbc6, connection properties makes the password non readable
    975920 Newbie
    Currently Being Moderated
    The OracleDataSource API doesn't provide any implementation like getPassword(). There is no exception, my need is to only get the password. But I am not sure how can I do it.

    Thanks and Regards
  • 3. Re: In ojdbc6, connection properties makes the password non readable
    rp0428 Guru
    Currently Being Moderated
    >
    The OracleDataSource API doesn't provide any implementation like getPassword(). There is no exception, my need is to only get the password. But I am not sure how can I do it.
    >
    You said
    >
    I want to create an instance of hibernate session factory from the oracleDataSource provided by client.
    >
    Did you try that? You don't need the password to do that? Sounds like you are just trying to hack the password.

    As mentioned the latest Oracle jar filters the password out when you use getProperties and has made the getPassword method protected. You need to extend the class to get access to the getPassword method now.

    But that won't give you the password unless setPassword was called to set it. You said that setProperties is being used. Those properties can only be accessed directly if you extend the class.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points