From 7ffd45d8a5c4a801fc2ec86d1dcd670f53613285 Mon Sep 17 00:00:00 2001 From: "Raif S. Naffah" Date: Sat, 8 Mar 2003 14:07:46 +0000 Subject: formatting + documentation. --- java/security/ProtectionDomain.java | 105 ++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 46 deletions(-) (limited to 'java/security/ProtectionDomain.java') diff --git a/java/security/ProtectionDomain.java b/java/security/ProtectionDomain.java index e8ead4665..44b780d4a 100644 --- a/java/security/ProtectionDomain.java +++ b/java/security/ProtectionDomain.java @@ -1,5 +1,5 @@ /* ProtectionDomain.java -- A security domain - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2003, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,55 +38,53 @@ exception statement from your version. */ package java.security; /** - * This class represents a group of classes, along with the permissions - * they are granted. The classes are identified by a CodeSource. - * Thus, any class loaded from the specified CodeSource is - * treated as part of this domain. The set of permissions is represented - * by a PermissionCollection. - *

- * Every class in the system will belong to one and only one - * ProtectionDomain. + *

This ProtectionDomain class encapsulates the characteristics + * of a domain, which encloses a set of classes whose instances are granted a + * set of permissions when being executed on behalf of a given set of + * Principals. * - * @version 0.0 + *

A static set of permissions can be bound to a ProtectionDomain + * when it is constructed; such permissions are granted to the domain regardless + * of the {@link Policy} in force. However, to support dynamic security + * policies, a ProtectionDomain can also be constructed such that + * it is dynamically mapped to a set of permissions by the current {@link + * Policy} whenever a permission is checked.

* * @author Aaron M. Renn (arenn@urbanophile.com) + * @version 0.0 */ public class ProtectionDomain { - /** - * This is the CodeSource for this protection domain - */ + /** This is the CodeSource for this protection domain. */ private CodeSource code_source; - /** - * This is the set of permissions granted to this domain - */ + /** This is the set of permissions granted to this domain. */ private PermissionCollection perms; /** - * This method initializes a new instance of ProtectionDomain - * representing the specified CodeSource and permission set. - * No permissions may be added to the PermissionCollection - * and this contructor will call the setReadOnly method on - * the specified permission set. + * Creates a new ProtectionDomain with the given {@link + * CodeSource} and {@link Permissions}. If the permissions object is not + * null, then setReadOnly() will be called on the + * passed in {@link Permissions} object. The only permissions granted to this + * domain are the ones specified; the current {@link Policy} will not be + * consulted. * - * @param code_source The CodeSource for this domain - * @param perms The permission set for this domain - * - * @see java.security.PermissionCollection#setReadOnly() + * @param codesource the codesource associated with this domain. + * @param permissions the permissions granted to this domain */ - public ProtectionDomain(CodeSource code_source, PermissionCollection perms) + public ProtectionDomain(CodeSource codesource, PermissionCollection permissions) { - this.code_source = code_source; - this.perms = perms; - if (perms != null) - perms.setReadOnly(); + this.code_source = codesource; + this.perms = permissions; + if (permissions != null) + permissions.setReadOnly(); } /** - * This method returns the CodeSource for this domain. - * - * @return This domain's CodeSource. + * Returns the {@link CodeSource} of this domain. + * + * @return the {@link CodeSource} of this domain which may be null. + * @since 1.2 */ public final CodeSource getCodeSource() { @@ -94,9 +92,12 @@ public class ProtectionDomain } /** - * This method returns the set of permissions granted to this domain. + * Returns the static permissions granted to this domain. * - * @return The permission set for this domain + * @return the static set of permissions for this domain which may be + * null. + * @see Policy#refresh() + * @see Policy#getPermissions(ProtectionDomain) */ public final PermissionCollection getPermissions() { @@ -104,28 +105,40 @@ public class ProtectionDomain } /** - * This method tests whether or not the specified Permission is - * implied by the set of permissions granted to this domain. + *

Check and see if this ProtectionDomain implies the + * permissions expressed in the Permission object.

+ * + *

The set of permissions evaluated is a function of whether the + * ProtectionDomain was constructed with a static set of + * permissions or it was bound to a dynamically mapped set of permissions.

* - * @param perm The Permission to test. + *

If the ProtectionDomain was constructed to a statically + * bound {@link PermissionCollection} then the permission will only be checked + * against the {@link PermissionCollection} supplied at construction.

* - * @return true if the specified Permission is implied for this domain, false otherwise. + *

However, if the ProtectionDomain was constructed with the + * constructor variant which supports dynamically binding permissions, then + * the permission will be checked against the combination of the + * {@link PermissionCollection} supplied at construction and the current + * {@link Policy} binding. + * + * @param permission the {@link Permission} object to check. + * @return true if permission is implicit to this + * ProtectionDomain. */ - public boolean implies(Permission perm) + public boolean implies(Permission permission) { PermissionCollection pc = getPermissions(); if (pc == null) return (false); - return (pc.implies(perm)); + return pc.implies(permission); } /** - * This method returns a String representation of this - * object. It will print the CodeSource and - * permission set associated with this domain. + * Convert a ProtectionDomain to a String. * - * @return A String representation of this object. + * @return a string representation of the object. */ public String toString() { @@ -138,7 +151,7 @@ public class ProtectionDomain sb.append(code_source + linesep); sb.append(perms); sb.append(linesep + ")" + linesep); - + return sb.toString(); } } -- cgit v1.2.1