View Javadoc

1   /*
2    * Copyright 2005 University Corporation for Advanced Internet Development, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.saml2.metadata.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.joda.time.DateTime;
25  import org.opensaml.common.impl.AbstractSignableSAMLObject;
26  import org.opensaml.saml2.common.Extensions;
27  import org.opensaml.saml2.metadata.ContactPerson;
28  import org.opensaml.saml2.metadata.KeyDescriptor;
29  import org.opensaml.saml2.metadata.Organization;
30  import org.opensaml.saml2.metadata.RoleDescriptor;
31  import org.opensaml.xml.XMLObject;
32  import org.opensaml.xml.util.AttributeMap;
33  import org.opensaml.xml.util.DatatypeHelper;
34  import org.opensaml.xml.util.LazyList;
35  import org.opensaml.xml.util.XMLObjectChildrenList;
36  
37  /** Concrete implementation of {@link org.opensaml.saml2.metadata.RoleDescriptor}. */
38  public abstract class RoleDescriptorImpl extends AbstractSignableSAMLObject implements RoleDescriptor {
39  
40      /** ID attribute. */
41      private String id;
42  
43      /** validUntil attribute. */
44      private DateTime validUntil;
45  
46      /** cacheDurection attribute. */
47      private Long cacheDuration;
48  
49      /** Set of supported protocols. */
50      private final List<String> supportedProtocols;
51  
52      /** Error URL. */
53      private String errorURL;
54  
55      /** Extensions child. */
56      private Extensions extensions;
57  
58      /** Organization administering this role. */
59      private Organization organization;
60  
61      /** "anyAttribute" attributes. */
62      private final AttributeMap unknownAttributes;
63  
64      /** Contact persons for this role. */
65      private final XMLObjectChildrenList<ContactPerson> contactPersons;
66  
67      /** Key descriptors for this role. */
68      private final XMLObjectChildrenList<KeyDescriptor> keyDescriptors;
69  
70      /**
71       * Constructor.
72       * 
73       * @param namespaceURI the namespace the element is in
74       * @param elementLocalName the local name of the XML element this Object represents
75       * @param namespacePrefix the prefix for the given namespace
76       */
77      protected RoleDescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
78          super(namespaceURI, elementLocalName, namespacePrefix);
79          unknownAttributes = new AttributeMap(this);
80          supportedProtocols = new LazyList<String>();
81          contactPersons = new XMLObjectChildrenList<ContactPerson>(this);
82          keyDescriptors = new XMLObjectChildrenList<KeyDescriptor>(this);
83      }
84  
85      /** {@inheritDoc} */
86      public String getID() {
87          return id;
88      }
89  
90      /** {@inheritDoc} */
91      public void setID(String newID) {
92          String oldID = this.id;
93          this.id = prepareForAssignment(this.id, newID);
94          registerOwnID(oldID, this.id);
95      }
96  
97      /** {@inheritDoc} */
98      public boolean isValid() {
99          if (validUntil != null) {
100             return validUntil.isBeforeNow();
101         } else {
102             return true;
103         }
104     }
105 
106     /** {@inheritDoc} */
107     public DateTime getValidUntil() {
108         return validUntil;
109     }
110 
111     /** {@inheritDoc} */
112     public void setValidUntil(DateTime validUntil) {
113         this.validUntil = prepareForAssignment(this.validUntil, validUntil);
114     }
115 
116     /** {@inheritDoc} */
117     public Long getCacheDuration() {
118         return cacheDuration;
119     }
120 
121     /** {@inheritDoc} */
122     public void setCacheDuration(Long duration) {
123         cacheDuration = prepareForAssignment(cacheDuration, duration);
124     }
125 
126     /** {@inheritDoc} */
127     public List<String> getSupportedProtocols() {
128         return Collections.unmodifiableList(supportedProtocols);
129     }
130 
131     /** {@inheritDoc} */
132     public boolean isSupportedProtocol(String protocol) {
133         return supportedProtocols.contains(protocol);
134     }
135 
136     /** {@inheritDoc} */
137     public void addSupportedProtocol(String protocol) {
138         protocol = DatatypeHelper.safeTrimOrNullString(protocol);
139         if (protocol != null && !supportedProtocols.contains(protocol)) {
140             releaseThisandParentDOM();
141             supportedProtocols.add(protocol);
142         }
143     }
144 
145     /** {@inheritDoc} */
146     public void removeSupportedProtocol(String protocol) {
147         protocol = DatatypeHelper.safeTrimOrNullString(protocol);
148         if (protocol != null && supportedProtocols.contains(protocol)) {
149             releaseThisandParentDOM();
150             supportedProtocols.remove(protocol);
151         }
152     }
153 
154     /** {@inheritDoc} */
155     public void removeSupportedProtocols(Collection<String> protocols) {
156         for (String protocol : protocols) {
157             removeSupportedProtocol(protocol);
158         }
159     }
160 
161     /** {@inheritDoc} */
162     public void removeAllSupportedProtocols() {
163         for (String protocol : supportedProtocols) {
164             removeSupportedProtocol(protocol);
165         }
166     }
167 
168     /** {@inheritDoc} */
169     public String getErrorURL() {
170         return errorURL;
171     }
172 
173     /** {@inheritDoc} */
174     public void setErrorURL(String errorURL) {
175 
176         this.errorURL = prepareForAssignment(this.errorURL, errorURL);
177     }
178 
179     /** {@inheritDoc} */
180     public Extensions getExtensions() {
181         return extensions;
182     }
183 
184     /** {@inheritDoc} */
185     public void setExtensions(Extensions extensions) throws IllegalArgumentException {
186         this.extensions = prepareForAssignment(this.extensions, extensions);
187     }
188 
189     /** {@inheritDoc} */
190     public Organization getOrganization() {
191         return organization;
192     }
193 
194     /** {@inheritDoc} */
195     public void setOrganization(Organization organization) throws IllegalArgumentException {
196         this.organization = prepareForAssignment(this.organization, organization);
197     }
198 
199     /** {@inheritDoc} */
200     public List<ContactPerson> getContactPersons() {
201         return contactPersons;
202     }
203 
204     /** {@inheritDoc} */
205     public List<KeyDescriptor> getKeyDescriptors() {
206         return keyDescriptors;
207     }
208 
209     /**
210      * {@inheritDoc}
211      */
212     public AttributeMap getUnknownAttributes() {
213         return unknownAttributes;
214     }
215 
216     /** {@inheritDoc} */
217     public String getSignatureReferenceID() {
218         return id;
219     }
220 
221     /** {@inheritDoc} */
222     public List<XMLObject> getOrderedChildren() {
223         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
224 
225         if (getSignature() != null) {
226             children.add(getSignature());
227         }
228 
229         if (extensions != null) {
230             children.add(getExtensions());
231         }
232         children.addAll(getKeyDescriptors());
233         if (organization != null) {
234             children.add(getOrganization());
235         }
236         children.addAll(getContactPersons());
237 
238         return Collections.unmodifiableList(children);
239     }
240 }