1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.wss4j.dom.message.token;
21
22 import java.util.Arrays;
23
24 import org.apache.wss4j.dom.WSConstants;
25 import org.apache.wss4j.common.bsp.BSPEnforcer;
26 import org.apache.wss4j.common.bsp.BSPRule;
27 import org.apache.wss4j.common.ext.WSSecurityException;
28 import org.apache.wss4j.common.util.DOM2Writer;
29 import org.apache.wss4j.common.util.XMLUtils;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32
33
34
35
36
37 public class SignatureConfirmation {
38
39 public static final String SC_VALUE_ATTR = "Value";
40 private Element element;
41 private byte[] signatureValue;
42
43
44
45
46
47
48
49
50
51 public SignatureConfirmation(Element elem, BSPEnforcer bspEnforcer) throws WSSecurityException {
52 element = elem;
53
54 String id = getID();
55 if (id == null || id.length() == 0) {
56 bspEnforcer.handleBSPRule(BSPRule.R5441);
57 }
58
59 String sv = element.getAttributeNS(null, SC_VALUE_ATTR);
60 if (sv != null) {
61 signatureValue = org.apache.xml.security.utils.XMLUtils.decode(sv);
62 }
63 }
64
65
66
67
68
69
70
71
72
73 public SignatureConfirmation(Document doc, byte[] signVal) {
74 element =
75 doc.createElementNS(
76 WSConstants.WSSE11_NS,
77 WSConstants.WSSE11_PREFIX + ":" + WSConstants.SIGNATURE_CONFIRMATION_LN
78 );
79 XMLUtils.setNamespace(element, WSConstants.WSSE11_NS, WSConstants.WSSE11_PREFIX);
80 if (signVal != null) {
81 String sv = org.apache.xml.security.utils.XMLUtils.encodeToString(signVal);
82 element.setAttributeNS(null, SC_VALUE_ATTR, sv);
83 }
84 }
85
86
87
88
89
90 public void addWSUNamespace() {
91 element.setAttributeNS(XMLUtils.XMLNS_NS, "xmlns:" + WSConstants.WSU_PREFIX, WSConstants.WSU_NS);
92 }
93
94
95
96
97
98
99 public Element getElement() {
100 return element;
101 }
102
103
104
105
106
107
108 public String toString() {
109 return DOM2Writer.nodeToString(element);
110 }
111
112
113
114
115
116 public void setID(String id) {
117 element.setAttributeNS(WSConstants.WSU_NS, WSConstants.WSU_PREFIX + ":Id", id);
118 }
119
120
121
122
123
124 public String getID() {
125 return element.getAttributeNS(WSConstants.WSU_NS, "Id");
126 }
127
128
129
130
131 public byte[] getSignatureValue() {
132 return signatureValue;
133 }
134
135 @Override
136 public int hashCode() {
137 int result = 17;
138 if (signatureValue != null) {
139 result = 31 * result + Arrays.hashCode(signatureValue);
140 }
141 return result;
142 }
143
144 @Override
145 public boolean equals(Object object) {
146 if (!(object instanceof SignatureConfirmation)) {
147 return false;
148 }
149 SignatureConfirmation signatureConfirmation = (SignatureConfirmation)object;
150 byte[] sigValue = signatureConfirmation.getSignatureValue();
151 return Arrays.equals(sigValue, getSignatureValue());
152 }
153
154 }