incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r921262 - in /sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal: DynamicClassLoaderProviderImpl.java DynamicRepositoryClassLoader.java RepositoryClassLoaderFacade.java
Date Wed, 10 Mar 2010 09:21:15 GMT
Author: cziegeler
Date: Wed Mar 10 09:21:14 2010
New Revision: 921262

URL: http://svn.apache.org/viewvc?rev=921262&view=rev
Log:
SLING-1434 : Inherit from SecureClassLoader (and not URLClassLoader)

Modified:
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java?rev=921262&r1=921261&r2=921262&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
(original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicClassLoaderProviderImpl.java
Wed Mar 10 09:21:14 2010
@@ -144,15 +144,13 @@ public class DynamicClassLoaderProviderI
      */
     public boolean delete(String name) {
         name = cleanPath(name);
-        Node parentNode = null;
         Session session = null;
         try {
             session = getSession();
             if (session.itemExists(name)) {
                 Item fileItem = session.getItem(name);
-                parentNode = fileItem.getParent();
                 fileItem.remove();
-                parentNode.save();
+                session.save();
                 return true;
             }
         } catch (RepositoryException re) {

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java?rev=921262&r1=921261&r2=921262&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
(original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
Wed Mar 10 09:21:14 2010
@@ -19,9 +19,9 @@ package org.apache.sling.jcr.classloader
 import java.beans.Introspector;
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
+import java.security.SecureClassLoader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -32,8 +32,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
 
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
@@ -65,10 +63,7 @@ import org.slf4j.LoggerFactory;
  * same, though.
  */
 public final class DynamicRepositoryClassLoader
-    extends URLClassLoader implements EventListener {
-
-    /** An empty list of url paths to call superclass constructor */
-    private static final URL[] NULL_PATH = {};
+    extends SecureClassLoader implements EventListener {
 
     /**
      * The special resource representing a resource which could not be
@@ -170,7 +165,7 @@ public final class DynamicRepositoryClas
                                         final String[] classPath,
                                         final ClassLoader parent) {
         // initialize the super class with an empty class path
-        super(NULL_PATH, parent);
+        super(parent);
 
         // check session and handles
         if (session == null) {
@@ -211,7 +206,7 @@ public final class DynamicRepositoryClas
                                          final DynamicRepositoryClassLoader old,
                                          final ClassLoader parent) {
         // initialize the super class with an empty class path
-        super(NULL_PATH, parent);
+        super(parent);
 
         // check session and handles
         if (session == null) {
@@ -383,43 +378,6 @@ public final class DynamicRepositoryClas
         return Collections.enumeration(list);
     }
 
-    /**
-     * Returns the search path of URLs for loading classes and resources.
-     * This includes the original list of URLs specified to the constructor,
-     * along with any URLs subsequently appended by the {@link #addURL(URL)}.
-     *
-     * @return the search path of URLs for loading classes and resources. The
-     *      list is empty, if this class loader has already been destroyed.
-     * @see java.net.URLClassLoader#getURLs()
-     */
-    public URL[] getURLs() {
-        if (destroyed) {
-            log.warn("Destroyed class loader has no URLs any more");
-            return NULL_PATH;
-        }
-
-        List<URL> urls = new ArrayList<URL>();
-        for (int i=0; i < repository.length; i++) {
-            URL url = repository[i].toURL();
-            if (url != null) {
-                urls.add(url);
-            }
-        }
-        return urls.toArray(new URL[urls.size()]);
-    }
-
-    /**
-     * We don't allow to add new urls at runtime.
-     * @see java.net.URLClassLoader#addURL(java.net.URL)
-     */
-    protected void addURL(URL url) {
-        if (destroyed) {
-            log.warn("Cannot add URL to destroyed class loader");
-        } else {
-            log.warn("addURL: {} unable to add URL at runtime, ignored", url);
-        }
-    }
-
     //---------- Property access ----------------------------------------------
 
     /**
@@ -617,45 +575,7 @@ public final class DynamicRepositoryClas
 
         Class<?> clazz = res.getLoadedClass();
         if (clazz == null) {
-
-            /**
-             * This following code for packages is duplicate from URLClassLoader
-             * because it is private there. I would like to not be forced to
-             * do this, but I still have to find a way ... -fmeschbe
-             */
-
-            // package support
-            int i = name.lastIndexOf('.');
-            if (i != -1) {
-                String pkgname = name.substring(0, i);
-                // Check if package already loaded.
-                Package pkg = getPackage(pkgname);
-                URL url = res.getCodeSourceURL();
-                Manifest man = res.getManifest();
-                if (pkg != null) {
-                    // Package found, so check package sealing.
-                    boolean ok;
-                    if (pkg.isSealed()) {
-                        // Verify that code source URL is the same.
-                        ok = pkg.isSealed(url);
-                    } else {
-                        // Make sure we are not attempting to seal the package
-                        // at this code source URL.
-                        ok = (man == null) || !isSealed(pkgname, man);
-                    }
-                    if (!ok) {
-                        throw new SecurityException("sealing violation");
-                    }
-                } else {
-                    if (man != null) {
-                        definePackage(pkgname, man, url);
-                    } else {
-                        definePackage(pkgname, null, null, null, null, null, null, null);
-                    }
-                }
-            }
-
-            byte[] data = res.getBytes();
+            final byte[] data = res.getBytes();
             clazz = defineClass(name, data, 0, data.length);
             res.setLoadedClass(clazz);
         }
@@ -663,28 +583,6 @@ public final class DynamicRepositoryClas
         return clazz;
     }
 
-    /**
-     * Returns true if the specified package name is sealed according to the
-     * given manifest
-     * <p>
-     * This code is duplicate from <code>URLClassLoader.isSealed</code> because
-     * the latter has private access and we need the method here.
-     */
-    private boolean isSealed(String name, Manifest man) {
-         String path = name.replace('.', '/').concat("/");
-         Attributes attr = man.getAttributes(path);
-         String sealed = null;
-         if (attr != null) {
-             sealed = attr.getValue(Attributes.Name.SEALED);
-         }
-         if (sealed == null) {
-             if ((attr = man.getMainAttributes()) != null) {
-                 sealed = attr.getValue(Attributes.Name.SEALED);
-             }
-         }
-         return "true".equalsIgnoreCase(sealed);
-    }
-
     //---------- reload support ------------------------------------------------
 
     /**

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java?rev=921262&r1=921261&r2=921262&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
(original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
Wed Mar 10 09:21:14 2010
@@ -20,7 +20,7 @@ package org.apache.sling.jcr.classloader
 
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLClassLoader;
+import java.security.SecureClassLoader;
 import java.util.Enumeration;
 
 import javax.jcr.RepositoryException;
@@ -31,13 +31,11 @@ import org.slf4j.LoggerFactory;
 /**
  * The <code>RepositoryClassLoaderFacade</code> TODO
  */
-class RepositoryClassLoaderFacade extends URLClassLoader {
+class RepositoryClassLoaderFacade extends SecureClassLoader {
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(RepositoryClassLoaderFacade.class);
 
-    private static final URL[] NO_URLS = new URL[0];
-
     private DynamicClassLoaderProviderImpl classLoaderProvider;
     private ClassLoader parent;
     private String[] classPath;
@@ -49,23 +47,13 @@ class RepositoryClassLoaderFacade extend
             String[] classPath) {
 
         // no parent class loader, we delegate to repository class loaders
-        super(NO_URLS, null);
+        super(null);
 
         this.classLoaderProvider = classLoaderProvider;
         this.parent = parent;
         this.classPath = classPath;
     }
 
-    @Override
-    public URL[] getURLs() {
-        try {
-            return getDelegateClassLoader().getURLs();
-        } catch (RepositoryException re) {
-            log.error("Cannot get repository class loader to get URLs", re);
-            return NO_URLS;
-        }
-    }
-
     protected synchronized Class<?> loadClass(String name, boolean resolve) throws
ClassNotFoundException {
         try {
             return this.getDelegateClassLoader().loadClass(name);



Mime
View raw message