1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opensaml.saml1.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.saml1.core.ResponseAbstractType;
28 import org.opensaml.xml.XMLObject;
29 import org.opensaml.xml.io.UnmarshallingException;
30 import org.opensaml.xml.signature.Signature;
31 import org.opensaml.xml.util.DatatypeHelper;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.w3c.dom.Attr;
35 import org.w3c.dom.Element;
36
37
38
39
40
41 public abstract class ResponseAbstractTypeUnmarshaller extends AbstractSAMLObjectUnmarshaller {
42
43
44 private final Logger log = LoggerFactory.getLogger(ResponseUnmarshaller.class);
45
46
47 public XMLObject unmarshall(Element domElement) throws UnmarshallingException {
48
49 ResponseAbstractType response = (ResponseAbstractType) super.unmarshall(domElement);
50 if (response.getMinorVersion() != 0 && !DatatypeHelper.isEmpty(response.getID())) {
51 domElement.setIdAttributeNS(null, ResponseAbstractType.ID_ATTRIB_NAME, true);
52 }
53 return response;
54 }
55
56
57 protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
58 throws UnmarshallingException {
59 ResponseAbstractType response = (ResponseAbstractType) parentSAMLObject;
60
61 if (childSAMLObject instanceof Signature) {
62 response.setSignature((Signature) childSAMLObject);
63 } else {
64 super.processChildElement(parentSAMLObject, childSAMLObject);
65 }
66 }
67
68
69 protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {
70 ResponseAbstractType response = (ResponseAbstractType) samlObject;
71
72 if (attribute.getLocalName().equals(ResponseAbstractType.ID_ATTRIB_NAME)) {
73 response.setID(attribute.getValue());
74 } else if (attribute.getLocalName().equals(ResponseAbstractType.INRESPONSETO_ATTRIB_NAME)) {
75 response.setInResponseTo(attribute.getValue());
76 } else if (attribute.getLocalName().equals(ResponseAbstractType.ISSUEINSTANT_ATTRIB_NAME)
77 && !DatatypeHelper.isEmpty(attribute.getValue())) {
78 response.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
79 } else if (attribute.getLocalName().equals(ResponseAbstractType.MINORVERSION_ATTRIB_NAME)) {
80 int minor;
81 try {
82 minor = Integer.parseInt(attribute.getValue());
83 } catch (NumberFormatException n) {
84 log.error("Parsing minor version ", n);
85 throw new UnmarshallingException(n);
86 }
87 if (minor == 0) {
88 response.setVersion(SAMLVersion.VERSION_10);
89 } else if (minor == 1) {
90 response.setVersion(SAMLVersion.VERSION_11);
91 }
92 } else if (attribute.getLocalName().equals(ResponseAbstractType.RECIPIENT_ATTRIB_NAME)) {
93 response.setRecipient(attribute.getValue());
94 } else {
95 super.processAttribute(samlObject, attribute);
96 }
97 }
98
99 }