1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
38 public abstract class RoleDescriptorImpl extends AbstractSignableSAMLObject implements RoleDescriptor {
39
40
41 private String id;
42
43
44 private DateTime validUntil;
45
46
47 private Long cacheDuration;
48
49
50 private final List<String> supportedProtocols;
51
52
53 private String errorURL;
54
55
56 private Extensions extensions;
57
58
59 private Organization organization;
60
61
62 private final AttributeMap unknownAttributes;
63
64
65 private final XMLObjectChildrenList<ContactPerson> contactPersons;
66
67
68 private final XMLObjectChildrenList<KeyDescriptor> keyDescriptors;
69
70
71
72
73
74
75
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
86 public String getID() {
87 return id;
88 }
89
90
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
98 public boolean isValid() {
99 if (validUntil != null) {
100 return validUntil.isBeforeNow();
101 } else {
102 return true;
103 }
104 }
105
106
107 public DateTime getValidUntil() {
108 return validUntil;
109 }
110
111
112 public void setValidUntil(DateTime validUntil) {
113 this.validUntil = prepareForAssignment(this.validUntil, validUntil);
114 }
115
116
117 public Long getCacheDuration() {
118 return cacheDuration;
119 }
120
121
122 public void setCacheDuration(Long duration) {
123 cacheDuration = prepareForAssignment(cacheDuration, duration);
124 }
125
126
127 public List<String> getSupportedProtocols() {
128 return Collections.unmodifiableList(supportedProtocols);
129 }
130
131
132 public boolean isSupportedProtocol(String protocol) {
133 return supportedProtocols.contains(protocol);
134 }
135
136
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
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
155 public void removeSupportedProtocols(Collection<String> protocols) {
156 for (String protocol : protocols) {
157 removeSupportedProtocol(protocol);
158 }
159 }
160
161
162 public void removeAllSupportedProtocols() {
163 for (String protocol : supportedProtocols) {
164 removeSupportedProtocol(protocol);
165 }
166 }
167
168
169 public String getErrorURL() {
170 return errorURL;
171 }
172
173
174 public void setErrorURL(String errorURL) {
175
176 this.errorURL = prepareForAssignment(this.errorURL, errorURL);
177 }
178
179
180 public Extensions getExtensions() {
181 return extensions;
182 }
183
184
185 public void setExtensions(Extensions extensions) throws IllegalArgumentException {
186 this.extensions = prepareForAssignment(this.extensions, extensions);
187 }
188
189
190 public Organization getOrganization() {
191 return organization;
192 }
193
194
195 public void setOrganization(Organization organization) throws IllegalArgumentException {
196 this.organization = prepareForAssignment(this.organization, organization);
197 }
198
199
200 public List<ContactPerson> getContactPersons() {
201 return contactPersons;
202 }
203
204
205 public List<KeyDescriptor> getKeyDescriptors() {
206 return keyDescriptors;
207 }
208
209
210
211
212 public AttributeMap getUnknownAttributes() {
213 return unknownAttributes;
214 }
215
216
217 public String getSignatureReferenceID() {
218 return id;
219 }
220
221
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 }