diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2010-12-25 01:23:49 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2010-12-25 01:23:49 +0000 |
commit | e2d3135056d61448313e413b201697b3808f06ba (patch) | |
tree | 759d2be3176d906a060eff623b3ddc3aacfca0c7 /java | |
parent | 5d5a64d47af13bdbfb5f3ed69073f08a8020e492 (diff) | |
download | classpath-e2d3135056d61448313e413b201697b3808f06ba.tar.gz |
Provide implies shortcut for ProtectionDomain instances with AllPermission.
2010-12-24 Andrew John Hughes <ahughes@redhat.com>
* java/security/ProtectionDomain.java,
(hasAllPermissions): Add new field.
(ProtectionDomain(CodeSource,PermissionCollection,
ClassLoader,Principal,boolean)): Check if permission
collection includes AllPermission and, if so, set
hasAllPermissions.
(implies(Permission)): Immediately return true if
hasAllPermissions is set.
Diffstat (limited to 'java')
-rw-r--r-- | java/security/ProtectionDomain.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/java/security/ProtectionDomain.java b/java/security/ProtectionDomain.java index d5d657d61..9af87c64a 100644 --- a/java/security/ProtectionDomain.java +++ b/java/security/ProtectionDomain.java @@ -41,6 +41,8 @@ import gnu.classpath.SystemProperties; import gnu.java.lang.CPStringBuilder; +import java.util.Enumeration; + /** * This class represents a group of classes, along with their granted * permissions. The classes are identified by a {@link CodeSource}. Thus, any @@ -71,6 +73,9 @@ public class ProtectionDomain /** Post 1.4 the policy may be refreshed! use false for pre 1.4. */ private boolean staticBinding; + /** True if this protection domain has all permissions */ + private boolean hasAllPermissions; + /** * Initializes a new instance of <code>ProtectionDomain</code> representing * the specified {@link CodeSource} and set of permissions. No permissions @@ -128,6 +133,13 @@ public class ProtectionDomain { perms = permissions; perms.setReadOnly(); + /* Check if this protection domain has all permissions */ + Enumeration<Permission> e = permissions.elements(); + while (e.hasMoreElements()) + { + if (e.nextElement() instanceof AllPermission) + hasAllPermissions = true; + } } this.classloader = classloader; @@ -190,6 +202,8 @@ public class ProtectionDomain */ public boolean implies(Permission permission) { + if (hasAllPermissions) + return true; if (staticBinding) return (perms == null ? false : perms.implies(permission)); // Else dynamically bound. Do we have it? |