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.RequestAbstractType;
28 import org.opensaml.saml1.core.RespondWith;
29 import org.opensaml.xml.XMLObject;
30 import org.opensaml.xml.io.UnmarshallingException;
31 import org.opensaml.xml.signature.Signature;
32 import org.opensaml.xml.util.DatatypeHelper;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.w3c.dom.Attr;
36 import org.w3c.dom.Element;
37
38
39
40
41 public abstract class RequestAbstractTypeUnmarshaller extends AbstractSAMLObjectUnmarshaller {
42
43
44 private final Logger log = LoggerFactory.getLogger(RequestAbstractType.class);
45
46
47 public XMLObject unmarshall(Element domElement) throws UnmarshallingException {
48
49 RequestAbstractType request = (RequestAbstractType) super.unmarshall(domElement);
50 if (request.getMinorVersion() != 0 && !DatatypeHelper.isEmpty(request.getID())) {
51 domElement.setIdAttributeNS(null, RequestAbstractType.ID_ATTRIB_NAME, true);
52 }
53 return request;
54 }
55
56
57 protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
58 throws UnmarshallingException {
59 RequestAbstractType request = (RequestAbstractType) parentSAMLObject;
60
61 if (childSAMLObject instanceof Signature) {
62 request.setSignature((Signature) childSAMLObject);
63 } else if (childSAMLObject instanceof RespondWith) {
64 request.getRespondWiths().add((RespondWith) childSAMLObject);
65 } else {
66 super.processChildElement(parentSAMLObject, childSAMLObject);
67 }
68 }
69
70
71 protected void processAttribute(XMLObject samlElement, Attr attribute) throws UnmarshallingException {
72 RequestAbstractType request = (RequestAbstractType) samlElement;
73
74 if (RequestAbstractType.ID_ATTRIB_NAME.equals(attribute.getLocalName())) {
75 request.setID(attribute.getValue());
76 } else if (RequestAbstractType.ISSUEINSTANT_ATTRIB_NAME.equals(attribute.getLocalName())
77 && !DatatypeHelper.isEmpty(attribute.getValue())) {
78 DateTime cal = new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC());
79 request.setIssueInstant(cal);
80 } else if (RequestAbstractType.MINORVERSION_ATTRIB_NAME.equals(attribute.getLocalName())) {
81 int minor;
82 try {
83 minor = Integer.parseInt(attribute.getValue());
84 } catch (NumberFormatException n) {
85 log.error("Unable to parse minor version string", n);
86 throw new UnmarshallingException(n);
87 }
88 if (minor == 0) {
89 request.setVersion(SAMLVersion.VERSION_10);
90 } else if (minor == 1) {
91 request.setVersion(SAMLVersion.VERSION_11);
92 }
93 } else {
94 super.processAttribute(samlElement, attribute);
95 }
96 }
97
98 }