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