Use SecurityManager to check AWT permission and file permission : SecurityManager « Security « Java Tutorial






import java.awt.AWTPermission;
import java.io.FilePermission;

public class MainClass {
  public static void main(String args[]) throws Exception {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      FilePermission fp = new FilePermission("c:\\autoexec.bat", "read");
      sm.checkPermission(fp);
    }

    if (sm != null) {
      AWTPermission ap = new AWTPermission("accessClipboard");
      sm.checkPermission(ap);
    }
    System.out.println("Has AWTPermission to access AWT Clipboard");

  }
}








36.41.SecurityManager
36.41.1.extends SecurityManager
36.41.2.Use SecurityManager to check AWT permission and file permission
36.41.3.Listing All Permissions Granted to Classes Loaded from a URL or Directory
36.41.4.Define your own security manager
36.41.5.Enabling the Security Manager
36.41.6.To specify an additional policy file, set the java.security.policy system property at the command line:
36.41.7.To ignore the policies in the java.security file, and use the specified policy, use '==' instead of '='