Added hardcoded id to all classes involved in ARP serialiazation. Intended to fix...
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / aa / ArpResource.java
1 /* 
2  * The Shibboleth License, Version 1. 
3  * Copyright (c) 2002 
4  * University Corporation for Advanced Internet Development, Inc. 
5  * All rights reserved
6  * 
7  * 
8  * Redistribution and use in source and binary forms, with or without 
9  * modification, are permitted provided that the following conditions are met:
10  * 
11  * Redistributions of source code must retain the above copyright notice, this 
12  * list of conditions and the following disclaimer.
13  * 
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.
22  * 
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
28  * 
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.
33  * 
34  * 
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.
48  */
49
50 package edu.internet2.middleware.shibboleth.aa;
51
52 /**
53  *  Attribute Authority & Release Policy
54  *  Resource (or URL) node in the ARP tree.
55  *
56  * @author     Parviz Dousti (dousti@cmu.edu)
57  * @created    June, 2002
58  */
59
60
61 import java.io.*;
62 import java.util.*;
63 import java.security.acl.*;
64
65 public class ArpResource extends ArpCore implements Serializable{
66
67         static final long serialVersionUID = 1L;
68         
69     // Attributes
70     protected String name;
71     protected String comment;
72
73     // Associations
74     protected TName tName;
75     protected Vector attributes;
76     protected AA_Acl acl;
77
78     // constructors
79     public ArpResource(String name) throws NotOwnerException{
80         this.name = name;
81         tName = new TName(name);
82         attributes = new Vector();
83         makeAcl("resourceAcl");
84     }
85
86     public ArpResource(String name, String comment) throws NotOwnerException{
87         this(name);
88         this.comment = comment;
89     }
90
91
92     // Operations
93     public String toString() {
94         return name+" ["+tName+"]";
95     }
96
97
98     public boolean addAnAttribute(String name, boolean exclude)
99         throws AAPermissionException{
100
101         if(attributes.contains(new ArpAttribute(name, exclude)))
102             return false; // already there
103         if(! insertPermitted())
104             throw new AAPermissionException("No INSERT right for "+getCaller());
105         attributes.add(new ArpAttribute(name, exclude));
106         return true;
107     }
108
109     public boolean addAnAttribute(ArpAttribute attr)
110         throws AAPermissionException{
111         return addAnAttribute(attr, false);
112     }
113
114     /**
115      * Adds the given attribute to the attributes for this Resource.
116      * if force flag is true and attribute already exists
117      * then replaces the existing reource otherwise leaves the existing 
118      * attribute untouched.  
119      * returns false if reource already existed.
120      */
121     public boolean addAnAttribute(ArpAttribute attr, boolean force)
122         throws AAPermissionException {
123
124         if(attributes.contains(attr)){
125             if(force){
126                 if(! replacePermitted())
127                     throw new AAPermissionException("No replace right for "+getCaller());               
128                 attributes.remove(attr);
129                 attributes.add(attr);
130             }
131             return false; // already there
132         }
133         if(! insertPermitted())
134             throw new AAPermissionException("No INSERT right for "+getCaller());        
135         attributes.add(attr);
136         return true;
137     }
138
139     public boolean removeAnAttribute(String name)
140         throws AAPermissionException {
141
142         if(attributes.contains(new ArpAttribute(name, false))){
143             if(! insertPermitted())
144                 throw new AAPermissionException("No DELETE right for "+getCaller());        
145             attributes.remove(new ArpAttribute(name, false));
146             return true;
147         }
148         return false; // not found
149     }
150
151     public ArpAttribute getAttribute(String name) {
152         Enumeration en = attributes.elements();
153         while(en.hasMoreElements()){
154             ArpAttribute aAttribute = (ArpAttribute)en.nextElement();
155             if(aAttribute.getName().equals(name))
156                 return aAttribute;
157         }
158         return null;
159     }
160
161     public ArpAttribute[] getAttributes() {
162         int len = attributes.size();
163         ArpAttribute[] a = new ArpAttribute[len];
164         for(int i = 0; i < len; i++)
165             a[i] = (ArpAttribute)attributes.get(i);
166         return a;
167     }
168
169
170     public int fit(String resrcName) {
171         TName tn = new TName(resrcName);
172         return tName.compare(tn);
173     }
174
175     public TName getTName(){
176         return tName;
177     }
178
179     public String getName(){
180         return name;
181     }
182
183     public String getComment(){
184         return comment;
185     }
186
187     public void setComment(String s){
188         this.comment = s;
189     }
190
191     public boolean equals(Object rsrc){
192         return name.equals(((ArpResource)rsrc).getName());
193     }
194
195 } /* end class ArpResource */