Forum Stats

  • 3,781,142 Users
  • 2,254,484 Discussions
  • 7,879,589 Comments

Discussions

Unexpected Behavior when Using Proxy Sessions

lucbors
lucbors Member Posts: 326 Bronze Badge
edited Jun 12, 2014 7:12PM in JDeveloper and ADF

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

Tagged:

Answers

  • Hi!

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

    Sascha

  • kdario
    kdario Member Posts: 3,519 Silver Crown
    edited Jun 12, 2014 4:52PM

    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

This discussion has been closed.