jdk/src/share/classes/java/util/logging/LogManager.java
changeset 14216 23714b376286
parent 13578 cb435d74ab6b
child 16098 9001e536ab4e
child 14229 40fbffe104bd
equal deleted inserted replaced
13644:063cbb0da3d3 14216:23714b376286
   312      *             the caller does not have LoggingPermission("control").
   312      *             the caller does not have LoggingPermission("control").
   313      * @exception NullPointerException if the PropertyChangeListener is null.
   313      * @exception NullPointerException if the PropertyChangeListener is null.
   314      */
   314      */
   315     public void addPropertyChangeListener(PropertyChangeListener l) throws SecurityException {
   315     public void addPropertyChangeListener(PropertyChangeListener l) throws SecurityException {
   316         PropertyChangeListener listener = Objects.requireNonNull(l);
   316         PropertyChangeListener listener = Objects.requireNonNull(l);
   317         checkAccess();
   317         checkPermission();
   318         synchronized (listenerMap) {
   318         synchronized (listenerMap) {
   319             // increment the registration count if already registered
   319             // increment the registration count if already registered
   320             Integer value = listenerMap.get(listener);
   320             Integer value = listenerMap.get(listener);
   321             value = (value == null) ? 1 : (value + 1);
   321             value = (value == null) ? 1 : (value + 1);
   322             listenerMap.put(listener, value);
   322             listenerMap.put(listener, value);
   336      * @param l  event listener (can be null)
   336      * @param l  event listener (can be null)
   337      * @exception  SecurityException  if a security manager exists and if
   337      * @exception  SecurityException  if a security manager exists and if
   338      *             the caller does not have LoggingPermission("control").
   338      *             the caller does not have LoggingPermission("control").
   339      */
   339      */
   340     public void removePropertyChangeListener(PropertyChangeListener l) throws SecurityException {
   340     public void removePropertyChangeListener(PropertyChangeListener l) throws SecurityException {
   341         checkAccess();
   341         checkPermission();
   342         if (l != null) {
   342         if (l != null) {
   343             PropertyChangeListener listener = l;
   343             PropertyChangeListener listener = l;
   344             synchronized (listenerMap) {
   344             synchronized (listenerMap) {
   345                 Integer value = listenerMap.get(listener);
   345                 Integer value = listenerMap.get(listener);
   346                 if (value != null) {
   346                 if (value != null) {
   791      * @exception  SecurityException  if a security manager exists and if
   791      * @exception  SecurityException  if a security manager exists and if
   792      *             the caller does not have LoggingPermission("control").
   792      *             the caller does not have LoggingPermission("control").
   793      * @exception  IOException if there are IO problems reading the configuration.
   793      * @exception  IOException if there are IO problems reading the configuration.
   794      */
   794      */
   795     public void readConfiguration() throws IOException, SecurityException {
   795     public void readConfiguration() throws IOException, SecurityException {
   796         checkAccess();
   796         checkPermission();
   797 
   797 
   798         // if a configuration class is specified, load it and use it.
   798         // if a configuration class is specified, load it and use it.
   799         String cname = System.getProperty("java.util.logging.config.class");
   799         String cname = System.getProperty("java.util.logging.config.class");
   800         if (cname != null) {
   800         if (cname != null) {
   801             try {
   801             try {
   849      * @exception  SecurityException  if a security manager exists and if
   849      * @exception  SecurityException  if a security manager exists and if
   850      *             the caller does not have LoggingPermission("control").
   850      *             the caller does not have LoggingPermission("control").
   851      */
   851      */
   852 
   852 
   853     public void reset() throws SecurityException {
   853     public void reset() throws SecurityException {
   854         checkAccess();
   854         checkPermission();
   855         synchronized (this) {
   855         synchronized (this) {
   856             props = new Properties();
   856             props = new Properties();
   857             // Since we are doing a reset we no longer want to initialize
   857             // Since we are doing a reset we no longer want to initialize
   858             // the global handlers, if they haven't been initialized yet.
   858             // the global handlers, if they haven't been initialized yet.
   859             initializedGlobalHandlers = true;
   859             initializedGlobalHandlers = true;
   934      * @exception  SecurityException  if a security manager exists and if
   934      * @exception  SecurityException  if a security manager exists and if
   935      *             the caller does not have LoggingPermission("control").
   935      *             the caller does not have LoggingPermission("control").
   936      * @exception  IOException if there are problems reading from the stream.
   936      * @exception  IOException if there are problems reading from the stream.
   937      */
   937      */
   938     public void readConfiguration(InputStream ins) throws IOException, SecurityException {
   938     public void readConfiguration(InputStream ins) throws IOException, SecurityException {
   939         checkAccess();
   939         checkPermission();
   940         reset();
   940         reset();
   941 
   941 
   942         // Load the properties
   942         // Load the properties
   943         props.load(ins);
   943         props.load(ins);
   944         // Instantiate new configuration objects.
   944         // Instantiate new configuration objects.
  1111             return;
  1111             return;
  1112         }
  1112         }
  1113         loadLoggerHandlers(rootLogger, null, "handlers");
  1113         loadLoggerHandlers(rootLogger, null, "handlers");
  1114     }
  1114     }
  1115 
  1115 
  1116 
  1116     private final Permission controlPermission = new LoggingPermission("control", null);
  1117     private Permission ourPermission = new LoggingPermission("control", null);
  1117 
       
  1118     void checkPermission() {
       
  1119         SecurityManager sm = System.getSecurityManager();
       
  1120         if (sm != null)
       
  1121             sm.checkPermission(controlPermission);
       
  1122     }
  1118 
  1123 
  1119     /**
  1124     /**
  1120      * Check that the current context is trusted to modify the logging
  1125      * Check that the current context is trusted to modify the logging
  1121      * configuration.  This requires LoggingPermission("control").
  1126      * configuration.  This requires LoggingPermission("control").
  1122      * <p>
  1127      * <p>
  1125      *
  1130      *
  1126      * @exception  SecurityException  if a security manager exists and if
  1131      * @exception  SecurityException  if a security manager exists and if
  1127      *             the caller does not have LoggingPermission("control").
  1132      *             the caller does not have LoggingPermission("control").
  1128      */
  1133      */
  1129     public void checkAccess() throws SecurityException {
  1134     public void checkAccess() throws SecurityException {
  1130         SecurityManager sm = System.getSecurityManager();
  1135         checkPermission();
  1131         if (sm == null) {
       
  1132             return;
       
  1133         }
       
  1134         sm.checkPermission(ourPermission);
       
  1135     }
  1136     }
  1136 
  1137 
  1137     // Nested class to represent a node in our tree of named loggers.
  1138     // Nested class to represent a node in our tree of named loggers.
  1138     private static class LogNode {
  1139     private static class LogNode {
  1139         HashMap<String,LogNode> children;
  1140         HashMap<String,LogNode> children;