From c1cca55d6fe8df3d80afce7f88843c4046c35903 Mon Sep 17 00:00:00 2001 From: bryce Date: Fri, 24 May 2002 11:57:40 +0000 Subject: Merge JDK 1.4 java.security changes from classpath. * java/security/AccessControlException.java: Merge from Classpath. * java/security/AccessController.java: Likewise. * java/security/AllPermission.java: Likewise. * java/security/BasicPermission.java: Likewise. * java/security/Certificate.java: Likewise. * java/security/CodeSource.java: Likewise. * java/security/DigestException.java: Likewise. * java/security/DigestOutputStream.java: Likewise. * java/security/DomainCombiner.java: Likewise. * java/security/GeneralSecurityException.java: Likewise. * java/security/Guard.java: Likewise. * java/security/GuardedObject.java: Likewise. * java/security/InvalidAlgorithmParameterException.java: Likewise. * java/security/InvalidKeyException.java: Likewise. * java/security/InvalidParameterException.java: Likewise. * java/security/Key.java: Likewise. * java/security/KeyException.java: Likewise. * java/security/KeyManagementException.java: Likewise. * java/security/KeyStoreException.java: Likewise. * java/security/MessageDigest.java: Likewise. * java/security/NoSuchAlgorithmException.java: Likewise. * java/security/NoSuchProviderException.java: Likewise. * java/security/Permission.java: Likewise. * java/security/PermissionCollection.java: Likewise. * java/security/Permissions.java: Likewise. * java/security/Policy.java: Likewise. * java/security/Principal.java: Likewise. * java/security/PrivateKey.java: Likewise. * java/security/PrivilegedAction.java: Likewise. * java/security/PrivilegedActionException.java: Likewise. * java/security/PrivilegedExceptionAction.java: Likewise. * java/security/ProtectionDomain.java: Likewise. * java/security/ProviderException.java: Likewise. * java/security/PublicKey.java: Likewise. * java/security/SecureClassLoader.java: Likewise. * java/security/SecurityPermission.java: Likewise. * java/security/SignatureException.java: Likewise. * java/security/UnrecoverableKeyException.java: Likewise. * java/security/UnresolvedPermission.java: Likewise. * java/security/acl/AclNotFoundException.java: Likewise. * java/security/acl/LastOwnerException.java: Likewise. * java/security/acl/NotOwnerException.java: Likewise. * java/security/cert/CRLException.java: Likewise. * java/security/cert/CertificateEncodingException.java: Likewise. * java/security/cert/CertificateException.java: Likewise. * java/security/cert/CertificateExpiredException.java: Likewise. * java/security/cert/CertificateFactory.java: Likewise. * java/security/cert/CertificateNotYetValidException.java: Likewise. * java/security/cert/CertificateParsingException.java: Likewise. * java/security/spec/InvalidKeySpecException.java: Likewise. * java/security/spec/InvalidParameterSpecException.java: Likewise. * java/security/cert/CertPath.java: New file. * java/security/cert/CertPathBuilderException.java: New file. * java/security/cert/CertPathValidatorException.java: New file. * java/security/cert/CertStoreException.java: New file. * Makefile.am: Add new CertPath classes. * Makefile.in: Rebuilt. * gnu/java/util/EmptyEnumeration: New file from classpath. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@53837 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/security/Permission.java | 126 ++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 52 deletions(-) (limited to 'libjava/java/security/Permission.java') diff --git a/libjava/java/security/Permission.java b/libjava/java/security/Permission.java index 8235e21a984..58702da2c0c 100644 --- a/libjava/java/security/Permission.java +++ b/libjava/java/security/Permission.java @@ -1,5 +1,5 @@ /* Permission.java -- The superclass for all permission objects - Copyright (C) 1998, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,7 @@ import java.io.Serializable; /** * This class is the abstract superclass of all classes that implement - * the concept of a permission. A permission consists of a permission name + * the concept of a permission. A permission consists of a permission name * and optionally a list of actions that relate to the permission. The * actual meaning of the name of the permission is defined only in the * context of a subclass. It may name a resource to which access permissions @@ -51,115 +51,137 @@ import java.io.Serializable; * actions associated with them. That is, you either have the permission * or you don't. * - * The most important method in this class is implies. This + *

The most important method in this class is implies. This * checks whether if one has this permission, then the specified * permission is also implied. As a conceptual example, consider the * permissions "Read All Files" and "Read File foo". The permission * "Read All Files" implies that the caller has permission to read the * file foo. * - * Permission's are not dynamic objects. Once created, a - * Permission's name and action list cannot be changed. + *

Permission's must be immutable - do not change their + * state after creation. * - * @version 0.0 - * - * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Aaron M. Renn + * @see Permissions + * @see PermissionCollection + * @since 1.1 + * @status updated to 1.4 */ public abstract class Permission implements Guard, Serializable { /** - * This is the name assigned to this permission object. + * Compatible with JDK 1.1+. */ - private String name; // Taken from the serializable form information + private static final long serialVersionUID = -5636570222231596674L; /** - * This method initializes a new instance of Permission to - * have the specified name. + * This is the name assigned to this permission object. + * + * @serial the name of the permission */ - public Permission(String name) - { - this.name = name; - } + private String name; /** - * This method returns the name of this Permission + * Create an instance with the specified name. * - * @return The name of this Permission + * @param name the permission name */ - public final String getName() + public Permission(String name) { - return (name); + this.name = name; } - /** - * This method returns the list of actions for this Permission - * as a String. - * - * @return The action list for this Permission. - */ - public abstract String getActions(); - /** * This method implements the Guard interface for this class. - * It calls the checkPermission method in + * It calls the checkPermission method in * SecurityManager with this Permission as its * argument. This method returns silently if the security check succeeds * or throws an exception if it fails. * - * @param obj The Object being guarded - ignored by this class - * - * @exception SecurityException If the security check fails + * @param obj the Object being guarded - ignored by this class + * @throws SecurityException if the security check fails + * @see GuardedObject + * @see SecurityManager#checkPermission(Permission) */ - public void checkGuard(Object obj) throws SecurityException + public void checkGuard(Object obj) { SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission(this); } - /** - * Check to see if this object equals OBJ. - */ - public abstract boolean equals (Object obj); - /** * This method tests whether this Permission implies that the * specified Permission is also granted. * - * @param perm The Permission to test against - * - * @return true if the specified Permission is implied by this one, false otherwise. + * @param perm the Permission to test against + * @return true if perm is implied by this */ public abstract boolean implies(Permission perm); /** - * This method returns a hash code for this Permission. + * Check to see if this object equals obj. Use implies, rather + * than equals, when making access control decisions. * - * @return A hash value. + * @param obj the object to compare to + */ + public abstract boolean equals(Object obj); + + /** + * This method returns a hash code for this Permission. It + * must satisfy the contract of Object.hashCode: it must be + * the same for all objects that equals considers to be the same. + * + * @return a hash value */ public abstract int hashCode(); /** - * This method returns a String representation of this - * Permission object. + * Get the name of this Permission. * - * @return This object as a String. + * @return the name */ - public String toString() + public final String getName() { - return ("'\"" + getClass().getName() + "\" \"" + getName() + - "\"" + " \"" + getActions() + "\")'"); + return name; } + /** + * This method returns the list of actions for this Permission + * as a String. The string should be in canonical order, for + * example, both new FilePermission(f, "write,read") and + * new FilePermission(f, "read,write") have the action list + * "read,write". + * + * @return the action list for this Permission + */ + public abstract String getActions(); + /** * This method returns an empty PermissionCollection object * that can store permissions of this type, or null if no - * such collection is defined. + * such collection is defined. Subclasses must override this to provide + * an appropriate collection when one is needed to accurately calculate + * implies. * - * @return A new PermissionCollection + * @return a new PermissionCollection */ public PermissionCollection newPermissionCollection() { return null; } -} + + /** + * This method returns a String representation of this + * Permission object. This is in the format: + * '(' + getClass().getName() + ' ' + getName() + ' ' + getActions + * + ')'. + * + * @return this object as a String + */ + public String toString() + { + return '(' + getClass().getName() + ' ' + getName() + ' ' + + getActions() + ')'; + } +} // class Permission -- cgit v1.2.3