src/share/classes/java/util/logging/Handler.java

Print this page

        

@@ -25,10 +25,13 @@
 
 
 package java.util.logging;
 
 import java.io.UnsupportedEncodingException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 /**
  * A <tt>Handler</tt> object takes log messages from a <tt>Logger</tt> and
  * exports them.  It might for example, write them to a console
  * or write them to a file, or send them to a network logging service,
  * or forward them to an OS log, or whatever.

@@ -60,14 +63,10 @@
     private volatile Formatter formatter;
     private volatile Level logLevel = Level.ALL;
     private volatile ErrorManager errorManager = new ErrorManager();
     private volatile String encoding;
 
-    // Package private support for security checking.  When sealed
-    // is true, we access check updates to the class.
-    boolean sealed = true;
-
     /**
      * Default constructor.  The resulting <tt>Handler</tt> has a log
      * level of <tt>Level.ALL</tt>, no <tt>Formatter</tt>, and no
      * <tt>Filter</tt>.  A default <tt>ErrorManager</tt> instance is installed
      * as the <tt>ErrorManager</tt>.

@@ -300,14 +299,22 @@
         }
         return filter.isLoggable(record);
     }
 
     // Package-private support method for security checks.
-    // If "sealed" is true, we check that the caller has
-    // appropriate security privileges to update Handler
-    // state and if not throw a SecurityException.
+    // We check that the caller has appropriate security privileges
+    // to update Handler state and if not throw a SecurityException.
     void checkPermission() throws SecurityException {
-        if (sealed) {
             manager.checkPermission();
         }
+
+    // Package-private support for executing actions with additional
+    // LoggingPermission("control", null) permission.
+    interface PrivilegedVoidAction extends PrivilegedAction<Void> {
+        default Void run() { runVoid(); return null; }
+        void runVoid();
+    }
+
+    void doWithControlPermission(PrivilegedVoidAction action) {
+        AccessController.doPrivileged(action, null, LogManager.controlPermission);
     }
 }