< prev index next >

test/jdk/java/util/logging/RootLogger/RootLevelInConfigFile.java

Print this page
rev 51958 : 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
Reviewed-by: alanb, dfuchs, kvn
   1 /*
   2  * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;
  25 import java.io.FilePermission;
  26 import java.io.IOException;
  27 import java.security.Permission;
  28 import java.security.PermissionCollection;
  29 import java.security.Permissions;
  30 import java.security.Policy;
  31 import java.security.ProtectionDomain;
  32 import java.util.PropertyPermission;
  33 import java.util.logging.Level;
  34 import java.util.logging.LogManager;
  35 import java.util.logging.Logger;
  36 import java.util.logging.LoggingPermission;
  37 import jdk.internal.misc.JavaAWTAccess;
  38 import jdk.internal.misc.SharedSecrets;
  39 
  40 /**
  41  * @test
  42  * @bug 8030850
  43  * @summary Tests that setting .level=FINEST for the root logger in logging
  44  *      configuration file does work.
  45  * @modules java.base/jdk.internal.misc
  46  *          java.logging
  47  * @run main/othervm RootLevelInConfigFile
  48  *
  49  * @author danielfuchs
  50  */
  51 public class RootLevelInConfigFile {
  52 
  53     public static final String CONFIG_FILE_KEY = "java.util.logging.config.file";
  54 
  55     public static void main(String[] args) throws IOException {
  56         System.setProperty(CONFIG_FILE_KEY,
  57                 new File(System.getProperty("test.src", "."),
  58                         "rootlogger.properties").getAbsolutePath());
  59         System.out.println(CONFIG_FILE_KEY + "="
  60                 + System.getProperty(CONFIG_FILE_KEY));
  61         if (! new File(System.getProperty(CONFIG_FILE_KEY)).canRead()) {
  62             throw new RuntimeException("can't read config file: "
  63                     + System.getProperty(CONFIG_FILE_KEY));
  64         }
  65 


 165 
 166         if (!global.isLoggable(Level.FINER)) {
 167             throw new RuntimeException("Expected FINER to be loggable in "
 168                     + global.getName());
 169         }
 170         if (!global.getParent().isLoggable(Level.FINER)) {
 171             throw new RuntimeException("Expected FINER to be loggable in "
 172                     + global.getName());
 173         }
 174 
 175     }
 176 
 177     static final class SimplePolicy extends Policy {
 178 
 179         final PermissionCollection perms = new Permissions();
 180         public SimplePolicy(String configFile) {
 181             perms.add(new LoggingPermission("control", null));
 182             perms.add(new PropertyPermission("java.util.logging.config.class","read"));
 183             perms.add(new PropertyPermission("java.util.logging.config.file","read"));
 184             perms.add(new FilePermission(configFile, "read"));
 185             perms.add(new RuntimePermission("accessClassInPackage.jdk.internal.misc"));
 186         }
 187 
 188         @Override
 189         public boolean implies(ProtectionDomain domain, Permission permission) {
 190             return perms.implies(permission);
 191         }
 192     }
 193 
 194     static enum Context { ONE, TWO };
 195 
 196     static final class JavaAWTAccessStub implements JavaAWTAccess {
 197         private Context context;
 198 
 199         public void setContext(Context context) {
 200             this.context = context;
 201         }
 202 
 203         @Override
 204         public Object getAppletContext() {
 205             return context;
   1 /*
   2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.File;
  25 import java.io.FilePermission;
  26 import java.io.IOException;
  27 import java.security.Permission;
  28 import java.security.PermissionCollection;
  29 import java.security.Permissions;
  30 import java.security.Policy;
  31 import java.security.ProtectionDomain;
  32 import java.util.PropertyPermission;
  33 import java.util.logging.Level;
  34 import java.util.logging.LogManager;
  35 import java.util.logging.Logger;
  36 import java.util.logging.LoggingPermission;
  37 import jdk.internal.access.JavaAWTAccess;
  38 import jdk.internal.access.SharedSecrets;
  39 
  40 /**
  41  * @test
  42  * @bug 8030850
  43  * @summary Tests that setting .level=FINEST for the root logger in logging
  44  *      configuration file does work.
  45  * @modules java.base/jdk.internal.access
  46  *          java.logging
  47  * @run main/othervm RootLevelInConfigFile
  48  *
  49  * @author danielfuchs
  50  */
  51 public class RootLevelInConfigFile {
  52 
  53     public static final String CONFIG_FILE_KEY = "java.util.logging.config.file";
  54 
  55     public static void main(String[] args) throws IOException {
  56         System.setProperty(CONFIG_FILE_KEY,
  57                 new File(System.getProperty("test.src", "."),
  58                         "rootlogger.properties").getAbsolutePath());
  59         System.out.println(CONFIG_FILE_KEY + "="
  60                 + System.getProperty(CONFIG_FILE_KEY));
  61         if (! new File(System.getProperty(CONFIG_FILE_KEY)).canRead()) {
  62             throw new RuntimeException("can't read config file: "
  63                     + System.getProperty(CONFIG_FILE_KEY));
  64         }
  65 


 165 
 166         if (!global.isLoggable(Level.FINER)) {
 167             throw new RuntimeException("Expected FINER to be loggable in "
 168                     + global.getName());
 169         }
 170         if (!global.getParent().isLoggable(Level.FINER)) {
 171             throw new RuntimeException("Expected FINER to be loggable in "
 172                     + global.getName());
 173         }
 174 
 175     }
 176 
 177     static final class SimplePolicy extends Policy {
 178 
 179         final PermissionCollection perms = new Permissions();
 180         public SimplePolicy(String configFile) {
 181             perms.add(new LoggingPermission("control", null));
 182             perms.add(new PropertyPermission("java.util.logging.config.class","read"));
 183             perms.add(new PropertyPermission("java.util.logging.config.file","read"));
 184             perms.add(new FilePermission(configFile, "read"));
 185             perms.add(new RuntimePermission("accessClassInPackage.jdk.internal.access"));
 186         }
 187 
 188         @Override
 189         public boolean implies(ProtectionDomain domain, Permission permission) {
 190             return perms.implies(permission);
 191         }
 192     }
 193 
 194     static enum Context { ONE, TWO };
 195 
 196     static final class JavaAWTAccessStub implements JavaAWTAccess {
 197         private Context context;
 198 
 199         public void setContext(Context context) {
 200             this.context = context;
 201         }
 202 
 203         @Override
 204         public Object getAppletContext() {
 205             return context;
< prev index next >