24 lines
763 B
Text
24 lines
763 B
Text
|
|
Permissions permissions = new Permissions();
|
|
ProtectionDomain protectionDomain =
|
|
new ProtectionDomain(null, permissions);
|
|
AccessControlContext context = new AccessControlContext(
|
|
new ProtectionDomain[] { protectionDomain });
|
|
|
|
// This is expected to succeed.
|
|
try (FileInputStream in = new FileInputStream(path)) {
|
|
System.out.format("FileInputStream: %s%n", in);
|
|
}
|
|
|
|
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
|
@Override
|
|
public Void run() throws Exception {
|
|
// This code runs with reduced privileges and is
|
|
// expected to fail.
|
|
try (FileInputStream in = new FileInputStream(path)) {
|
|
System.out.format("FileInputStream: %s%n", in);
|
|
}
|
|
return null;
|
|
}
|
|
}, context);
|
|
|