1. /*
  2. * @(#)Acl.java 1.17 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.acl;
  8. import java.util.Enumeration;
  9. import java.security.Principal;
  10. /**
  11. * Interface representing an Access Control List (ACL). An Access
  12. * Control List is a data structure used to guard access to
  13. * resources.<p>
  14. *
  15. * An ACL can be thought of as a data structure with multiple ACL
  16. * entries. Each ACL entry, of interface type AclEntry, contains a
  17. * set of permissions associated with a particular principal. (A
  18. * principal represents an entity such as an individual user or a
  19. * group). Additionally, each ACL entry is specified as being either
  20. * positive or negative. If positive, the permissions are to be
  21. * granted to the associated principal. If negative, the permissions
  22. * are to be denied.<p>
  23. *
  24. * The ACL Entries in each ACL observe the following rules:<p>
  25. *
  26. * <ul> <li>Each principal can have at most one positive ACL entry and
  27. * one negative entry; that is, multiple positive or negative ACL
  28. * entries are not allowed for any principal. Each entry specifies
  29. * the set of permissions that are to be granted (if positive) or
  30. * denied (if negative). <p>
  31. *
  32. * <li>If there is no entry for a particular principal, then the
  33. * principal is considered to have a null (empty) permission set.<p>
  34. *
  35. * <li>If there is a positive entry that grants a principal a
  36. * particular permission, and a negative entry that denies the
  37. * principal the same permission, the result is as though the
  38. * permission was never granted or denied. <p>
  39. *
  40. * <li>Individual permissions always override permissions of the
  41. * group(s) to which the individual belongs. That is, individual
  42. * negative permissions (specific denial of permissions) override the
  43. * groups' positive permissions. And individual positive permissions
  44. * override the groups' negative permissions.<p>
  45. *
  46. * </ul>
  47. *
  48. * The <code> java.security.acl </code> package provides the
  49. * interfaces to the ACL and related data structures (ACL entries,
  50. * groups, permissions, etc.), and the <code> sun.security.acl </code>
  51. * classes provide a default implementation of the interfaces. For
  52. * example, <code> java.security.acl.Acl </code> provides the
  53. * interface to an ACL and the <code> sun.security.acl.AclImpl </code>
  54. * class provides the default implementation of the interface.<p>
  55. *
  56. * The <code> java.security.acl.Acl </code> interface extends the
  57. * <code> java.security.acl.Owner </code> interface. The Owner
  58. * interface is used to maintain a list of owners for each ACL. Only
  59. * owners are allowed to modify an ACL. For example, only an owner can
  60. * call the ACL's <code>addEntry</code> method to add a new ACL entry
  61. * to the ACL.
  62. *
  63. * @see java.security.acl.AclEntry
  64. * @see java.security.acl.Owner
  65. * @see java.security.acl.Acl#getPermissions
  66. *
  67. * @version 1.17, 01/11/29
  68. * @author Satish Dharmaraj
  69. */
  70. public interface Acl extends Owner {
  71. /**
  72. * Sets the name of this ACL.
  73. *
  74. * @param caller the principal invoking this method. It must be an
  75. * owner of this ACL.
  76. *
  77. * @param name the name to be given to this ACL.
  78. *
  79. * @exception NotOwnerException if the caller principal
  80. * is not an owner of this ACL.
  81. */
  82. public void setName(Principal caller, String name)
  83. throws NotOwnerException;
  84. /**
  85. * Returns the name of this ACL.
  86. *
  87. * @return the name of this ACL.
  88. */
  89. public String getName();
  90. /**
  91. * Adds an ACL entry to this ACL. An entry associates a principal
  92. * (e.g., an individual or a group) with a set of
  93. * permissions. Each principal can have at most one positive ACL
  94. * entry (specifying permissions to be granted to the principal)
  95. * and one negative ACL entry (specifying permissions to be
  96. * denied). If there is already an ACL entry of the same type
  97. * (negative or positive) already in the ACL, false is returned.
  98. *
  99. * @param caller the principal invoking this method. It must be an
  100. * owner of this ACL.
  101. *
  102. * @param entry the ACL entry to be added to this ACL.
  103. *
  104. * @return true on success, false if an entry of the same type
  105. * (positive or negative) for the same principal is already
  106. * present in this ACL.
  107. *
  108. * @exception NotOwnerException if the caller principal
  109. * is not an owner of this ACL.
  110. */
  111. public boolean addEntry(Principal caller, AclEntry entry)
  112. throws NotOwnerException;
  113. /**
  114. * Removes an ACL entry from this ACL.
  115. *
  116. * @param caller the principal invoking this method. It must be an
  117. * owner of this ACL.
  118. *
  119. * @param entry the ACL entry to be removed from this ACL.
  120. *
  121. * @return true on success, false if the entry is not part of this ACL.
  122. *
  123. * @exception NotOwnerException if the caller principal is not
  124. * an owner of this Acl.
  125. */
  126. public boolean removeEntry(Principal caller, AclEntry entry)
  127. throws NotOwnerException;
  128. /**
  129. * Returns an enumeration for the set of allowed permissions for the
  130. * specified principal (representing an entity such as an individual or
  131. * a group). This set of allowed permissions is calculated as
  132. * follows:<p>
  133. *
  134. * <ul>
  135. *
  136. * <li>If there is no entry in this Access Control List for the
  137. * specified principal, an empty permission set is returned.<p>
  138. *
  139. * <li>Otherwise, the principal's group permission sets are determined.
  140. * (A principal can belong to one or more groups, where a group is a
  141. * group of principals, represented by the Group interface.)
  142. * The group positive permission set is the union of all
  143. * the positive permissions of each group that the principal belongs to.
  144. * The group negative permission set is the union of all
  145. * the negative permissions of each group that the principal belongs to.
  146. * If there is a specific permission that occurs in both
  147. * the positive permission set and the negative permission set,
  148. * it is removed from both.<p>
  149. *
  150. * The individual positive and negative permission sets are also
  151. * determined. The positive permission set contains the permissions
  152. * specified in the positive ACL entry (if any) for the principal.
  153. * Similarly, the negative permission set contains the permissions
  154. * specified in the negative ACL entry (if any) for the principal.
  155. * The individual positive (or negative) permission set is considered
  156. * to be null if there is not a positive (negative) ACL entry for the
  157. * principal in this ACL.<p>
  158. *
  159. * The set of permissions granted to the principal is then calculated
  160. * using the simple rule that individual permissions always override
  161. * the group permissions. That is, the principal's individual negative
  162. * permission set (specific denial of permissions) overrides the group
  163. * positive permission set, and the principal's individual positive
  164. * permission set overrides the group negative permission set.
  165. *
  166. * </ul>
  167. *
  168. * @param user the principal whose permission set is to be returned.
  169. *
  170. * @return the permission set specifying the permissions the principal
  171. * is allowed.
  172. */
  173. public Enumeration getPermissions(Principal user);
  174. /**
  175. * Returns an enumeration of the entries in this ACL. Each element in
  176. * the enumeration is of type AclEntry.
  177. *
  178. * @return an enumeration of the entries in this ACL.
  179. */
  180. public Enumeration entries();
  181. /**
  182. * Checks whether or not the specified principal has the specified
  183. * permission. If it does, true is returned, otherwise false is returned.
  184. *
  185. * More specifically, this method checks whether the passed permission
  186. * is a member of the allowed permission set of the specified principal.
  187. * The allowed permission set is determined by the same algorithm as is
  188. * used by the <code>getPermissions</code> method.
  189. *
  190. * @param principal the principal, assumed to be a valid authenticated
  191. * Principal.
  192. *
  193. * @param permission the permission to be checked for.
  194. *
  195. * @return true if the principal has the specified permission, false
  196. * otherwise.
  197. *
  198. * @see #getPermissions
  199. */
  200. public boolean checkPermission(Principal principal, Permission permission);
  201. /**
  202. * Returns a string representation of the
  203. * ACL contents.
  204. *
  205. * @return a string representation of the ACL contents.
  206. */
  207. public String toString();
  208. }