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.IDCard;
32 import dk.sosi.seal.model.ModelException;
33 import dk.sosi.seal.model.constants.NameSpaces;
34 import org.w3c.dom.Document;
35 import org.w3c.dom.Element;
36
37
38
39
40
41
42
43
44 public class WSTrustUtil {
45
46 public static final String VERSION = "2.0";
47 private static final String urn = "urn:oasis:names:tc:SAML:2.0:assertion:";
48 private static final String Issue = "http://schemas.xmlsoap.org/ws/2005/02/trust/Issue";
49 private static final String Valid = "http://schemas.xmlsoap.org/ws/2005/02/trust/status/valid";
50
51 public Element createSecurityTokenRequest(Document document, IDCard idCard) {
52
53 if (idCard == null) throw new ModelException("No IDCard present in SecurityTokenRequest");
54
55 Element elmWsTrust = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":RequestSecurityToken");
56 elmWsTrust.setAttribute("Context", "www.sosi.dk");
57
58 Element elmRequestType = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":TokenType");
59 elmRequestType.appendChild(document.createTextNode(urn));
60 elmWsTrust.appendChild(elmRequestType);
61
62 Element elmTokenType = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":RequestType");
63 elmTokenType.appendChild(document.createTextNode(Issue));
64 elmWsTrust.appendChild(elmTokenType);
65
66
67 Element elmClaims = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":Claims");
68
69 elmClaims.appendChild(idCard.serialize2DOMDocument(null, document));
70 elmWsTrust.appendChild(elmClaims);
71
72 Element elmIssuer = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":Issuer");
73 Element elmAddress = document.createElementNS(NameSpaces.WSA_SCHEMA, NameSpaces.NS_WSA + ":Address");
74 elmAddress.appendChild(document.createTextNode(idCard.getIssuer()));
75 elmIssuer.appendChild(elmAddress);
76 elmWsTrust.appendChild(elmIssuer);
77
78 return elmWsTrust;
79
80 }
81
82 public Element createSecurityTokenResponse(Document document, IDCard idCard) {
83
84 if (idCard == null) throw new ModelException("No idCard present in SecurityTokenResponse");
85
86 Element elmWsTrust = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":RequestSecurityTokenResponse");
87 elmWsTrust.setAttribute("Context", "www.sosi.dk");
88
89 Element elmTokenType = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":TokenType");
90 elmTokenType.appendChild(document.createTextNode(urn));
91 elmWsTrust.appendChild(elmTokenType);
92
93 Element elmRequestedSecurityTokens = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":RequestedSecurityToken");
94
95 elmRequestedSecurityTokens.appendChild(idCard.serialize2DOMDocument(null,document));
96 elmWsTrust.appendChild(elmRequestedSecurityTokens);
97
98 Element elmStatus = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":Status");
99 Element elmStatusCode = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":Code");
100 elmStatusCode.appendChild(document.createTextNode(Valid));
101 elmStatus.appendChild(elmStatusCode);
102 elmWsTrust.appendChild(elmStatus);
103
104 Element elmIssuer = document.createElementNS(NameSpaces.WST_SCHEMA, NameSpaces.NS_WST + ":Issuer");
105 Element elmAddress = document.createElementNS(NameSpaces.WSA_SCHEMA, NameSpaces.NS_WSA + ":Address");
106 elmAddress.appendChild(document.createTextNode(idCard.getIssuer()));
107 elmIssuer.appendChild(elmAddress);
108 elmWsTrust.appendChild(elmIssuer);
109
110 return elmWsTrust;
111
112 }
113
114 }