001: /*
002: * @(#)Acl.java 1.25 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.security.acl;
029:
030: import java.util.Enumeration;
031: import java.security.Principal;
032:
033: /**
034: * Interface representing an Access Control List (ACL). An Access
035: * Control List is a data structure used to guard access to
036: * resources.<p>
037: *
038: * An ACL can be thought of as a data structure with multiple ACL
039: * entries. Each ACL entry, of interface type AclEntry, contains a
040: * set of permissions associated with a particular principal. (A
041: * principal represents an entity such as an individual user or a
042: * group). Additionally, each ACL entry is specified as being either
043: * positive or negative. If positive, the permissions are to be
044: * granted to the associated principal. If negative, the permissions
045: * are to be denied.<p>
046: *
047: * The ACL Entries in each ACL observe the following rules:<p>
048: *
049: * <ul> <li>Each principal can have at most one positive ACL entry and
050: * one negative entry; that is, multiple positive or negative ACL
051: * entries are not allowed for any principal. Each entry specifies
052: * the set of permissions that are to be granted (if positive) or
053: * denied (if negative). <p>
054: *
055: * <li>If there is no entry for a particular principal, then the
056: * principal is considered to have a null (empty) permission set.<p>
057: *
058: * <li>If there is a positive entry that grants a principal a
059: * particular permission, and a negative entry that denies the
060: * principal the same permission, the result is as though the
061: * permission was never granted or denied. <p>
062: *
063: * <li>Individual permissions always override permissions of the
064: * group(s) to which the individual belongs. That is, individual
065: * negative permissions (specific denial of permissions) override the
066: * groups' positive permissions. And individual positive permissions
067: * override the groups' negative permissions.<p>
068: *
069: * </ul>
070: *
071: * The <code> java.security.acl </code> package provides the
072: * interfaces to the ACL and related data structures (ACL entries,
073: * groups, permissions, etc.), and the <code> sun.security.acl </code>
074: * classes provide a default implementation of the interfaces. For
075: * example, <code> java.security.acl.Acl </code> provides the
076: * interface to an ACL and the <code> sun.security.acl.AclImpl </code>
077: * class provides the default implementation of the interface.<p>
078: *
079: * The <code> java.security.acl.Acl </code> interface extends the
080: * <code> java.security.acl.Owner </code> interface. The Owner
081: * interface is used to maintain a list of owners for each ACL. Only
082: * owners are allowed to modify an ACL. For example, only an owner can
083: * call the ACL's <code>addEntry</code> method to add a new ACL entry
084: * to the ACL.
085: *
086: * @see java.security.acl.AclEntry
087: * @see java.security.acl.Owner
088: * @see java.security.acl.Acl#getPermissions
089: *
090: * @version 1.18, 00/02/02
091: * @author Satish Dharmaraj
092: */
093:
094: public interface Acl extends Owner {
095:
096: /**
097: * Sets the name of this ACL.
098: *
099: * @param caller the principal invoking this method. It must be an
100: * owner of this ACL.
101: *
102: * @param name the name to be given to this ACL.
103: *
104: * @exception NotOwnerException if the caller principal
105: * is not an owner of this ACL.
106: *
107: * @see #getName
108: */
109: public void setName(Principal caller, String name)
110: throws NotOwnerException;
111:
112: /**
113: * Returns the name of this ACL.
114: *
115: * @return the name of this ACL.
116: *
117: * @see #setName
118: */
119: public String getName();
120:
121: /**
122: * Adds an ACL entry to this ACL. An entry associates a principal
123: * (e.g., an individual or a group) with a set of
124: * permissions. Each principal can have at most one positive ACL
125: * entry (specifying permissions to be granted to the principal)
126: * and one negative ACL entry (specifying permissions to be
127: * denied). If there is already an ACL entry of the same type
128: * (negative or positive) already in the ACL, false is returned.
129: *
130: * @param caller the principal invoking this method. It must be an
131: * owner of this ACL.
132: *
133: * @param entry the ACL entry to be added to this ACL.
134: *
135: * @return true on success, false if an entry of the same type
136: * (positive or negative) for the same principal is already
137: * present in this ACL.
138: *
139: * @exception NotOwnerException if the caller principal
140: * is not an owner of this ACL.
141: */
142: public boolean addEntry(Principal caller, AclEntry entry)
143: throws NotOwnerException;
144:
145: /**
146: * Removes an ACL entry from this ACL.
147: *
148: * @param caller the principal invoking this method. It must be an
149: * owner of this ACL.
150: *
151: * @param entry the ACL entry to be removed from this ACL.
152: *
153: * @return true on success, false if the entry is not part of this ACL.
154: *
155: * @exception NotOwnerException if the caller principal is not
156: * an owner of this Acl.
157: */
158: public boolean removeEntry(Principal caller, AclEntry entry)
159: throws NotOwnerException;
160:
161: /**
162: * Returns an enumeration for the set of allowed permissions for the
163: * specified principal (representing an entity such as an individual or
164: * a group). This set of allowed permissions is calculated as
165: * follows:<p>
166: *
167: * <ul>
168: *
169: * <li>If there is no entry in this Access Control List for the
170: * specified principal, an empty permission set is returned.<p>
171: *
172: * <li>Otherwise, the principal's group permission sets are determined.
173: * (A principal can belong to one or more groups, where a group is a
174: * group of principals, represented by the Group interface.)
175: * The group positive permission set is the union of all
176: * the positive permissions of each group that the principal belongs to.
177: * The group negative permission set is the union of all
178: * the negative permissions of each group that the principal belongs to.
179: * If there is a specific permission that occurs in both
180: * the positive permission set and the negative permission set,
181: * it is removed from both.<p>
182: *
183: * The individual positive and negative permission sets are also
184: * determined. The positive permission set contains the permissions
185: * specified in the positive ACL entry (if any) for the principal.
186: * Similarly, the negative permission set contains the permissions
187: * specified in the negative ACL entry (if any) for the principal.
188: * The individual positive (or negative) permission set is considered
189: * to be null if there is not a positive (negative) ACL entry for the
190: * principal in this ACL.<p>
191: *
192: * The set of permissions granted to the principal is then calculated
193: * using the simple rule that individual permissions always override
194: * the group permissions. That is, the principal's individual negative
195: * permission set (specific denial of permissions) overrides the group
196: * positive permission set, and the principal's individual positive
197: * permission set overrides the group negative permission set.
198: *
199: * </ul>
200: *
201: * @param user the principal whose permission set is to be returned.
202: *
203: * @return the permission set specifying the permissions the principal
204: * is allowed.
205: */
206: public Enumeration getPermissions(Principal user);
207:
208: /**
209: * Returns an enumeration of the entries in this ACL. Each element in
210: * the enumeration is of type AclEntry.
211: *
212: * @return an enumeration of the entries in this ACL.
213: */
214: public Enumeration entries();
215:
216: /**
217: * Checks whether or not the specified principal has the specified
218: * permission. If it does, true is returned, otherwise false is returned.
219: *
220: * More specifically, this method checks whether the passed permission
221: * is a member of the allowed permission set of the specified principal.
222: * The allowed permission set is determined by the same algorithm as is
223: * used by the <code>getPermissions</code> method.
224: *
225: * @param principal the principal, assumed to be a valid authenticated
226: * Principal.
227: *
228: * @param permission the permission to be checked for.
229: *
230: * @return true if the principal has the specified permission, false
231: * otherwise.
232: *
233: * @see #getPermissions
234: */
235: public boolean checkPermission(Principal principal,
236: Permission permission);
237:
238: /**
239: * Returns a string representation of the
240: * ACL contents.
241: *
242: * @return a string representation of the ACL contents.
243: */
244: public String toString();
245: }
|