[jboss-cvs] JBossAS SVN: r112644 - projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 14 15:19:12 EST 2012


Author: jesper.pedersen
Date: 2012-02-14 15:19:11 -0500 (Tue, 14 Feb 2012)
New Revision: 112644

Added:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/SecurityActions.java
Modified:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReauthPlugin.java
Log:
[JBJCA-748] MySQLReauthPlugin caches method instance

Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReauthPlugin.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReauthPlugin.java	2012-02-14 17:13:43 UTC (rev 112643)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/MySQLReauthPlugin.java	2012-02-14 20:19:11 UTC (rev 112644)
@@ -35,8 +35,6 @@
  */
 public class MySQLReauthPlugin implements ReauthPlugin
 {
-   private Method changeUser;
-
    /**
     * Default constructor
     */
@@ -55,10 +53,9 @@
 
       try
       {
-         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-         mysqlConnection = Class.forName("com.mysql.jdbc.Connection", true, tccl);
+         mysqlConnection = Class.forName("com.mysql.jdbc.Connection", true, cl);
       }
-      catch (ClassNotFoundException cnfe) 
+      catch (Throwable t) 
       {
          // Ignore
       }
@@ -67,17 +64,18 @@
       {
          try
          {
-            mysqlConnection = Class.forName("com.mysql.jdbc.Connection", true, cl);
+            ClassLoader tccl = SecurityActions.getThreadContextClassLoader();
+            mysqlConnection = Class.forName("com.mysql.jdbc.Connection", true, tccl);
          }
          catch (Throwable t) 
          {
-            throw new SQLException("Cannot resolve com.mysq.jdbc.Connection changeUser method", t);
+            throw new SQLException("Cannot resolve com.mysq.jdbc.Connection", t);
          }
       }
 
       try
       {
-         changeUser = mysqlConnection.getMethod("changeUser", new Class[] {String.class, String.class});
+         Method changeUser = mysqlConnection.getMethod("changeUser", new Class[] {String.class, String.class});
       }
       catch (Throwable t)
       {
@@ -97,6 +95,8 @@
       Object[] params = new Object[] {userName, password};
       try
       {
+         Method changeUser = c.getClass().getMethod("changeUser", new Class[] {String.class, String.class});
+         changeUser.setAccessible(true);
          changeUser.invoke(c, params);
       }
       catch (Throwable t) 

Added: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/SecurityActions.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/SecurityActions.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/extensions/mysql/SecurityActions.java	2012-02-14 20:19:11 UTC (rev 112644)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.adapters.jdbc.extensions.mysql;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class SecurityActions
+{
+   /**
+    * Get the thread classloader
+    * @return The value
+    */
+   static ClassLoader getThreadContextClassLoader()
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() 
+      {
+         public ClassLoader run()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   }
+}



More information about the jboss-cvs-commits mailing list