Search in sources :

Example 1 with LoggingPermission

use of java.util.logging.LoggingPermission in project jdk8u_jdk by JetBrains.

the class TestSetResourceBundle method testPermission.

/**
     * Test the LoggingPermission("control") is required.
     * @param loggerName The logger to use.
     */
public static void testPermission(String loggerName) {
    if (System.getSecurityManager() != null) {
        throw new Error("Security manager is already set");
    }
    Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION));
    System.setSecurityManager(new SecurityManager());
    final ResourceBundle bundle = ResourceBundle.getBundle(LIST_BUNDLE_NAME);
    Logger foobar = Logger.getLogger(loggerName);
    try {
        foobar.setResourceBundle(bundle);
        throw new RuntimeException("Permission not checked!");
    } catch (AccessControlException x) {
        if (x.getPermission() instanceof LoggingPermission) {
            if ("control".equals(x.getPermission().getName())) {
                System.out.println("Got expected exception: " + x);
                return;
            }
        }
        throw new RuntimeException("Unexpected exception: " + x, x);
    }
}
Also used : LoggingPermission(java.util.logging.LoggingPermission) AccessControlException(java.security.AccessControlException) ResourceBundle(java.util.ResourceBundle) Logger(java.util.logging.Logger)

Aggregations

AccessControlException (java.security.AccessControlException)1 ResourceBundle (java.util.ResourceBundle)1 Logger (java.util.logging.Logger)1 LoggingPermission (java.util.logging.LoggingPermission)1