Listing All Permissions Granted to a Loaded Class

This example retrieves all the permissions granted to a particular class. These permissions are effective only if a security manager is installed (see Enabling the Security Manager). However, with a security manager installed, a class will require permission to execute Class.getProtectionDomain() and Policy.getPermissions().
// Get the protection domain for the class ProtectionDomain domain = this.getClass().getProtectionDomain(); // With the protection domain, get all the permissions from the Policy object PermissionCollection pcoll = Policy.getPolicy().getPermissions(domain); // View each permission in the permission collection Enumeration enum = pcoll.elements(); for (; enum.hasMoreElements(); ) { Permission p = (Permission)enum.nextElement(); }
Here's the list of permissions for a class under the default policy file:
(java.lang.RuntimePermission exitVM) (java.lang.RuntimePermission stopThread) (java.util.PropertyPermission java.specification.vendor read) (java.util.PropertyPermission java.vm.specification.vendor read) (java.util.PropertyPermission path.separator read) (java.util.PropertyPermission java.vm.name read) (java.util.PropertyPermission java.class.version read) (java.util.PropertyPermission os.name read) (java.util.PropertyPermission java.vendor.url read) (java.util.PropertyPermission java.vendor read) (java.util.PropertyPermission java.vm.vendor read) (java.util.PropertyPermission file.separator read) (java.util.PropertyPermission os.version read) (java.util.PropertyPermission java.vm.version read) (java.util.PropertyPermission java.version read) (java.util.PropertyPermission line.separator read) (java.util.PropertyPermission java.vm.specification.version read) (java.util.PropertyPermission java.specification.name read) (java.util.PropertyPermission java.vm.specification.name read) (java.util.PropertyPermission java.specification.version read) (java.util.PropertyPermission os.arch read) (java.net.SocketPermission localhost:1024- listen,resolve) (java.io.FilePermission \C:\users\almanac\- read)
Here's the list of permissions for the java.lang.String class which is loaded with the system class loader:
(java.security.AllPermission <all permissions> <all actions>)

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.