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  /**
18   * 
19   */
20  
21  package org.opensaml.saml2.core.impl;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.opensaml.saml2.core.AuthnRequest;
28  import org.opensaml.saml2.core.Conditions;
29  import org.opensaml.saml2.core.NameIDPolicy;
30  import org.opensaml.saml2.core.RequestedAuthnContext;
31  import org.opensaml.saml2.core.Scoping;
32  import org.opensaml.saml2.core.Subject;
33  import org.opensaml.xml.XMLObject;
34  import org.opensaml.xml.schema.XSBooleanValue;
35  
36  /**
37   * A concrete implementation of {@link org.opensaml.saml2.core.AuthnRequest}.
38   */
39  public class AuthnRequestImpl extends RequestAbstractTypeImpl implements AuthnRequest {
40  
41      /** Subject child element. */
42      private Subject subject;
43  
44      /** NameIDPolicy child element. */
45      private NameIDPolicy nameIDPolicy;
46  
47      /** Conditions child element. */
48      private Conditions conditions;
49  
50      /** RequestedAuthnContext child element. */
51      private RequestedAuthnContext requestedAuthnContext;
52  
53      /** Scoping child element. */
54      private Scoping scoping;
55  
56      /** ForeceAuthn attribute. */
57      private XSBooleanValue forceAuthn;
58  
59      /** IsPassive attribute. */
60      private XSBooleanValue isPassive;
61  
62      /** ProtocolBinding attribute. */
63      private String protocolBinding;
64  
65      /** AssertionConsumerServiceIndex attribute. */
66      private Integer assertionConsumerServiceIndex;
67  
68      /** AssertionConsumerServiceURL attribute. */
69      private String assertionConsumerServiceURL;
70  
71      /** AttributeConsumingServiceIndex attribute. */
72      private Integer attributeConsumingServiceIndex;
73  
74      /** ProviderName attribute. */
75      private String providerName;
76  
77      /**
78       * Constructor.
79       * 
80       * @param namespaceURI the namespace the element is in
81       * @param elementLocalName the local name of the XML element this Object represents
82       * @param namespacePrefix the prefix for the given namespace
83       */
84      protected AuthnRequestImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
85          super(namespaceURI, elementLocalName, namespacePrefix);
86      }
87  
88      /** {@inheritDoc} */
89      public Boolean isForceAuthn() {
90          if (forceAuthn != null) {
91              return forceAuthn.getValue();
92          }
93  
94          return Boolean.FALSE;
95      }
96  
97      /** {@inheritDoc} */
98      public XSBooleanValue isForceAuthnXSBoolean() {
99          return forceAuthn;
100     }
101 
102     /** {@inheritDoc} */
103     public void setForceAuthn(Boolean newForceAuth) {
104         if (newForceAuth != null) {
105             forceAuthn = prepareForAssignment(forceAuthn, new XSBooleanValue(newForceAuth, false));
106         } else {
107             forceAuthn = prepareForAssignment(forceAuthn, null);
108         }
109     }
110 
111     /** {@inheritDoc} */
112     public void setForceAuthn(XSBooleanValue newForceAuthn) {
113         forceAuthn = prepareForAssignment(this.forceAuthn, newForceAuthn);
114     }
115 
116     /** {@inheritDoc} */
117     public Boolean isPassive() {
118         if (isPassive != null) {
119             return isPassive.getValue();
120         }
121 
122         return Boolean.FALSE;
123     }
124 
125     /** {@inheritDoc} */
126     public XSBooleanValue isPassiveXSBoolean() {
127         return isPassive;
128     }
129 
130     /** {@inheritDoc} */
131     public void setIsPassive(Boolean newIsPassive) {
132         if (newIsPassive != null) {
133             isPassive = prepareForAssignment(isPassive, new XSBooleanValue(newIsPassive, false));
134         } else {
135             isPassive = prepareForAssignment(isPassive, null);
136         }
137     }
138 
139     /** {@inheritDoc} */
140     public void setIsPassive(XSBooleanValue newIsPassive) {
141         this.isPassive = prepareForAssignment(this.isPassive, newIsPassive);
142     }
143 
144     /** {@inheritDoc} */
145     public String getProtocolBinding() {
146         return this.protocolBinding;
147     }
148 
149     /** {@inheritDoc} */
150     public void setProtocolBinding(String newProtocolBinding) {
151         this.protocolBinding = prepareForAssignment(this.protocolBinding, newProtocolBinding);
152     }
153 
154     /** {@inheritDoc} */
155     public Integer getAssertionConsumerServiceIndex() {
156         return assertionConsumerServiceIndex;
157     }
158 
159     /** {@inheritDoc} */
160     public void setAssertionConsumerServiceIndex(Integer newAssertionConsumerServiceIndex) {
161         this.assertionConsumerServiceIndex = prepareForAssignment(this.assertionConsumerServiceIndex,
162                 newAssertionConsumerServiceIndex);
163     }
164 
165     /** {@inheritDoc} */
166     public String getAssertionConsumerServiceURL() {
167         return this.assertionConsumerServiceURL;
168     }
169 
170     /** {@inheritDoc} */
171     public void setAssertionConsumerServiceURL(String newAssertionConsumerServiceURL) {
172         this.assertionConsumerServiceURL = prepareForAssignment(this.assertionConsumerServiceURL,
173                 newAssertionConsumerServiceURL);
174     }
175 
176     /** {@inheritDoc} */
177     public Integer getAttributeConsumingServiceIndex() {
178         return this.attributeConsumingServiceIndex;
179     }
180 
181     /** {@inheritDoc} */
182     public void setAttributeConsumingServiceIndex(Integer newAttributeConsumingServiceIndex) {
183         this.attributeConsumingServiceIndex = prepareForAssignment(this.attributeConsumingServiceIndex,
184                 newAttributeConsumingServiceIndex);
185     }
186 
187     /** {@inheritDoc} */
188     public String getProviderName() {
189         return this.providerName;
190     }
191 
192     /** {@inheritDoc} */
193     public void setProviderName(String newProviderName) {
194         this.providerName = prepareForAssignment(this.providerName, newProviderName);
195     }
196 
197     /** {@inheritDoc} */
198     public Subject getSubject() {
199         return this.subject;
200     }
201 
202     /** {@inheritDoc} */
203     public void setSubject(Subject newSubject) {
204         this.subject = prepareForAssignment(this.subject, newSubject);
205     }
206 
207     /** {@inheritDoc} */
208     public NameIDPolicy getNameIDPolicy() {
209         return this.nameIDPolicy;
210     }
211 
212     /** {@inheritDoc} */
213     public void setNameIDPolicy(NameIDPolicy newNameIDPolicy) {
214         this.nameIDPolicy = prepareForAssignment(this.nameIDPolicy, newNameIDPolicy);
215     }
216 
217     /** {@inheritDoc} */
218     public Conditions getConditions() {
219         return this.conditions;
220     }
221 
222     /** {@inheritDoc} */
223     public void setConditions(Conditions newConditions) {
224         this.conditions = prepareForAssignment(this.conditions, newConditions);
225     }
226 
227     /** {@inheritDoc} */
228     public RequestedAuthnContext getRequestedAuthnContext() {
229         return this.requestedAuthnContext;
230     }
231 
232     /** {@inheritDoc} */
233     public void setRequestedAuthnContext(RequestedAuthnContext newRequestedAuthnContext) {
234         this.requestedAuthnContext = prepareForAssignment(this.requestedAuthnContext, newRequestedAuthnContext);
235     }
236 
237     /** {@inheritDoc} */
238     public Scoping getScoping() {
239         return this.scoping;
240     }
241 
242     /** {@inheritDoc} */
243     public void setScoping(Scoping newScoping) {
244         this.scoping = prepareForAssignment(this.scoping, newScoping);
245     }
246 
247     /** {@inheritDoc} */
248     public List<XMLObject> getOrderedChildren() {
249         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
250 
251         if (super.getOrderedChildren() != null) {
252             children.addAll(super.getOrderedChildren());
253         }
254 
255         if (subject != null) {
256             children.add(subject);
257         }
258 
259         if (nameIDPolicy != null) {
260             children.add(nameIDPolicy);
261         }
262 
263         if (conditions != null) {
264             children.add(conditions);
265         }
266 
267         if (requestedAuthnContext != null) {
268             children.add(requestedAuthnContext);
269         }
270 
271         if (scoping != null) {
272             children.add(scoping);
273         }
274 
275         if (children.size() == 0) {
276             return null;
277         }
278 
279         return Collections.unmodifiableList(children);
280     }
281 }