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.joda.time.DateTime;
24  import org.joda.time.chrono.ISOChronology;
25  import org.opensaml.common.SAMLVersion;
26  import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
27  import org.opensaml.saml2.core.Advice;
28  import org.opensaml.saml2.core.Assertion;
29  import org.opensaml.saml2.core.Conditions;
30  import org.opensaml.saml2.core.Issuer;
31  import org.opensaml.saml2.core.Statement;
32  import org.opensaml.saml2.core.Subject;
33  import org.opensaml.xml.XMLObject;
34  import org.opensaml.xml.io.UnmarshallingException;
35  import org.opensaml.xml.signature.Signature;
36  import org.opensaml.xml.util.DatatypeHelper;
37  import org.w3c.dom.Attr;
38  
39  /**
40   * A thread-safe Unmarshaller for {@link org.opensaml.saml2.core.Assertion}.
41   */
42  public class AssertionUnmarshaller extends AbstractSAMLObjectUnmarshaller {
43  
44      /** {@inheritDoc} */
45      protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
46          Assertion assertion = (Assertion) parentObject;
47  
48          if (childObject instanceof Issuer) {
49              assertion.setIssuer((Issuer) childObject);
50          } else if (childObject instanceof Signature) {
51              assertion.setSignature((Signature) childObject);
52          } else if (childObject instanceof Subject) {
53              assertion.setSubject((Subject) childObject);
54          } else if (childObject instanceof Conditions) {
55              assertion.setConditions((Conditions) childObject);
56          } else if (childObject instanceof Advice) {
57              assertion.setAdvice((Advice) childObject);
58          } else if (childObject instanceof Statement) {
59              assertion.getStatements().add((Statement) childObject);
60          } else {
61              super.processChildElement(parentObject, childObject);
62          }
63      }
64  
65      /** {@inheritDoc} */
66      protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
67          Assertion assertion = (Assertion) samlObject;
68  
69          if (attribute.getLocalName().equals(Assertion.VERSION_ATTRIB_NAME)) {
70              assertion.setVersion(SAMLVersion.valueOf(attribute.getValue()));
71          } else if (attribute.getLocalName().equals(Assertion.ISSUE_INSTANT_ATTRIB_NAME)
72                  && !DatatypeHelper.isEmpty(attribute.getValue())) {
73              assertion.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
74          } else if (attribute.getLocalName().equals(Assertion.ID_ATTRIB_NAME)) {
75              assertion.setID(attribute.getValue());
76              attribute.getOwnerElement().setIdAttributeNode(attribute, true);
77          } else {
78              super.processAttribute(samlObject, attribute);
79          }
80      }
81  }