sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1734330 - in /sis/branches/JDK8/core: sis-referencing/src/main/java/org/apache/sis/referencing/factory/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ sis-utility/src/main/java/org/apache/sis/internal/system/
Date Wed, 09 Mar 2016 22:39:28 GMT
Author: desruisseaux
Date: Wed Mar  9 22:39:28 2016
New Revision: 1734330

URL: http://svn.apache.org/viewvc?rev=1734330&view=rev
Log:
Allow some parts of SIS to run in security-constrained environments.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Shutdown.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java?rev=1734330&r1=1734329&r2=1734330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/GeodeticObjectFactory.java
[UTF-8] Wed Mar  9 22:39:28 2016
@@ -26,6 +26,8 @@ import java.util.logging.Logger;
 import java.util.logging.LogRecord;
 import java.util.concurrent.atomic.AtomicReference;
 import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import javax.measure.unit.Unit;
 import javax.measure.quantity.Angle;
 import javax.measure.quantity.Length;
@@ -186,8 +188,9 @@ import org.apache.sis.xml.XML;
  * since localizations are applied by the {@link InternationalString#toString(Locale)} method.</p>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @author  Guilhem Legal (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
 public class GeodeticObjectFactory extends AbstractFactory implements CRSFactory, CSFactory,
DatumFactory, Parser {
@@ -1524,7 +1527,11 @@ public class GeodeticObjectFactory exten
             if (c == null) {
                 c = Class.forName("org.apache.sis.io.wkt.GeodeticObjectParser").asSubclass(Parser.class)
                          .getConstructor(Map.class, ObjectFactory.class, MathTransformFactory.class);
-                c.setAccessible(true);
+                final Constructor<? extends Parser> cp = c;     // For allowing use
in inner class.
+                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                    cp.setAccessible(true);
+                    return null;
+                });
                 parserConstructor = c;
             }
             p = c.newInstance(defaultProperties, this, getMathTransformFactory());

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java?rev=1734330&r1=1734329&r2=1734330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactory.java
[UTF-8] Wed Mar  9 22:39:28 2016
@@ -26,6 +26,8 @@ import java.util.concurrent.atomic.Atomi
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.io.Serializable;
 import javax.measure.quantity.Length;
 import javax.measure.unit.SI;
@@ -1230,7 +1232,7 @@ public class DefaultMathTransformFactory
      *
      * @param  text Math transform encoded in Well-Known Text format.
      * @return The math transform (never {@code null}).
-     * @throws FactoryException if the Well-Known Text can't be parsed,
+     * @throws FactoryException if the Well-Known Text can not be parsed,
      *         or if the math transform creation failed from some other reason.
      */
     @Override
@@ -1242,7 +1244,11 @@ public class DefaultMathTransformFactory
             if (c == null) {
                 c = Class.forName("org.apache.sis.io.wkt.MathTransformParser").asSubclass(Parser.class)
                          .getConstructor(MathTransformFactory.class);
-                c.setAccessible(true);
+                final Constructor<? extends Parser> cp = c;     // For allowing use
in inner class.
+                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                    cp.setAccessible(true);
+                    return null;
+                });
                 parserConstructor = c;
             }
             p = c.newInstance(this);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1734330&r1=1734329&r2=1734330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Wed Mar  9 22:39:28 2016
@@ -20,6 +20,9 @@ import java.util.Map;
 import java.util.IdentityHashMap;
 import java.util.ServiceLoader;
 import java.util.ServiceConfigurationError;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.io.FilePermission;
 import org.apache.sis.internal.util.Utilities;
 
 
@@ -29,8 +32,9 @@ import org.apache.sis.internal.util.Util
  * A candidate replacement is JSR-330.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Guilhem Legal (Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.7
  * @module
  *
  * @see <a href="https://jcp.org/en/jsr/detail?id=330">JSR-330</a>
@@ -85,20 +89,21 @@ public final class DefaultFactories exte
     public static synchronized <T> T forClass(final Class<T> type) {
         T factory = type.cast(FACTORIES.get(type));
         if (factory == null && !FACTORIES.containsKey(type)) {
-            T fallback = null;
-            for (final T candidate : ServiceLoader.load(type)) {
-                if (Utilities.isSIS(candidate.getClass())) {
-                    if (factory != null) {
-                        throw new ServiceConfigurationError("Found two implementations of
" + type);
+            factory = AccessController.doPrivileged((PrivilegedAction<T>) () ->
{
+                T prefered = null;
+                T fallback = null;
+                for (final T candidate : ServiceLoader.load(type)) {
+                    if (Utilities.isSIS(candidate.getClass())) {
+                        if (prefered != null) {
+                            throw new ServiceConfigurationError("Found two implementations
of " + type);
+                        }
+                        prefered = candidate;
+                    } else if (fallback == null) {
+                        fallback = candidate;
                     }
-                    factory = candidate;
-                } else if (fallback == null) {
-                    fallback = candidate;
                 }
-            }
-            if (factory == null) {
-                factory = fallback;
-            }
+                return (prefered != null) ? prefered : fallback;
+            }, null, new FilePermission("<<ALL FILES>>", "read"));       // For
reading META-INF/services/ files.
             /*
              * Verifies if the factory that we just selected is the same implementation than
an existing instance.
              * The main case for this test is org.apache.sis.referencing.factory.GeodeticObjectFactory,
where the

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Shutdown.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Shutdown.java?rev=1734330&r1=1734329&r2=1734330&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Shutdown.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Shutdown.java
[UTF-8] Wed Mar  9 22:39:28 2016
@@ -19,6 +19,8 @@ package org.apache.sis.internal.system;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.concurrent.Callable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import org.apache.sis.util.logging.Logging;
 
 // Branch-dependent imports
@@ -29,6 +31,7 @@ import java.util.Objects;
  * A central place where to manage SIS shutdown process.
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Guilhem Legal (Geomatys)
  * @since   0.3
  * @version 0.7
  * @module
@@ -115,7 +118,10 @@ public final class Shutdown extends Thre
             resources.add(resource);
             if (hook == null && container == null) {
                 hook = new Shutdown();
-                Runtime.getRuntime().addShutdownHook(hook);
+                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                    Runtime.getRuntime().addShutdownHook(hook);
+                    return null;
+                });
             }
         }
     }
@@ -126,7 +132,10 @@ public final class Shutdown extends Thre
     private static void removeShutdownHook() {
         assert Thread.holdsLock(resources);
         if (hook != null) {
-            Runtime.getRuntime().removeShutdownHook(hook);
+            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                Runtime.getRuntime().removeShutdownHook(hook);
+                return null;
+            });
             hook = null;
         }
     }



Mime
View raw message