Java SecurityManager .checkPermission (Permission perm, Object context)
Syntax
SecurityManager.checkPermission(Permission perm, Object context) has the following syntax.
public void checkPermission(Permission perm, Object context)
Example
In the following code shows how to use SecurityManager.checkPermission(Permission perm, Object context) method.
/* w ww.ja v a2 s . co m*/
import java.io.FilePermission;
import java.security.AccessControlContext;
import java.security.AccessController;
public class Main extends SecurityManager {
public static void main(String[] args) {
AccessControlContext con = AccessController.getContext();
System.setProperty("java.security.policy", "file:/C:/java.policy");
Main sm = new Main();
System.setSecurityManager(sm);
sm.checkPermission(new FilePermission("test.txt", "read,write"), con);
System.out.println("Allowed!");
}
}