...
Code Block | ||
---|---|---|
| ||
import java.security.*; public class Trusted { public static void loadLibrary(final String library){ AccessController.doPrivileged(new PrivilegedAction<Void>() { public Void run() { System.loadLibrary(library); return null; } }); } } //////////////////////////////////////////////////////////////////////////////////// public class Untrusted { static{ System.setProperty("java.security.policy", "java.policy"); SecurityManager sm = new SecurityManager(); System.setSecurityManager(sm); System.out.println("Allowed!"); } private native void sayHello(); public static void main(String[] args) { String library = new String("HelloImpl"); Trusted.loadLibrary(library); new Untrusted.sayHello(); // invoke the native method } } |
Compliant Solution
Code Block | ||
---|---|---|
| ||
...