sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1734483 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ core/sis-utility/src/main/java/org/apache/sis/internal/system/ core/sis-utility/src/main/java/org/apache/sis/setup/ core/sis-utility/src...
Date Thu, 10 Mar 2016 23:34:20 GMT
Author: desruisseaux
Date: Thu Mar 10 23:34:19 2016
New Revision: 1734483

URL: http://svn.apache.org/viewvc?rev=1734483&view=rev
Log:
Tune some AccessController.doPrivileged(...) calls and add a security.policy file that developers
can use as a template.
This work is based on Guilhem L├ęgal work (SIS-320).

Added:
    sis/branches/JDK8/src/main/config/
    sis/branches/JDK8/src/main/config/logging.properties   (with props)
    sis/branches/JDK8/src/main/config/security.policy   (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1734483&r1=1734482&r2=1734483&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Thu Mar 10 23:34:19 2016
@@ -23,6 +23,8 @@ import java.util.ServiceLoader;
 import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.lang.reflect.Method;
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -242,7 +244,7 @@ public abstract class Initializer {
              * As a fallback, try to open the Derby database located in $SIS_DATA/Databases/SpatialMetadata
directory.
              */
             final boolean create;
-            final String home = System.getProperty(DERBY_HOME_KEY);
+            final String home = AccessController.doPrivileged((PrivilegedAction<String>)
() -> System.getProperty(DERBY_HOME_KEY));
             final Path dir = DataDirectory.DATABASES.getDirectory();
             if (dir != null) {
                 Path path = dir.resolve(DATABASE);
@@ -308,7 +310,8 @@ public abstract class Initializer {
      */
     public static boolean hasJNDI() {
         return NamingManager.hasInitialContextFactoryBuilder() ||
-               System.getProperty(Context.INITIAL_CONTEXT_FACTORY) != null;
+               AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
+                       System.getProperty(Context.INITIAL_CONTEXT_FACTORY) != null);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java?rev=1734483&r1=1734482&r2=1734483&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
[UTF-8] Thu Mar 10 23:34:19 2016
@@ -115,9 +115,7 @@ public enum DataDirectory {
      */
     public static synchronized Path getRootDirectory() {
         if (rootDirectory == null) try {
-            final String dir = AccessController.doPrivileged((PrivilegedAction<String>)
() -> {
-                return System.getenv(ENV);
-            });
+            final String dir = AccessController.doPrivileged((PrivilegedAction<String>)
() -> System.getenv(ENV));
             if (dir == null || dir.isEmpty()) {
                 warning("getRootDirectory", null, Messages.Keys.DataDirectoryNotSpecified_1,
ENV);
             } else try {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java?rev=1734483&r1=1734482&r2=1734483&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Supervisor.java
[UTF-8] Thu Mar 10 23:34:19 2016
@@ -70,7 +70,7 @@ public final class Supervisor extends St
      * The JMX object name, created when the {@link #register()} is first invoked.
      * {@link ObjectName#WILDCARD} is used as a sentinel value if the registration failed.
      */
-    private static ObjectName name;
+    private static volatile ObjectName name;
 
     /**
      * Registers the {@code Supervisor} instance, if not already done.
@@ -84,19 +84,23 @@ public final class Supervisor extends St
     public static synchronized void register() {
         if (name == null) {
             name = ObjectName.WILDCARD;                         // In case of failure.
+            final LogRecord record;
             try {
                 final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                 final ObjectName n = new ObjectName(NAME);
                 server.registerMBean(new Supervisor(), n);
-                name = n; // Store only on success.
+                name = n;                                    // Store only on success.
+                return;
             } catch (InstanceAlreadyExistsException e) {
-                final LogRecord record = Messages.getResources(null)
-                        .getLogRecord(Level.CONFIG, Messages.Keys.AlreadyRegistered_2, "MBean",
NAME);
-                record.setLoggerName(Loggers.SYSTEM);
-                Logging.log(Supervisor.class, "register", record);
-            } catch (SecurityException | JMException e) {
-                Logging.unexpectedException(Logging.getLogger(Loggers.SYSTEM), Supervisor.class,
"register", e);
+                record = Messages.getResources(null).getLogRecord(Level.CONFIG, Messages.Keys.AlreadyRegistered_2,
"MBean", NAME);
+            } catch (JMException e) {
+                record = new LogRecord(Level.WARNING, e.toString());
+                record.setThrown(e);
+            } catch (SecurityException e) {
+                record = new LogRecord(Level.CONFIG, e.toString());
             }
+            record.setLoggerName(Loggers.SYSTEM);
+            Logging.log(Supervisor.class, "register", record);
         }
     }
 

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java?rev=1734483&r1=1734482&r2=1734483&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/About.java [UTF-8]
Thu Mar 10 23:34:19 2016
@@ -355,9 +355,7 @@ fill:   for (int i=0; ; i++) {
                     if (sections.contains(PATHS)) {
                         nameKey = Vocabulary.Keys.DataDirectory;
                         try {
-                            value = AccessController.doPrivileged((PrivilegedAction<String>)
() -> {
-                                return System.getenv(DataDirectory.ENV);
-                            });
+                            value = AccessController.doPrivileged((PrivilegedAction<String>)
() -> System.getenv(DataDirectory.ENV));
                         } catch (SecurityException e) {
                             value = e.toString();
                         }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1734483&r1=1734482&r2=1734483&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] Thu Mar 10 23:34:19 2016
@@ -376,7 +376,7 @@ public final class Logging extends Stati
          * than the locale on the client side.
          */
         final StringBuilder buffer = new StringBuilder(256).append(Classes.getShortClassName(error));
-        String message = error.getMessage(); // Targeted to system administrators.
+        String message = error.getMessage();                    // Targeted to system administrators.
         if (message != null) {
             buffer.append(": ").append(message);
         }

Added: sis/branches/JDK8/src/main/config/logging.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/src/main/config/logging.properties?rev=1734483&view=auto
==============================================================================
--- sis/branches/JDK8/src/main/config/logging.properties (added)
+++ sis/branches/JDK8/src/main/config/logging.properties [UTF-8] Thu Mar 10 23:34:19 2016
@@ -0,0 +1,23 @@
+##################################################################################
+#                                                                                #
+#                    Logging configuration file for debugging                    #
+#                                                                                #
+#  This configuration file uses a finer logging level than the default setting   #
+#  defined by "$JAVA_HOME/jre/lib/logging.properties" file. This configuration   #
+#  can be enabled by adding the following argument when launching Java (replace  #
+#  "$SIS_SOURCE" by the root directory of Apache SIS project and "/" by the      #
+#  platform-specific path separator).                                            #
+#                                                                                #
+# -Djava.util.logging.config.file=$SIS_SOURCE/src/main/config/logging.properties #
+#                                                                                #
+##################################################################################
+
+# Handlers installed during VM startup.
+# These classes must be on the system classpath.
+handlers= java.util.logging.ConsoleHandler
+
+# Default global logging level.
+.level= CONFIG
+
+# Set the message that are printed on the console to INFO and above.
+java.util.logging.ConsoleHandler.level = CONFIG

Propchange: sis/branches/JDK8/src/main/config/logging.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/src/main/config/logging.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/src/main/config/security.policy
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/src/main/config/security.policy?rev=1734483&view=auto
==============================================================================
--- sis/branches/JDK8/src/main/config/security.policy (added)
+++ sis/branches/JDK8/src/main/config/security.policy [UTF-8] Thu Mar 10 23:34:19 2016
@@ -0,0 +1,49 @@
+//
+// Security policy for running Apache SIS in a security-constrained environment.
+// The first grant block below contains the permissions that are most likely to
+// be needed for SIS use. Other grant block contains permissions needed only if
+// the JavaDB is used or if MBeans monitoring is desired.
+//
+grant {
+  permission java.lang.RuntimePermission          "shutdownHooks";
+  permission java.lang.RuntimePermission          "getenv.SIS_DATA";
+  permission java.util.PropertyPermission         "java.naming.factory.initial", "read";
+  permission java.util.PropertyPermission         "derby.system.home", "read";
+  permission java.lang.RuntimePermission          "getClassLoader";
+  permission java.lang.reflect.ReflectPermission  "suppressAccessChecks";
+
+  // Actually only need access to the ${SIS_DATA} directory.
+  // The read and delete actions are needed for Derby and may be omitted if another
+  // database is used (e.g. PostgreSQL). Read operations may also be omitted too if
+  // another database is used and no other files (e.g. datum shift grids) is needed.
+  permission java.io.FilePermission "${user.home}${/}-", "read,write,delete";
+};
+
+
+
+//
+// Optional permissions for using the JavaDB embedded with Oracle JDK.
+// Some or all of those permissions can be omitted if a Derby driver
+// or another database driver (e.g. PostgreSQL) is on the classpath.
+//
+grant {
+  permission java.io.FilePermission        "${user.dir}${/}derby.log", "read,write,delete";
+  permission java.io.FilePermission        "${java.home}${/}..${/}db${/}lib${/}derby.jar",
"read";
+  permission java.util.PropertyPermission  "java.home", "read";
+  permission java.util.PropertyPermission  "derby.*", "read";
+  permission java.lang.RuntimePermission   "getClassLoader";
+  permission java.lang.RuntimePermission   "createClassLoader";
+  permission java.lang.RuntimePermission   "setContextClassLoader";
+};
+
+
+
+//
+// Optional permissions. If those permissions are not granted, a message
+// will be logged at Level.CONFIG and JMX monitoring will be disabled.
+//
+grant {
+  permission javax.management.MBeanServerPermission  "createMBeanServer";
+  permission javax.management.MBeanPermission        "org.apache.sis.internal.system.Supervisor#-[org.apache.sis:type=Supervisor]",
"registerMBean,unregisterMBean";
+  permission javax.management.MBeanTrustPermission   "register";
+};

Propchange: sis/branches/JDK8/src/main/config/security.policy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/src/main/config/security.policy
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message