Example usage for java.lang SecurityManager checkPermission

List of usage examples for java.lang SecurityManager checkPermission

Introduction

In this page you can find the example usage for java.lang SecurityManager checkPermission.

Prototype

public void checkPermission(Permission perm, Object context) 

Source Link

Document

Throws a SecurityException if the specified security context is denied access to the resource specified by the given permission.

Usage

From source file:Main.java

public static void main(String[] args) {
    AccessControlContext con = AccessController.getContext();

    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPermission(new FilePermission("test.txt", "read,write"), con);

    System.out.println("Allowed!");
}