Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unexpected Behavior when Using Proxy Sessions

lucborsJun 10 2014 — edited Jun 12 2014

Hi all,

I'm having an issue using PROXYTYPE connections in my ADF (11.1.1.7) Application.

To explain the problem, I created two functional users that have "connect" privileges "through" the user that sets up the jdbc connection.

Grant connect through MY_JDBC_USER to MY_FUNC_USER_ONE;

Grant connect through MY_JDBC_USER to MY_FUNC_USER_TWO with roles ROLE_ONE;

If I connect MY_FUNC_USER_ONE, the connection is successful. The current user (line 09 below) is displayed as FUNC_USER_ONE. Unfortunately I get lots of ORA_0942 (table or view does not exist).

That is why I added the "with roles" option to MY_FUNC_USER_TWO.

However when I now try to connect MY_FUNC_USER_TWO using the openProxySession(), it does not work... The current user (line 09 below) is displayed as MY_JDBC_USER.

I do not get any errors from the database, so to be honest I don't have a clue why this is not working.....

Here is my code and note that I created my ownTranscationFactory that extends DatabaseTransactionFactory .

public void prepareSession (Session session){

myTransactionImpl myTrans = (myTransactionImpl)this.getDBTransaction();
        OracleConnection conn = hzpcTrans.getConnection();
        String currentUser = ADFContext.getCurrent().getSecurityContext().getUserName();
        java.util.Properties prop = new java.util.Properties();
        prop.put(OracleConnection.PROXY_USER_NAME, currentUser);

      try {
            conn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop);
            DatabaseMetaData meta = conn.getMetaData();           
            System.out.println("the user currently on the session is " + meta.getUserName());
        }

.catch.........

}

Any help is welcome.

Thanks

Comments

Sascha Herrmann

Hi!

Works for us. Strange that you don't get an exception. What does your ROLE_ONE look like?

Sascha

kdario

AFAIK conn.openProxySession() can fail silently(so you will get standard connection instead of proxy).

Also, because of connection pooling, always check if you already have proxy connection(and if so, close this connection) before opening new proxy connection.

So your code should look like this:

public void prepareSession (Session session){ 

myTransactionImpl myTrans = (myTransactionImpl)this.getDBTransaction();

      OracleConnection conn = hzpcTrans.getConnection();

      String currentUser = ADFContext.getCurrent().getSecurityContext().getUserName();

      java.util.Properties prop = new java.util.Properties();

      prop.put(OracleConnection.PROXY_USER_NAME, currentUser);

      try {

if(conn.isProxySession()){

            conn.close(OracleConnection.PROXY_SESSION);

        }

            conn.openProxySession(OracleConnection.PROXYTYPE_USER_NAME, prop);

if(!conn.isProxySession()){

            throw SomeException();

        }

            DatabaseMetaData meta = conn.getMetaData();            

            System.out.println("the user currently on the session is " + meta.getUserName());

        }

.catch.........

}

I'm not sure why you need custom connection factory(maybe you introduced some error there? )

You can retrieve OracleConnection like this:

PreparedStatement statement =  this.getDBTransaction().createPreparedStatement("commit", 1);

OracleConnection conn = (OracleConnection)statement.getConnection();

And don't forget to call super.prepareSession(session); 

Dario

unknown-7404

Already replied in your duplicate JDBC forum thread

https://community.oracle.com/thread/3570631

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 10 2014
Added on Jun 10 2014
3 comments
1,470 views