2 * The Shibboleth License, Version 1.
4 * University Corporation for Advanced Internet Development, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution, if any, must include
17 * the following acknowledgment: "This product includes software developed by
18 * the University Corporation for Advanced Internet Development
19 * <http://www.ucaid.edu>Internet2 Project. Alternately, this acknowledegement
20 * may appear in the software itself, if and wherever such third-party
21 * acknowledgments normally appear.
23 * Neither the name of Shibboleth nor the names of its contributors, nor
24 * Internet2, nor the University Corporation for Advanced Internet Development,
25 * Inc., nor UCAID may be used to endorse or promote products derived from this
26 * software without specific prior written permission. For written permission,
27 * please contact shibboleth@shibboleth.org
29 * Products derived from this software may not be called Shibboleth, Internet2,
30 * UCAID, or the University Corporation for Advanced Internet Development, nor
31 * may Shibboleth appear in their name, without prior written permission of the
32 * University Corporation for Advanced Internet Development.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 * AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
38 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK
39 * OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE.
40 * IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
41 * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 package edu.internet2.middleware.shibboleth.aa;
53 * Attribute Authority & Release Policy
54 * Access Control List for ARPs
56 * @author Parviz Dousti (dousti@cmu.edu)
63 import java.security.acl.*;
65 public class AA_Acl implements java.security.acl.Acl, Serializable{
67 static final long serialVersionUID = 1L;
73 AA_Acl(String name, java.security.Principal root){
74 positives = new HashSet();
75 negatives = new HashSet();
76 owners = new HashSet();
81 AA_Acl(Collection p, Collection n, String name, java.security.Principal root){
82 positives = new HashSet(p);
83 negatives = new HashSet(n);
84 owners = new HashSet();
89 /////// Methods //////////
91 public boolean addEntry(java.security.Principal p, AclEntry entry)throws NotOwnerException{
93 if(this.isOwner(p) == false)
94 throw new NotOwnerException();
95 if(entry.isNegative()){
96 if(negatives.contains(entry)){
102 }else{ // is positive ACL
103 if(positives.contains(entry)){
106 positives.add(entry);
112 public boolean checkPermission(java.security.Principal user, java.security.acl.Permission perm){
113 for(Iterator it = positives.iterator(); it.hasNext();){
114 AclEntry entry = (AclEntry)it.next();
115 java.security.Principal p = entry.getPrincipal();
117 if(entry.checkPermission(perm)){
118 //make sure it is not in negative list
119 for(Iterator it2 = negatives.iterator(); it2.hasNext();){
120 AclEntry entry2 = (AclEntry)it2.next();
121 java.security.Principal p2 = entry2.getPrincipal();
123 if(entry2.checkPermission(perm)){
124 return false; // in both list
129 // not in negative list
130 return true; // give permission
138 return false; // not in any positive entry
141 public Enumeration entries(){
142 return new AclEntryEnumeration(positives, negatives);
145 public String getName(){
149 public Enumeration getPermissions(java.security.Principal user){
150 return new AclPermissionEnumeration(user, positives, negatives);
153 public boolean removeEntry(java.security.Principal caller, AclEntry entry)
154 throws NotOwnerException{
156 if(this.isOwner(caller) == false)
157 throw new NotOwnerException();
158 if(entry.isNegative()){
159 if(negatives.contains(entry)){
160 negatives.remove(entry);
165 }else{ // is positive ACL
166 if(positives.contains(entry)){
167 positives.remove(entry);
176 public void setName(java.security.Principal caller, String name)
177 throws NotOwnerException{
178 if(this.isOwner(caller) == false)
179 throw new NotOwnerException();
183 public String toString(){
193 /////////// Owner methods ///////////////
194 public boolean addOwner(java.security.Principal caller, java.security.Principal owner)
195 throws NotOwnerException{
196 if(owners.contains(caller) == false)
197 throw new NotOwnerException();
198 return owners.add(owner);
201 public boolean deleteOwner(java.security.Principal caller, java.security.Principal owner)
202 throws NotOwnerException,
204 if(owners.contains(caller) == false)
205 throw new NotOwnerException();
206 return owners.remove(owner);
209 public boolean isOwner(java.security.Principal owner){
210 return owners.contains(owner);
216 class AclEntryEnumeration implements java.util.Enumeration{
220 AclEntryEnumeration(HashSet p, HashSet n){
223 it = entries.iterator();
226 public boolean hasMoreElements(){
230 public Object nextElement(){
237 class AclPermissionEnumeration implements java.util.Enumeration{
241 AclPermissionEnumeration(java.security.Principal user, HashSet p, HashSet n){
242 permissions = new HashSet();
243 // go throu entries and find the one for this user
244 for(Iterator i = p.iterator(); i.hasNext();){
245 AclEntry ae = (AclEntry)i.next();
246 if(ae.getPrincipal().equals(user)){
247 // go throu permissions and add it to enum
248 for(Enumeration j=ae.permissions(); j.hasMoreElements();){
249 permissions.add((Permission)j.nextElement());
253 // now go throu negatives and either add it or remove positve one
254 for(Iterator i = n.iterator(); i.hasNext();){
255 AclEntry ae = (AclEntry)i.next();
256 if(ae.getPrincipal().equals(user)){
257 // go throu permissions and check it
258 for(Enumeration j=ae.permissions(); j.hasMoreElements();){
259 Permission perm = (Permission)j.nextElement();
260 if(permissions.contains(perm)){
261 permissions.remove(perm);
263 permissions.add(perm);
269 it = permissions.iterator();
272 public boolean hasMoreElements(){
276 public Object nextElement(){