Author: markt
Date: Fri Feb  7 14:54:12 2014
New Revision: 1565667

URL: http://svn.apache.org/r1565667
Log:
Fix DBCP-177
Enable DBCP to work with a SecurityManager such that only DBCP needs to be 
granted the necessary permissions to communicate with the database.

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1565667&r1=1565666&r2=1565667&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Fri Feb  7 14:54:12 2014
@@ -133,6 +133,10 @@ The <action> type attribute can be add,u
         Enable JDBC resources that are no longer referenced by client code to 
be
         eligible for garbage collection.
       </action>
+      <action dev="markt" issue="DBCP-177" type="add">
+        Enable DBCP to work with a SecurityManager such that only DBCP needs to
+        be granted the necessary permissions to communicate with the database.
+      </action>
     </release>
     <release version="1.5.1" date="TBD" description="TBD">
       <action dev="markt" issue="DBCP-400" type="fix">

Modified: 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1565667&r1=1565666&r2=1565667&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
 (original)
+++ 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
 Fri Feb  7 14:54:12 2014
@@ -76,6 +76,31 @@ public class BasicDataSource
     static {
         // Attempt to prevent deadlocks - see DBCP - 272
         DriverManager.getDrivers();
+        try {
+            // Load classes now to prevent AccessControlExceptions later
+            // A number of classes are loaded when getConnection() is called
+            // but the following classes are not loaded and therefore require
+            // explicit loading.
+            if (Utils.IS_SECURITY_ENABLED) {
+                ClassLoader loader = BasicDataSource.class.getClassLoader();
+                String dbcpPackageName = 
BasicDataSource.class.getPackage().getName();
+                loader.loadClass(dbcpPackageName + 
".BasicDataSource$PaGetConnection");
+                loader.loadClass(dbcpPackageName + 
".DelegatingCallableStatement");
+                loader.loadClass(dbcpPackageName + 
".DelegatingDatabaseMetaData");
+                loader.loadClass(dbcpPackageName + 
".DelegatingPreparedStatement");
+                loader.loadClass(dbcpPackageName + ".DelegatingResultSet");
+                loader.loadClass(dbcpPackageName + 
".PoolableCallableStatement");
+                loader.loadClass(dbcpPackageName + 
".PoolablePreparedStatement");
+                loader.loadClass(dbcpPackageName + 
".PoolingConnection$StatementType");
+                loader.loadClass(dbcpPackageName + ".PStmtKey");
+
+                String poolPackageName = 
PooledObject.class.getPackage().getName();
+                loader.loadClass(poolPackageName + 
".impl.LinkedBlockingDeque$Node");
+                loader.loadClass(poolPackageName + 
".impl.GenericKeyedObjectPool$ObjectDeque");
+            }
+        } catch (ClassNotFoundException cnfe) {
+            throw new IllegalStateException("Unable to pre-load classes", 
cnfe);
+        }
     }
 
     // ------------------------------------------------------------- Properties


Reply via email to