You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2010/09/14 15:11:09 UTC

svn commit: r996882 - /incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java

Author: timothyjward
Date: Tue Sep 14 13:11:09 2010
New Revision: 996882

URL: http://svn.apache.org/viewvc?rev=996882&view=rev
Log:
ARIES-407 - Java 2 security fix

Modified:
    incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java

Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java?rev=996882&r1=996881&r2=996882&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/TempBundleDelegatingClassLoader.java Tue Sep 14 13:11:09 2010
@@ -21,7 +21,12 @@ package org.apache.aries.jpa.container.u
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.UndeclaredThrowableException;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Enumeration;
 
 import org.osgi.framework.Bundle;
@@ -68,13 +73,41 @@ public class TempBundleDelegatingClassLo
   }
 
   @Override
-  protected URL findResource(String resName) {
-    return bundle.getResource(resName);
+  protected URL findResource(final String resName)
+  {
+    return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+
+      public URL run()
+      {
+        return bundle.getResource(resName);
+      }
+    });
   }
 
   @SuppressWarnings("unchecked")
   @Override
-  protected Enumeration<URL> findResources(String resName) throws IOException {
-    return bundle.getResources(resName);
+  protected Enumeration<URL> findResources(final String resName) throws IOException
+  {
+    Enumeration<URL> resources = null;
+    try {
+      resources = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
+
+        public Enumeration<URL> run() throws IOException
+        {
+          return bundle.getResources(resName);
+        }
+      });
+    } catch(PrivilegedActionException pae) {
+      Exception thrownException = pae.getException();
+      if (thrownException instanceof RuntimeException) {
+        throw (RuntimeException)thrownException;
+      } else if (thrownException instanceof IOException) {
+        throw (IOException)thrownException;
+      } else {
+        // This code should never get called.
+        throw new UndeclaredThrowableException(thrownException);
+      }
+    }
+    return resources;
   }
 }