1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package dk.sosi.seal.model.dombuilders;
30
31 import dk.sosi.seal.model.Reply;
32 import dk.sosi.seal.model.constants.MedComTags;
33 import dk.sosi.seal.model.constants.NameSpaces;
34 import dk.sosi.seal.model.constants.SOAPTags;
35 import dk.sosi.seal.vault.CredentialVault;
36 import org.w3c.dom.Document;
37 import org.w3c.dom.Element;
38
39
40
41
42
43
44
45
46
47
48 public class SAMLReplyDOMBuilder extends SOAPMessageDOMBuilder {
49
50 protected SAMLUtil samlUtil = new SAMLUtil();
51
52
53
54
55
56
57
58
59
60
61
62 public SAMLReplyDOMBuilder(Document document, Reply reply, CredentialVault vault) {
63
64 super(document, reply, vault);
65 }
66
67
68
69
70 protected void _buildDOMDocument(Document document, Element header, Element body) {
71
72 Reply reply = (Reply) getMessage();
73
74
75 Element wssSecurity = samlUtil.createSecurityHeader(document, header, reply);
76
77 if (reply.getIDCard() != null) {
78 wssSecurity.appendChild(reply.getIDCard().serialize2DOMDocument(reply.getFactory(), document));
79 }
80
81 Element medComHeader = samlUtil.createMedcomHeader(document, header);
82
83
84 if (reply.getIDCard() != null) {
85 samlUtil.createSecurityLevel(document, medComHeader, reply.getIDCard().getAuthenticationLevel().getLevel());
86 } else {
87 samlUtil.createSecurityLevel(document, medComHeader, 1);
88 }
89 Element medcomLinking = samlUtil.createMedcomLinking(document, medComHeader, reply);
90 Element inResponseToMessageID = (Element) medcomLinking.appendChild(document.createElementNS(
91 NameSpaces.MEDCOM_SCHEMA,
92 MedComTags.IN_RESPONSE_TO_MESSAGE_ID_PREFIXED));
93 inResponseToMessageID.appendChild(document.createTextNode(reply.getRequestID()));
94
95
96 if (reply.isFault()) {
97 Element soapFault = document.createElementNS(NameSpaces.SOAP_SCHEMA, SOAPTags.FAULT_PREFIXED);
98
99 Element faultcode = document.createElement(SOAPTags.FAULTCODE);
100 faultcode.appendChild(document.createTextNode("Server"));
101 soapFault.appendChild(faultcode);
102
103 Element detail = document.createElement(SOAPTags.DETAIL);
104 Element medcomFaultCode = document.createElementNS(NameSpaces.MEDCOM_SCHEMA, MedComTags.FAULT_CODE_PREFIXED);
105 medcomFaultCode.appendChild(document.createTextNode(reply.getFaultCode()));
106 detail.appendChild(medcomFaultCode);
107 soapFault.appendChild(detail);
108
109 Element faultstring = document.createElement(SOAPTags.FAULTSTRING);
110 faultstring.appendChild(document.createTextNode(reply.getFaultString()));
111 soapFault.appendChild(faultstring);
112
113 body.appendChild(soapFault);
114 } else {
115 Element flowStatus = document.createElementNS(NameSpaces.MEDCOM_SCHEMA, MedComTags.FLOW_STATUS_PREFIXED);
116 flowStatus.appendChild(document.createTextNode(reply.getFlowStatus()));
117 medComHeader.appendChild(flowStatus);
118 }
119 }
120 }