Creating Custom Permissions

You have seen how to create a policy file that uses predefined permissions. It may be the case, however, that your application needs to define its own permissions. This is easy to do in Java.

User-Defined Permission Code Example

You can check to see if a specific permission has been granted to your code by creating a Permission object of that type, such as a FilePermission object. Then you can check for that permission using the checkPermission() method of the AccessController class. This method does not return a value. If you have the permission, the method simply completes. If you do not have the permission, or if the values specified in the permission object that is the parameter to the checkPermission method are ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.