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 org.opensaml.saml2.core.AuthnRequest;
24  import org.opensaml.saml2.core.Conditions;
25  import org.opensaml.saml2.core.NameIDPolicy;
26  import org.opensaml.saml2.core.RequestedAuthnContext;
27  import org.opensaml.saml2.core.Scoping;
28  import org.opensaml.saml2.core.Subject;
29  import org.opensaml.xml.XMLObject;
30  import org.opensaml.xml.io.UnmarshallingException;
31  import org.opensaml.xml.schema.XSBooleanValue;
32  import org.w3c.dom.Attr;
33  
34  /**
35   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.AuthnRequest} objects.
36   */
37  public class AuthnRequestUnmarshaller extends RequestAbstractTypeUnmarshaller {
38  
39      /** {@inheritDoc} */
40      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
41          AuthnRequest req = (AuthnRequest) samlObject;
42  
43          if (attribute.getLocalName().equals(AuthnRequest.FORCE_AUTHN_ATTRIB_NAME)) {
44              req.setForceAuthn(XSBooleanValue.valueOf(attribute.getValue()));
45          } else if (attribute.getLocalName().equals(AuthnRequest.IS_PASSIVE_ATTRIB_NAME)) {
46              req.setIsPassive(XSBooleanValue.valueOf(attribute.getValue()));
47          } else if (attribute.getLocalName().equals(AuthnRequest.PROTOCOL_BINDING_ATTRIB_NAME)) {
48              req.setProtocolBinding(attribute.getValue());
49          } else if (attribute.getLocalName().equals(AuthnRequest.ASSERTION_CONSUMER_SERVICE_INDEX_ATTRIB_NAME)) {
50              req.setAssertionConsumerServiceIndex(Integer.valueOf(attribute.getValue()));
51          } else if (attribute.getLocalName().equals(AuthnRequest.ASSERTION_CONSUMER_SERVICE_URL_ATTRIB_NAME)) {
52              req.setAssertionConsumerServiceURL(attribute.getValue());
53          } else if (attribute.getLocalName().equals(AuthnRequest.ATTRIBUTE_CONSUMING_SERVICE_INDEX_ATTRIB_NAME)) {
54              req.setAttributeConsumingServiceIndex(Integer.valueOf(attribute.getValue()));
55          } else if (attribute.getLocalName().equals(AuthnRequest.PROVIDER_NAME_ATTRIB_NAME)) {
56              req.setProviderName(attribute.getValue());
57          } else {
58              super.processAttribute(samlObject, attribute);
59          }
60      }
61  
62      /** {@inheritDoc} */
63      protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
64              throws UnmarshallingException {
65          AuthnRequest req = (AuthnRequest) parentSAMLObject;
66  
67          if (childSAMLObject instanceof Subject) {
68              req.setSubject((Subject) childSAMLObject);
69          } else if (childSAMLObject instanceof NameIDPolicy) {
70              req.setNameIDPolicy((NameIDPolicy) childSAMLObject);
71          } else if (childSAMLObject instanceof Conditions) {
72              req.setConditions((Conditions) childSAMLObject);
73          } else if (childSAMLObject instanceof RequestedAuthnContext) {
74              req.setRequestedAuthnContext((RequestedAuthnContext) childSAMLObject);
75          } else if (childSAMLObject instanceof Scoping) {
76              req.setScoping((Scoping) childSAMLObject);
77          } else {
78              super.processChildElement(parentSAMLObject, childSAMLObject);
79          }
80      }
81  }