openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r577863 - in /openjpa/branches/1.0.x: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/util/ openjpa-lib/src/main/java/org/apach...
Date Thu, 20 Sep 2007 18:39:01 GMT
Author: mikedd
Date: Thu Sep 20 11:39:00 2007
New Revision: 577863

URL: http://svn.apache.org/viewvc?rev=577863&view=rev
Log:
OPENJPA-339

Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
    openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
    openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
    openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
    openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
Thu Sep 20 11:39:00 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.datacache;
 
+import java.security.AccessController;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -28,6 +29,7 @@
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
 import org.apache.openjpa.util.InvalidStateException;
@@ -97,7 +99,9 @@
         _caches.put(cache, schedule);
         _stop = false;
         if (_thread == null) {
-            _thread = new Thread(this, _loc.get("scheduler-name").getMessage());
+            _thread = (Thread) AccessController
+                .doPrivileged(J2DoPrivHelper.newThreadAction(this, _loc.get(
+                    "scheduler-name").getMessage()));
             _thread.setDaemon(true);
             _thread.start();
             if (_log.isTraceEnabled())

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Thu Sep 20 11:39:00 2007
@@ -19,6 +19,7 @@
 package org.apache.openjpa.meta;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -656,9 +657,15 @@
                     if (log.isTraceEnabled())
                         log.trace(_loc.get("scan-found-names", clss, file));
                     names.addAll(Arrays.asList(clss));
-                    mapPersistentTypeNames(((File) AccessController
+                    File f = (File) AccessController
                         .doPrivileged(J2DoPrivHelper
-                            .getAbsoluteFileAction(file))).toURL(), clss);
+                            .getAbsoluteFileAction(file));
+                    try {
+                        mapPersistentTypeNames(AccessController
+                            .doPrivileged(J2DoPrivHelper.toURLAction(f)), clss);
+                    } catch (PrivilegedActionException pae) {
+                        throw (FileNotFoundException) pae.getException();
+                    }
                 }
             }
         }

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java
Thu Sep 20 11:39:00 2007
@@ -26,6 +26,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.sql.Timestamp;
 import java.util.ArrayList;
@@ -438,7 +439,7 @@
      * Return the cached factory proxy for the given bean type.
      */
     private ProxyBean getFactoryProxyBean(Object orig) {
-        Class type = orig.getClass();
+        final Class type = orig.getClass();
         if (isUnproxyable(type))
             return null;
 
@@ -449,7 +450,12 @@
                 ProxyBean.class);
             Class pcls = loadBuildTimeProxy(type, l);
             if (pcls == null) {
-                BCClass bc = generateProxyBeanBytecode(type, true);
+                BCClass bc = (BCClass) AccessController
+                    .doPrivileged(new PrivilegedAction() {
+                        public Object run() {
+                            return generateProxyBeanBytecode(type, true);
+                        }
+                    });
                 if (bc != null)
                     pcls = GeneratedClasses.loadBCClass(bc, l);
             }
@@ -517,7 +523,8 @@
         boolean runtime) {
         assertNotFinal(type);
         Project project = new Project(); 
-        BCClass bc = project.loadClass(getProxyClassName(type, runtime));
+        BCClass bc = (BCClass) AccessController.doPrivileged(J2DoPrivHelper
+            .loadProjectClassAction(project, getProxyClassName(type, runtime))); 
         bc.setSuperclass(type);
         bc.declareInterface(ProxyCollection.class);
  
@@ -554,7 +561,8 @@
     protected BCClass generateProxyMapBytecode(Class type, boolean runtime) {
         assertNotFinal(type);
         Project project = new Project(); 
-        BCClass bc = project.loadClass(getProxyClassName(type, runtime));
+        BCClass bc = (BCClass) AccessController.doPrivileged(J2DoPrivHelper
+            .loadProjectClassAction(project, getProxyClassName(type, runtime))); 
         bc.setSuperclass(type);
         bc.declareInterface(ProxyMap.class);
  
@@ -573,7 +581,8 @@
     protected BCClass generateProxyDateBytecode(Class type, boolean runtime) {
         assertNotFinal(type);
         Project project = new Project(); 
-        BCClass bc = project.loadClass(getProxyClassName(type, runtime));
+        BCClass bc = (BCClass) AccessController.doPrivileged(J2DoPrivHelper
+            .loadProjectClassAction(project, getProxyClassName(type, runtime))); 
         bc.setSuperclass(type);
         bc.declareInterface(ProxyDate.class);
  
@@ -592,7 +601,8 @@
         boolean runtime) {
         assertNotFinal(type);
         Project project = new Project(); 
-        BCClass bc = project.loadClass(getProxyClassName(type, runtime));
+        BCClass bc = (BCClass) AccessController.doPrivileged(J2DoPrivHelper
+            .loadProjectClassAction(project, getProxyClassName(type, runtime))); 
         bc.setSuperclass(type);
         bc.declareInterface(ProxyCalendar.class);
  
@@ -626,7 +636,8 @@
         }
 
         Project project = new Project(); 
-        BCClass bc = project.loadClass(getProxyClassName(type, runtime));
+        BCClass bc = (BCClass) AccessController.doPrivileged(J2DoPrivHelper
+            .loadProjectClassAction(project, getProxyClassName(type, runtime))); 
         bc.setSuperclass(type);
         bc.declareInterface(ProxyBean.class);
  
@@ -1596,7 +1607,7 @@
             })); 
         }
 
-        ProxyManagerImpl mgr = new ProxyManagerImpl();
+        final ProxyManagerImpl mgr = new ProxyManagerImpl();
         Class cls;
         BCClass bc;
         for (int i = 0; i < types.size(); i++) {
@@ -1618,8 +1629,15 @@
                 bc = mgr.generateProxyDateBytecode(cls, false);
             else if (Calendar.class.isAssignableFrom(cls))
                 bc = mgr.generateProxyCalendarBytecode(cls, false);
-            else
-                bc = mgr.generateProxyBeanBytecode(cls, false);
+            else {
+                final Class fCls = cls;
+                bc = (BCClass) AccessController
+                    .doPrivileged(new PrivilegedAction() {
+                        public Object run() {
+                            return mgr.generateProxyBeanBytecode(fCls, false);
+                        }
+                    });
+            }
 
             System.out.println(bc.getName());
             bc.write(new File(dir, bc.getClassName() + ".class"));

Modified: openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
(original)
+++ openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java
Thu Sep 20 11:39:00 2007
@@ -24,6 +24,7 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.util.ArrayList;
@@ -111,8 +112,14 @@
             throw new NoSuchElementException();
 
         _file = (File) _itr.next();
-        return ((File) AccessController.doPrivileged(J2DoPrivHelper
-            .getAbsoluteFileAction(_file))).toURL();
+        try {
+            File f = (File) AccessController.doPrivileged(J2DoPrivHelper
+                .getAbsoluteFileAction(_file));
+            return AccessController.doPrivileged(
+                J2DoPrivHelper.toURLAction(f));
+        } catch (PrivilegedActionException pae) {
+            throw (MalformedURLException) pae.getException();
+        }
     }
 
     public InputStream getInputStream() throws IOException {

Modified: openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
(original)
+++ openjpa/branches/1.0.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
Thu Sep 20 11:39:00 2007
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.lang.reflect.AccessibleObject;
 import java.net.InetAddress;
+import java.net.MalformedURLException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URL;
@@ -69,6 +70,7 @@
  * <li>File.isDirectory
  * <li>File.mkdirs
  * <li>File.renameTo
+ * <li>File.toURL
  * <li>FileInputStream new
  * <li>FileOutputStream new
  * <li>System.getProperties
@@ -79,6 +81,7 @@
  * <li>Socket.accept
  * <li>System.getProperty
  * <li>Thread.getContextClassLoader
+ * <li>Thread new
  * <li>TemporaryClassLoader new
  * <li>URL.openStream
  * <li>URLConnection.getContent
@@ -594,6 +597,24 @@
     }
 
     /**
+     * Return a PrivilegedExceptionAction object for f.toURL().
+     * 
+     * Requires security policy:
+     *   'permission java.io.FilePermission "read";'
+     *   
+     * @return Boolean
+     * @throws MalformedURLException
+     */
+    public static final PrivilegedExceptionAction toURLAction(final File file)
+        throws MalformedURLException {
+        return new PrivilegedExceptionAction() {
+            public Object run() throws MalformedURLException {
+                return file.toURL();
+            }
+        };
+    }
+
+    /**
      * Return a PrivilegedExceptionAction object for new FileInputStream().
      * 
      * Requires security policy:
@@ -769,6 +790,23 @@
     }
 
     /**
+     * Return a PrivilegedAction object for new Thread().
+     * 
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "modifyThreadGroup";'
+     * 
+     * @return Thread
+     */
+    public static final PrivilegedAction newThreadAction(
+        final Runnable target, final String name) {
+        return new PrivilegedAction() {
+            public Object run() {
+                return new Thread(target, name);
+            }
+        };
+    }
+
+    /**
      * Return a PrivilegedExceptionAction object for url.openStream().
      * 
      * Requires security policy:
@@ -963,6 +1001,23 @@
         return new PrivilegedAction() {
             public Object run() {
                 return project.loadClass(clazz);
+            }
+        };
+    }
+    
+    /**
+     * Return a PrivilegeAction object for Project.loadClass().
+     * 
+     * Requires security policy:
+     *   'permission java.lang.RuntimePermission "getClassLoader";'
+     *   
+     * @return BCClass
+     */
+    public static final PrivilegedAction loadProjectClassAction(
+        final Project project, final String clazzName) {
+        return new PrivilegedAction() {
+            public Object run() {
+                return project.loadClass(clazzName);
             }
         };
     }

Modified: openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
Thu Sep 20 11:39:00 2007
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
@@ -458,7 +459,12 @@
         @Override
         public void parse(File file)
             throws IOException {
-            _source = file.toURL();
+            try {
+                _source = (URL) AccessController.doPrivileged(J2DoPrivHelper
+                    .toURLAction(file));
+            } catch (PrivilegedActionException pae) {
+                throw (MalformedURLException) pae.getException();
+            }
             super.parse(file);
         }
 

Modified: openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java?rev=577863&r1=577862&r2=577863&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
(original)
+++ openjpa/branches/1.0.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
Thu Sep 20 11:39:00 2007
@@ -24,6 +24,7 @@
 import java.net.URL;
 import java.net.URLDecoder;
 import java.security.AccessController;
+import java.security.PrivilegedActionException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -219,8 +220,12 @@
             if (cp[i].equals(name)
                 || cp[i].endsWith(File.separatorChar + name)) {
                 try {
-                    addJarFile(new File(cp[i]).toURL());
+                    addJarFile((URL) AccessController
+                        .doPrivileged(J2DoPrivHelper
+                            .toURLAction(new File(cp[i]))));
                     return;
+                } catch (PrivilegedActionException pae) {
+                    break;
                 } catch (MalformedURLException mue) {
                     break;
                 }



Mime
View raw message