diff options
Diffstat (limited to 'libjava/classpath/java/security')
4 files changed, 47 insertions, 15 deletions
diff --git a/libjava/classpath/java/security/AccessControlContext.java b/libjava/classpath/java/security/AccessControlContext.java index 9a6ad208144..3b51e94125b 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}. * + * <p>Code calling this constructor must have a {@link + * SecurityPermission} of <i>createAccessControlContext</i>.</p> + * + * @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 bc9c2deefbb..93e34b87c22 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 <code>PrivilegedExceptionAction</code> whose * <code>run()</code> should be be called. * @return the result of the <code>action.run()</code> method. - * @exception PrivilegedActionException wrapped around any exception that - * is thrown in the <code>run()</code> method. + * @exception PrivilegedActionException wrapped around any checked exception + * that is thrown in the <code>run()</code> 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 <code>AccessControlContext</code> whose protection * domains should be added to the protection domain of the calling class. * @return the result of the <code>action.run()</code> method. - * @exception PrivilegedActionException wrapped around any exception that - * is thrown in the <code>run()</code> method. + * @exception PrivilegedActionException wrapped around any checked exception + * that is thrown in the <code>run()</code> 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 26b01a50a6b..7ef59cfe2de 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 54b97923efd..fd51d0535b3 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, |