From 8f523f3a1047919d3563daf1ef47ba87336ebe89 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 15 Nov 2005 23:20:01 +0000 Subject: Imported GNU Classpath 0.19 + gcj-import-20051115. * sources.am: Regenerated. * Makefile.in: Likewise. * scripts/makemake.tcl: Use glob -nocomplain. From-SVN: r107049 --- .../java/security/AccessControlContext.java | 34 ++++++++++++++++++---- .../classpath/java/security/AccessController.java | 16 +++++++--- libjava/classpath/java/security/Identity.java | 8 ++--- libjava/classpath/java/security/Security.java | 4 +-- 4 files changed, 47 insertions(+), 15 deletions(-) (limited to 'libjava/classpath/java/security') diff --git a/libjava/classpath/java/security/AccessControlContext.java b/libjava/classpath/java/security/AccessControlContext.java index 9a6ad20..3b51e94 100644 --- a/libjava/classpath/java/security/AccessControlContext.java +++ b/libjava/classpath/java/security/AccessControlContext.java @@ -77,14 +77,23 @@ public final class AccessControlContext /** * Construct a new AccessControlContext with the specified - * ProtectionDomains and DomainCombiner + * {@link ProtectionDomain}s and {@link DomainCombiner}. * + *

Code calling this constructor must have a {@link + * SecurityPermission} of createAccessControlContext.

+ * + * @throws SecurityException If the caller does not have permission + * to create an access control context. * @since 1.3 */ public AccessControlContext(AccessControlContext acc, DomainCombiner combiner) { - // XXX check permission to call this. + SecurityManager sm = System.getSecurityManager (); + if (sm != null) + { + sm.checkPermission (new SecurityPermission ("createAccessControlContext")); + } AccessControlContext acc2 = AccessController.getContext(); protectionDomains = combiner.combine (acc2.protectionDomains, acc.protectionDomains); @@ -119,10 +128,20 @@ public final class AccessControlContext public void checkPermission(Permission perm) throws AccessControlException { if (protectionDomains.length == 0) - throw new AccessControlException ("permission not granted"); + throw new AccessControlException ("permission " + + perm + + " not granted: no protection domains"); + for (int i = 0; i < protectionDomains.length; i++) - if (!protectionDomains[i].implies(perm)) - throw new AccessControlException ("permission not granted"); + { + final ProtectionDomain domain = protectionDomains[i]; + if (!domain.implies(perm)) + throw new AccessControlException ("permission " + + perm + + " not granted: " + + domain + + " does not imply it."); + } } /** @@ -173,4 +192,9 @@ public final class AccessControlContext return h; } + + ProtectionDomain[] getProtectionDomains () + { + return protectionDomains; + } } diff --git a/libjava/classpath/java/security/AccessController.java b/libjava/classpath/java/security/AccessController.java index bc9c2de..93e34b8 100644 --- a/libjava/classpath/java/security/AccessController.java +++ b/libjava/classpath/java/security/AccessController.java @@ -142,8 +142,8 @@ public final class AccessController * @param action the PrivilegedExceptionAction whose * run() should be be called. * @return the result of the action.run() method. - * @exception PrivilegedActionException wrapped around any exception that - * is thrown in the run() method. + * @exception PrivilegedActionException wrapped around any checked exception + * that is thrown in the run() method. */ public static Object doPrivileged(PrivilegedExceptionAction action) throws PrivilegedActionException @@ -153,6 +153,10 @@ public final class AccessController { return action.run(); } + catch (RuntimeException e) + { + throw e; + } catch (Exception e) { throw new PrivilegedActionException(e); @@ -178,8 +182,8 @@ public final class AccessController * @param context the AccessControlContext whose protection * domains should be added to the protection domain of the calling class. * @return the result of the action.run() method. - * @exception PrivilegedActionException wrapped around any exception that - * is thrown in the run() method. + * @exception PrivilegedActionException wrapped around any checked exception + * that is thrown in the run() method. */ public static Object doPrivileged(PrivilegedExceptionAction action, AccessControlContext context) @@ -190,6 +194,10 @@ public final class AccessController { return action.run(); } + catch (RuntimeException e) + { + throw e; + } catch (Exception e) { throw new PrivilegedActionException(e); diff --git a/libjava/classpath/java/security/Identity.java b/libjava/classpath/java/security/Identity.java index 26b01a5..7ef59cf 100644 --- a/libjava/classpath/java/security/Identity.java +++ b/libjava/classpath/java/security/Identity.java @@ -297,8 +297,8 @@ public abstract class Identity implements Principal, Serializable if (identity == this) return true; - if ((((Identity) identity).getName() == this.name) && - (((Identity) identity).getScope() == this.scope)) + if ((((Identity) identity).getName().equals(this.name)) && + (((Identity) identity).getScope().equals(this.scope))) return true; return identityEquals((Identity) identity); @@ -319,8 +319,8 @@ public abstract class Identity implements Principal, Serializable */ protected boolean identityEquals(Identity identity) { - return ((identity.getName() == this.name) && - (identity.getPublicKey() == this.publicKey)); + return ((identity.getName().equals(this.name)) && + (identity.getPublicKey().equals(this.publicKey))); } /** diff --git a/libjava/classpath/java/security/Security.java b/libjava/classpath/java/security/Security.java index 54b9792..fd51d05 100644 --- a/libjava/classpath/java/security/Security.java +++ b/libjava/classpath/java/security/Security.java @@ -1,5 +1,5 @@ /* Security.java --- Java base security class implementation - Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -651,7 +651,7 @@ public final class Security if (result.isEmpty()) return null; - return (Provider[]) result.toArray(new Provider[0]); + return (Provider[]) result.toArray(new Provider[result.size()]); } private static void selectProviders(String svc, String algo, String attr, -- cgit v1.1