Index: java/security/AccessControlContext.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/security/AccessControlContext.java,v retrieving revision 1.5 diff -u -b -B -r1.5 AccessControlContext.java --- java/security/AccessControlContext.java 22 Jan 2002 22:27:00 -0000 1.5 +++ java/security/AccessControlContext.java 3 Jun 2004 06:25:26 -0000 @@ -1,5 +1,5 @@ /* AccessControlContext.java --- Access Control Context Class - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +37,8 @@ package java.security; +import java.util.HashSet; + /** AccessControlContext makes system resource access decsion based on permission rights. @@ -53,8 +55,8 @@ */ public final class AccessControlContext { - private ProtectionDomain protectionDomain[]; - private DomainCombiner combiner; + private final ProtectionDomain[] protectionDomains; + private final DomainCombiner combiner; /** Construct a new AccessControlContext with the specified @@ -65,29 +67,12 @@ */ public AccessControlContext(ProtectionDomain[]context) { - int i, j, k, count = context.length, count2 = 0; - for (i = 0, j = 0; i < count; i++) - { - for (k = 0; k < i; k++) - if (context[k] == protectionDomain[i]) - break; - if (k != i) //it means previous loop did not complete - continue; - - count2++; - } - - protectionDomain = new ProtectionDomain[count2]; - for (i = 0, j = 0; i < count2; i++) - { - for (k = 0; k < i; k++) - if (context[k] == protectionDomain[i]) - break; - if (k != i) //it means previous loop did not complete - continue; - - protectionDomain[j++] = context[i]; - } + HashSet domains = new HashSet (context.length); + for (int i = 0; i < context.length; i++) + domains.add (context[i]); + protectionDomains = (ProtectionDomain[]) + domains.toArray (new ProtectionDomain[domains.size()]); + combiner = null; } /** @@ -101,7 +86,17 @@ public AccessControlContext(AccessControlContext acc, DomainCombiner combiner) { - this(acc.protectionDomain); + // XXX check permission to call this. + AccessControlContext acc2 = AccessController.getContext(); + protectionDomains = combiner.combine (acc2.protectionDomains, + acc.protectionDomains); + this.combiner = combiner; + } + + AccessControlContext (ProtectionDomain[] domains, AccessControlContext acc, + DomainCombiner combiner) + { + protectionDomains = combiner.combine (domains, acc.protectionDomains); this.combiner = combiner; } @@ -125,11 +120,9 @@ */ public void checkPermission(Permission perm) throws AccessControlException { - for (int i = 0; i < protectionDomain.length; i++) - if (protectionDomain[i].implies(perm) == true) - return; - - throw new AccessControlException("Permission not granted"); + for (int i = 0; i < protectionDomains.length; i++) + if (!protectionDomains[i].implies(perm)) + throw new AccessControlException ("permission not granted"); } /** @@ -151,9 +144,17 @@ if (acc.protectionDomain.length != protectionDomain.length) return false; - for (int i = 0; i < protectionDomain.length; i++) - if (acc.protectionDomain[i] != protectionDomain[i]) + int i, j; + for (i = 0; i < protectionDomains.length; i++) + { + for (j = 0; j < acc.protectionDomains.length; j++) + { + if (acc.protectionDomains[j].equals (protectionDomains[i])) + break; + } + if (j == acc.protectionDomains.length) return false; + } return true; } return false; Index: java/security/ProtectionDomain.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/security/ProtectionDomain.java,v retrieving revision 1.10 diff -u -b -B -r1.10 ProtectionDomain.java --- java/security/ProtectionDomain.java 10 Mar 2003 17:17:39 -0000 1.10 +++ java/security/ProtectionDomain.java 3 Jun 2004 06:25:26 -0000 @@ -83,7 +83,7 @@ */ public ProtectionDomain(CodeSource codesource, PermissionCollection permissions) { - this(codesource, permissions, null, null, false); + this(codesource, permissions, null, null, true); } /** Index: java/security/SecureClassLoader.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/security/SecureClassLoader.java,v retrieving revision 1.9 diff -u -b -B -r1.9 SecureClassLoader.java --- java/security/SecureClassLoader.java 30 Apr 2003 06:47:24 -0000 1.9 +++ java/security/SecureClassLoader.java 3 Jun 2004 06:25:26 -0000 @@ -84,7 +84,7 @@ if (cs != null) { ProtectionDomain protectionDomain - = new ProtectionDomain(cs, getPermissions(cs)); + = new ProtectionDomain(cs, getPermissions(cs), this, null); return super.defineClass(name, b, off, len, protectionDomain); } else @@ -103,7 +103,7 @@ */ protected PermissionCollection getPermissions(CodeSource cs) { - Policy policy = Policy.getPolicy(); + Policy policy = Policy.getCurrentPolicy(); return policy.getPermissions(cs); } } Index: java/util/PropertyPermissionCollection.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/util/PropertyPermissionCollection.java,v retrieving revision 1.3 diff -u -b -B -r1.3 PropertyPermissionCollection.java --- java/util/PropertyPermissionCollection.java 30 Apr 2002 22:08:47 -0000 1.3 +++ java/util/PropertyPermissionCollection.java 3 Jun 2004 06:25:26 -0000 @@ -145,7 +145,7 @@ return true; } - prefixLength = name.lastIndexOf('.', prefixLength); + prefixLength = name.lastIndexOf('.', prefixLength - 1); if (prefixLength < 0) return false; name = name.substring(0, prefixLength + 1) + '*';