use of java.security.Permission in project jdk8u_jdk by JetBrains.
the class TestLogConfigurationDeadLock method main.
/**
* This test will run both with and without a security manager.
*
* The test starts a number of threads that will call
* LogManager.readConfiguration() concurrently (ReadConf), then starts
* a number of threads that will create new loggers concurrently
* (AddLogger), and then two additional threads: one (Stopper) that
* will stop the test after 4secs (TIME ms), and one DeadlockDetector
* that will attempt to detect deadlocks.
* If after 4secs no deadlock was detected and no exception was thrown
* then the test is considered a success and passes.
*
* This procedure is done twice: once without a security manager and once
* again with a security manager - which means the test takes ~8secs to
* run.
*
* Note that 8sec may not be enough to detect issues if there are some.
* This is a best effort test.
*
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// test without security
System.out.println("No security");
test();
// test with security
System.out.println("\nWith security");
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
if (super.implies(domain, permission))
return true;
// all permissions
return true;
}
});
System.setSecurityManager(new SecurityManager());
test();
}
use of java.security.Permission in project jdk8u_jdk by JetBrains.
the class TestLogConfigurationDeadLockWithConf method main.
/**
* This test will run both with and without a security manager.
*
* The test starts a number of threads that will call
* LogManager.readConfiguration() concurrently (ReadConf), then starts
* a number of threads that will create new loggers concurrently
* (AddLogger), and then two additional threads: one (Stopper) that
* will stop the test after 4secs (TIME ms), and one DeadlockDetector
* that will attempt to detect deadlocks.
* If after 4secs no deadlock was detected and no exception was thrown
* then the test is considered a success and passes.
*
* This procedure is done twice: once without a security manager and once
* again with a security manager - which means the test takes ~8secs to
* run.
*
* Note that 8sec may not be enough to detect issues if there are some.
* This is a best effort test.
*
* @param args the command line arguments
* @throws java.lang.Exception if the test fails.
*/
public static void main(String[] args) throws Exception {
File config = new File(System.getProperty("test.src", "."), "deadlockconf.properties");
if (!config.canRead()) {
System.err.println("Can't read config file: test cannot execute.");
System.err.println("Please check your test environment: ");
System.err.println("\t -Dtest.src=" + System.getProperty("test.src", "."));
System.err.println("\t config file is: " + config.getAbsolutePath());
throw new RuntimeException("Can't read config file: " + config.getAbsolutePath());
}
System.setProperty("java.util.logging.config.file", config.getAbsolutePath());
// test without security
System.out.println("No security");
test();
// test with security
System.out.println("\nWith security");
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
if (super.implies(domain, permission))
return true;
// all permissions
return true;
}
});
System.setSecurityManager(new SecurityManager());
test();
}
use of java.security.Permission in project jdk8u_jdk by JetBrains.
the class bug8078165 method main.
public static void main(final String[] args) throws Exception {
// Mac only
System.setSecurityManager(new SecurityManager() {
@Override
public void checkPermission(Permission permission) {
// Just allows everything
}
});
// The method shouldn't throw NPE
Toolkit.getDefaultToolkit().getImage(new URL("file://./dummyImage@2x.png"));
Toolkit.getDefaultToolkit().getImage("./dummyImage@2x.png");
}
use of java.security.Permission in project robovm by robovm.
the class OldRuntimeTest method test_execLjava_lang_StringArrayLjava_lang_StringArrayLjava_io_File.
public void test_execLjava_lang_StringArrayLjava_lang_StringArrayLjava_io_File() {
String[] envp = getEnv();
File workFolder = Support_Resources.createTempFolder();
checkExec(5, envp, workFolder);
checkExec(5, null, null);
try {
Runtime.getRuntime().exec((String[]) null, null, workFolder);
fail("NullPointerException should be thrown.");
} catch (IOException ioe) {
fail("IOException was thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
Runtime.getRuntime().exec(new String[] { "ls", null }, null, workFolder);
fail("NullPointerException should be thrown.");
} catch (IOException ioe) {
fail("IOException was thrown.");
} catch (NullPointerException npe) {
//expected
}
SecurityManager sm = new SecurityManager() {
public void checkPermission(Permission perm) {
if (perm.getName().equals("checkExec")) {
throw new SecurityException();
}
}
public void checkExec(String cmd) {
throw new SecurityException();
}
};
try {
Runtime.getRuntime().exec(new String[] { "" }, envp, workFolder);
fail("IOException should be thrown.");
} catch (IOException e) {
//expected
}
}
use of java.security.Permission in project robovm by robovm.
the class OldRuntimeTest method test_execLjava_lang_StringLjava_lang_StringArrayLjava_io_File.
public void test_execLjava_lang_StringLjava_lang_StringArrayLjava_io_File() {
String[] envp = getEnv();
File workFolder = Support_Resources.createTempFolder();
checkExec(2, envp, workFolder);
checkExec(2, null, null);
try {
Runtime.getRuntime().exec((String) null, null, workFolder);
fail("NullPointerException should be thrown.");
} catch (IOException ioe) {
fail("IOException was thrown.");
} catch (NullPointerException npe) {
//expected
}
SecurityManager sm = new SecurityManager() {
public void checkPermission(Permission perm) {
if (perm.getName().equals("checkExec")) {
throw new SecurityException();
}
}
public void checkExec(String cmd) {
throw new SecurityException();
}
};
try {
Runtime.getRuntime().exec("", envp, workFolder);
fail("SecurityException should be thrown.");
} catch (IllegalArgumentException iae) {
//expected
} catch (IOException e) {
fail("IOException was thrown.");
}
}
Aggregations