1. /*
  2. * @(#)Acl.java 1.23 04/05/05
  3. *
  4. * Copyright 2004 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.23, 04/05/05
  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. * @see #getName
  83. */
  84. public void setName(Principal caller, String name)
  85. throws NotOwnerException;
  86. /**
  87. * Returns the name of this ACL.
  88. *
  89. * @return the name of this ACL.
  90. *
  91. * @see #setName
  92. */
  93. public String getName();
  94. /**
  95. * Adds an ACL entry to this ACL. An entry associates a principal
  96. * (e.g., an individual or a group) with a set of
  97. * permissions. Each principal can have at most one positive ACL
  98. * entry (specifying permissions to be granted to the principal)
  99. * and one negative ACL entry (specifying permissions to be
  100. * denied). If there is already an ACL entry of the same type
  101. * (negative or positive) already in the ACL, false is returned.
  102. *
  103. * @param caller the principal invoking this method. It must be an
  104. * owner of this ACL.
  105. *
  106. * @param entry the ACL entry to be added to this ACL.
  107. *
  108. * @return true on success, false if an entry of the same type
  109. * (positive or negative) for the same principal is already
  110. * present in this ACL.
  111. *
  112. * @exception NotOwnerException if the caller principal
  113. * is not an owner of this ACL.
  114. */
  115. public boolean addEntry(Principal caller, AclEntry entry)
  116. throws NotOwnerException;
  117. /**
  118. * Removes an ACL entry from this ACL.
  119. *
  120. * @param caller the principal invoking this method. It must be an
  121. * owner of this ACL.
  122. *
  123. * @param entry the ACL entry to be removed from this ACL.
  124. *
  125. * @return true on success, false if the entry is not part of this ACL.
  126. *
  127. * @exception NotOwnerException if the caller principal is not
  128. * an owner of this Acl.
  129. */
  130. public boolean removeEntry(Principal caller, AclEntry entry)
  131. throws NotOwnerException;
  132. /**
  133. * Returns an enumeration for the set of allowed permissions for the
  134. * specified principal (representing an entity such as an individual or
  135. * a group). This set of allowed permissions is calculated as
  136. * follows:<p>
  137. *
  138. * <ul>
  139. *
  140. * <li>If there is no entry in this Access Control List for the
  141. * specified principal, an empty permission set is returned.<p>
  142. *
  143. * <li>Otherwise, the principal's group permission sets are determined.
  144. * (A principal can belong to one or more groups, where a group is a
  145. * group of principals, represented by the Group interface.)
  146. * The group positive permission set is the union of all
  147. * the positive permissions of each group that the principal belongs to.
  148. * The group negative permission set is the union of all
  149. * the negative permissions of each group that the principal belongs to.
  150. * If there is a specific permission that occurs in both
  151. * the positive permission set and the negative permission set,
  152. * it is removed from both.<p>
  153. *
  154. * The individual positive and negative permission sets are also
  155. * determined. The positive permission set contains the permissions
  156. * specified in the positive ACL entry (if any) for the principal.
  157. * Similarly, the negative permission set contains the permissions
  158. * specified in the negative ACL entry (if any) for the principal.
  159. * The individual positive (or negative) permission set is considered
  160. * to be null if there is not a positive (negative) ACL entry for the
  161. * principal in this ACL.<p>
  162. *
  163. * The set of permissions granted to the principal is then calculated
  164. * using the simple rule that individual permissions always override
  165. * the group permissions. That is, the principal's individual negative
  166. * permission set (specific denial of permissions) overrides the group
  167. * positive permission set, and the principal's individual positive
  168. * permission set overrides the group negative permission set.
  169. *
  170. * </ul>
  171. *
  172. * @param user the principal whose permission set is to be returned.
  173. *
  174. * @return the permission set specifying the permissions the principal
  175. * is allowed.
  176. */
  177. public Enumeration<Permission> getPermissions(Principal user);
  178. /**
  179. * Returns an enumeration of the entries in this ACL. Each element in
  180. * the enumeration is of type AclEntry.
  181. *
  182. * @return an enumeration of the entries in this ACL.
  183. */
  184. public Enumeration<AclEntry> entries();
  185. /**
  186. * Checks whether or not the specified principal has the specified
  187. * permission. If it does, true is returned, otherwise false is returned.
  188. *
  189. * More specifically, this method checks whether the passed permission
  190. * is a member of the allowed permission set of the specified principal.
  191. * The allowed permission set is determined by the same algorithm as is
  192. * used by the <code>getPermissions</code> method.
  193. *
  194. * @param principal the principal, assumed to be a valid authenticated
  195. * Principal.
  196. *
  197. * @param permission the permission to be checked for.
  198. *
  199. * @return true if the principal has the specified permission, false
  200. * otherwise.
  201. *
  202. * @see #getPermissions
  203. */
  204. public boolean checkPermission(Principal principal, Permission permission);
  205. /**
  206. * Returns a string representation of the
  207. * ACL contents.
  208. *
  209. * @return a string representation of the ACL contents.
  210. */
  211. public String toString();
  212. }