12 Replies Latest reply on Aug 19, 2013 2:32 PM by shinobies

    JBoss Connection Pool + Oracle End-To-End Metrics

    shinobies

      Hello there!

       

      I'm in a dire need of a hand/advice/tip/whatever you guys can give about my situation. Any insight is much appreciated. I may even be way over my head and knowledge (I'm a beginner in my team of Architects). I was assigned a task and I'm trying everything I can to see it done or at least, thoroughly researched, so I really thank you for any support I can get.

       

      At my workplace we want to improve the data obtained by Oracle Audit Vault by providing more accurate information about the database connections used in our applications, like the logged in user using the application. The idea is to intercept the moment when the application get a connection from the pool, and inject the metrics data. Then, when the connection is released, intercept again and clean the fields in which the data was injected.

       

      We can do this manually (inject the metrics data), in a simple main method, for instance:

       

      import java.sql.DriverManager;

      import java.sql.ResultSet;

      import java.sql.Statement;

       

      import oracle.jdbc.driver.OracleConnection;

      import oracle.jdbc.driver.OracleDriver;

       

      public class Test {


                public static void main(String[] args) throws Exception {

                          String url = "connection_url";

                          String user = "user";

                          String pass = "password";

                          DriverManager.registerDriver(new OracleDriver());

                          OracleConnection cnx = (OracleConnection) DriverManager.getConnection(url, user, pass);

       

                          String metrics[] = new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];

                          metrics[OracleConnection.END_TO_END_ACTION_INDEX] = "Simple Test";

                          metrics[OracleConnection.END_TO_END_MODULE_INDEX] = "Test Application";

                          metrics[OracleConnection.END_TO_END_CLIENTID_INDEX] = "User ID";

                          // Set these metrics

                          cnx.setEndToEndMetrics(metrics, (short) 0);

       

        // Check if the metrics are there

                          Statement statement = cnx.createStatement();

                          ResultSet rs = statement.executeQuery("select sysdate, sys_context('USERENV','ACTION'), sys_context('USERENV','MODULE'), " +

                          "sys_context('USERENV','CLIENT_IDENTIFIER') from dual");

                          rs.next();

                          System.out.println(rs.getString(1) + " – " + rs.getString(2) + ", " + rs.getString(3) + ", " + rs.getString(4));

                          rs.close();

                          statement.close();

                          cnx.close();

                }

      }

       

       

      So, that's my question: Is it possible? If it is, what should I do?

        • 1. Re: JBoss Connection Pool + Oracle End-To-End Metrics
          wdfink

          Hello Bored,

           

          welcome to the forum.

           

          what you try to achieve?

          If you use JBoss connection pool the user is configured in the datasource. There is a pool statistic which you can analyze.

          Depend on the version you might use the jdbc.spy function to get more information.

           

          If you want to customize more an option might to wrap the Oracle driver and do what you want before or after passing the ivocation to the original driver.

          • 2. Re: JBoss Connection Pool + Oracle End-To-End Metrics
            shinobies

            Thank you!

             

            We are trying to get more info about the connection by injecting userdata that will be obtained from PicketLink, i.e., the logged in user.

            This way, we'll know who was using the connection at any given time.

             

            Or at least, that's the idea. The line of thought I was given to pursuit was to try and intercept the retrieval of a connection from the pool.

            The code I posted is supposed to be used at this moment: application gets a connection from the pool, inject the Oracle metrics data (the userdata) and proceed.

            • 3. Re: JBoss Connection Pool + Oracle End-To-End Metrics
              pmm

              The easiest is probably to set v$session.program on the DataSource you can get the the other information exept the action from the Oracle session tables.

              • 4. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                shinobies

                Indeed setting v$session columns on datasource is the easiest, but it only allows me to define static info, since the connection isn't made programmatically (getConnection), We want to grab the logged in user info as well.

                • 5. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                  pmm

                  Bored Elf wrote:

                   

                  Indeed setting v$session columns on datasource is the easiest, but it only allows me to define static info, since the connection isn't made programmatically (getConnection), We want to grab the logged in user info as well.

                  The user should be avaible on the Oracle session tables, v$session.username or something similar.

                  • 6. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                    shinobies

                    I'm sorry, maybe I wasn't specific enough. Like told Wolf-Dieter Fink, I meant the logged in the application user, not the user from the connection. Please, review my second post so you can get a better understanding of the problem: https://community.jboss.org/message/832965#832965.

                    • 7. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                      jesper.pedersen

                      The above code is wrong in application server context, as the datasource deployments are controlled by the JCA container (IronJacamar) in the case of WildFly.

                       

                      So the credential for connection is either the credential configured for the datasource (user-name/password or security-domain) or the user name and password passed in to datasource.getConnection(u, p) call.

                       

                      You can use getUnderlyingConection() on the Connection instance (WrappedConnection) in order to obtain the Oracle specific connection implementation.

                       

                      However, I think you are looking for "connection-listener" for datasource deployments using IronJacamar 1.1 - which will be in WildFly 8 shortly. See http://www.ironjacamar.org/doc/schema/datasources_1_2.xsd for now.

                      1 of 1 people found this helpful
                      • 8. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                        shinobies

                        Indeed, that code was just an example of what I'm trying to achieve.

                         

                        The database connection credentials doesn't matter. In our environment we have many applications and we use SSO provided by Picketlink. In order to get more accurate metrics from Audit Vault, we would like to pass the user ID using the application when it gets and releases a connection from the pool, not only the parameters that can be configured on the datasource using connection-property.

                         

                        That's very interesting, precisely what we would need. So this feature is available on IronJacamar 1.1? Could it be used with JBoss EAP 6.0 or 6.1 or even AS 7.1?

                        • 9. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                          jesper.pedersen

                          Datasources doesn't know anything about their related web application or whatever. That being said, you could likely setup application specific lookup features for the connection listener implementation through its properties...

                           

                          IronJacamar 1.1 is for WildFly 8+

                          • 10. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                            shinobies

                            Jesper Pedersen wrote:

                             

                            Datasources doesn't know anything about their related web application or whatever.

                            I'm aware. Hence the connection listener.

                             

                            IronJacamar 1.1 is for WildFly 8+

                            So in order to use a connection-listener, I would need to migrate the application server?

                            • 11. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                              pmm

                              Bored Elf wrote:

                               

                              I'm sorry, maybe I wasn't specific enough. Like told Wolf-Dieter Fink, I meant the logged in the application user, not the user from the connection. Please, review my second post so you can get a better understanding of the problem: https://community.jboss.org/message/832965#832965.

                              I would do probably do this in the application layer either a servlet filter or a top level EJB interceptor.

                              1 of 1 people found this helpful
                              • 12. Re: JBoss Connection Pool + Oracle End-To-End Metrics
                                shinobies

                                Philippe Marschall wrote:

                                I would do probably do this in the application layer either a servlet filter or a top level EJB interceptor.

                                First thing that occurred to me but it would require to change a lot of applications.