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().
Here's the list of permissions for a class under the default policy file:
Here's the list of permissions for the java.lang.String class which
is loaded with the system class loader:
// 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();
}
(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)
(java.security.AllPermission <all permissions> <all actions>)
Post a comment