1/* 2 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package java.security.acl; 27 28import java.util.Enumeration; 29import java.security.Principal; 30 31/** 32 * Interface representing an Access Control List (ACL). An Access 33 * Control List is a data structure used to guard access to 34 * resources.<p> 35 * 36 * An ACL can be thought of as a data structure with multiple ACL 37 * entries. Each ACL entry, of interface type AclEntry, contains a 38 * set of permissions associated with a particular principal. (A 39 * principal represents an entity such as an individual user or a 40 * group). Additionally, each ACL entry is specified as being either 41 * positive or negative. If positive, the permissions are to be 42 * granted to the associated principal. If negative, the permissions 43 * are to be denied.<p> 44 * 45 * The ACL Entries in each ACL observe the following rules: 46 * 47 * <ul> <li>Each principal can have at most one positive ACL entry and 48 * one negative entry; that is, multiple positive or negative ACL 49 * entries are not allowed for any principal. Each entry specifies 50 * the set of permissions that are to be granted (if positive) or 51 * denied (if negative). 52 * 53 * <li>If there is no entry for a particular principal, then the 54 * principal is considered to have a null (empty) permission set. 55 * 56 * <li>If there is a positive entry that grants a principal a 57 * particular permission, and a negative entry that denies the 58 * principal the same permission, the result is as though the 59 * permission was never granted or denied. 60 * 61 * <li>Individual permissions always override permissions of the 62 * group(s) to which the individual belongs. That is, individual 63 * negative permissions (specific denial of permissions) override the 64 * groups' positive permissions. And individual positive permissions 65 * override the groups' negative permissions. 66 * 67 * </ul> 68 * 69 * The {@code java.security.acl } package provides the 70 * interfaces to the ACL and related data structures (ACL entries, 71 * groups, permissions, etc.).<p> 72 * 73 * The {@code java.security.acl.Acl } interface extends the 74 * {@code java.security.acl.Owner } interface. The Owner 75 * interface is used to maintain a list of owners for each ACL. Only 76 * owners are allowed to modify an ACL. For example, only an owner can 77 * call the ACL's {@code addEntry} method to add a new ACL entry 78 * to the ACL. 79 * 80 * @see java.security.acl.AclEntry 81 * @see java.security.acl.Owner 82 * @see java.security.acl.Acl#getPermissions 83 * 84 * @author Satish Dharmaraj 85 * @since 1.1 86 * 87 * @deprecated This package has been replaced by {@code java.security.Policy} 88 * and related classes since 1.2. 89 */ 90 91@Deprecated(since="9") 92public interface Acl extends Owner { 93 94 /** 95 * Sets the name of this ACL. 96 * 97 * @param caller the principal invoking this method. It must be an 98 * owner of this ACL. 99 * 100 * @param name the name to be given to this ACL. 101 * 102 * @exception NotOwnerException if the caller principal 103 * is not an owner of this ACL. 104 * 105 * @see #getName 106 */ 107 public void setName(Principal caller, String name) 108 throws NotOwnerException; 109 110 /** 111 * Returns the name of this ACL. 112 * 113 * @return the name of this ACL. 114 * 115 * @see #setName 116 */ 117 public String getName(); 118 119 /** 120 * Adds an ACL entry to this ACL. An entry associates a principal 121 * (e.g., an individual or a group) with a set of 122 * permissions. Each principal can have at most one positive ACL 123 * entry (specifying permissions to be granted to the principal) 124 * and one negative ACL entry (specifying permissions to be 125 * denied). If there is already an ACL entry of the same type 126 * (negative or positive) already in the ACL, false is returned. 127 * 128 * @param caller the principal invoking this method. It must be an 129 * owner of this ACL. 130 * 131 * @param entry the ACL entry to be added to this ACL. 132 * 133 * @return true on success, false if an entry of the same type 134 * (positive or negative) for the same principal is already 135 * present in this ACL. 136 * 137 * @exception NotOwnerException if the caller principal 138 * is not an owner of this ACL. 139 */ 140 public boolean addEntry(Principal caller, AclEntry entry) 141 throws NotOwnerException; 142 143 /** 144 * Removes an ACL entry from this ACL. 145 * 146 * @param caller the principal invoking this method. It must be an 147 * owner of this ACL. 148 * 149 * @param entry the ACL entry to be removed from this ACL. 150 * 151 * @return true on success, false if the entry is not part of this ACL. 152 * 153 * @exception NotOwnerException if the caller principal is not 154 * an owner of this Acl. 155 */ 156 public boolean removeEntry(Principal caller, AclEntry entry) 157 throws NotOwnerException; 158 159 /** 160 * Returns an enumeration for the set of allowed permissions for the 161 * specified principal (representing an entity such as an individual or 162 * a group). This set of allowed permissions is calculated as 163 * follows: 164 * 165 * <ul> 166 * 167 * <li>If there is no entry in this Access Control List for the 168 * specified principal, an empty permission set is returned. 169 * 170 * <li>Otherwise, the principal's group permission sets are determined. 171 * (A principal can belong to one or more groups, where a group is a 172 * group of principals, represented by the Group interface.) 173 * The group positive permission set is the union of all 174 * the positive permissions of each group that the principal belongs to. 175 * The group negative permission set is the union of all 176 * the negative permissions of each group that the principal belongs to. 177 * If there is a specific permission that occurs in both 178 * the positive permission set and the negative permission set, 179 * it is removed from both.<p> 180 * 181 * The individual positive and negative permission sets are also 182 * determined. The positive permission set contains the permissions 183 * specified in the positive ACL entry (if any) for the principal. 184 * Similarly, the negative permission set contains the permissions 185 * specified in the negative ACL entry (if any) for the principal. 186 * The individual positive (or negative) permission set is considered 187 * to be null if there is not a positive (negative) ACL entry for the 188 * principal in this ACL.<p> 189 * 190 * The set of permissions granted to the principal is then calculated 191 * using the simple rule that individual permissions always override 192 * the group permissions. That is, the principal's individual negative 193 * permission set (specific denial of permissions) overrides the group 194 * positive permission set, and the principal's individual positive 195 * permission set overrides the group negative permission set. 196 * 197 * </ul> 198 * 199 * @param user the principal whose permission set is to be returned. 200 * 201 * @return the permission set specifying the permissions the principal 202 * is allowed. 203 */ 204 public Enumeration<Permission> getPermissions(Principal user); 205 206 /** 207 * Returns an enumeration of the entries in this ACL. Each element in 208 * the enumeration is of type AclEntry. 209 * 210 * @return an enumeration of the entries in this ACL. 211 */ 212 public Enumeration<AclEntry> entries(); 213 214 /** 215 * Checks whether or not the specified principal has the specified 216 * permission. If it does, true is returned, otherwise false is returned. 217 * 218 * More specifically, this method checks whether the passed permission 219 * is a member of the allowed permission set of the specified principal. 220 * The allowed permission set is determined by the same algorithm as is 221 * used by the {@code getPermissions} method. 222 * 223 * @param principal the principal, assumed to be a valid authenticated 224 * Principal. 225 * 226 * @param permission the permission to be checked for. 227 * 228 * @return true if the principal has the specified permission, false 229 * otherwise. 230 * 231 * @see #getPermissions 232 */ 233 public boolean checkPermission(Principal principal, Permission permission); 234 235 /** 236 * Returns a string representation of the 237 * ACL contents. 238 * 239 * @return a string representation of the ACL contents. 240 */ 241 public String toString(); 242} 243