1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.saml1.core.impl;
18
19 import org.joda.time.DateTime;
20 import org.joda.time.chrono.ISOChronology;
21 import org.opensaml.common.SAMLVersion;
22 import org.opensaml.common.impl.AbstractSAMLObjectUnmarshaller;
23 import org.opensaml.saml1.core.Advice;
24 import org.opensaml.saml1.core.Assertion;
25 import org.opensaml.saml1.core.Conditions;
26 import org.opensaml.saml1.core.Statement;
27 import org.opensaml.xml.XMLObject;
28 import org.opensaml.xml.io.UnmarshallingException;
29 import org.opensaml.xml.signature.Signature;
30 import org.opensaml.xml.util.DatatypeHelper;
31 import org.w3c.dom.Attr;
32 import org.w3c.dom.Element;
33
34
35
36
37 public class AssertionUnmarshaller extends AbstractSAMLObjectUnmarshaller {
38
39
40 public XMLObject unmarshall(Element domElement) throws UnmarshallingException {
41
42 Assertion assertion = (Assertion) super.unmarshall(domElement);
43 if (assertion.getMinorVersion() != 0 && !DatatypeHelper.isEmpty(assertion.getID())) {
44 domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true);
45 }
46 return assertion;
47 }
48
49
50 protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
51 throws UnmarshallingException {
52
53 Assertion assertion = (Assertion) parentSAMLObject;
54
55 if (childSAMLObject instanceof Signature) {
56 assertion.setSignature((Signature) childSAMLObject);
57 } else if (childSAMLObject instanceof Conditions) {
58 assertion.setConditions((Conditions) childSAMLObject);
59 } else if (childSAMLObject instanceof Advice) {
60 assertion.setAdvice((Advice) childSAMLObject);
61 } else if (childSAMLObject instanceof Statement) {
62 assertion.getStatements().add((Statement) childSAMLObject);
63 } else {
64 super.processChildElement(parentSAMLObject, childSAMLObject);
65 }
66 }
67
68
69 protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
70
71 Assertion assertion = (Assertion) samlObject;
72
73 if (Assertion.ID_ATTRIB_NAME.equals(attribute.getLocalName())) {
74 assertion.setID(attribute.getValue());
75 } else if (Assertion.ISSUER_ATTRIB_NAME.equals(attribute.getLocalName())) {
76 assertion.setIssuer(attribute.getValue());
77 } else if (Assertion.ISSUEINSTANT_ATTRIB_NAME.equals(attribute.getLocalName())
78 && !DatatypeHelper.isEmpty(attribute.getValue())) {
79 assertion.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
80 } else if (Assertion.MINORVERSION_ATTRIB_NAME.equals(attribute.getLocalName())) {
81 if (attribute.getValue().equals("0")) {
82 assertion.setVersion(SAMLVersion.VERSION_10);
83 } else {
84 assertion.setVersion(SAMLVersion.VERSION_11);
85 }
86 } else {
87 super.processAttribute(samlObject, attribute);
88 }
89 }
90
91 }