author | jlahoda |
Tue, 24 Sep 2019 15:40:26 +0200 | |
branch | JDK-8226585-branch |
changeset 58290 | d885633d9de4 |
parent 54731 | 81de17a33575 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1337 | 2 |
* reserved comment block |
3 |
* DO NOT REMOVE OR ALTER! |
|
2 | 4 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
7 |
* or more contributor license agreements. See the NOTICE file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
9 |
* regarding copyright ownership. The ASF licenses this file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
10 |
* to you under the Apache License, Version 2.0 (the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
11 |
* "License"); you may not use this file except in compliance |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
1337 | 13 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
1337 | 15 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
16 |
* Unless required by applicable law or agreed to in writing, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
17 |
* software distributed under the License is distributed on an |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
19 |
* KIND, either express or implied. See the License for the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
21 |
* under the License. |
1337 | 22 |
*/ |
23 |
/* |
|
54731
81de17a33575
8219013: Update Apache Santuario (XML Signature) to version 2.1.3
weijun
parents:
53998
diff
changeset
|
24 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
1337 | 25 |
*/ |
26 |
/* |
|
54731
81de17a33575
8219013: Update Apache Santuario (XML Signature) to version 2.1.3
weijun
parents:
53998
diff
changeset
|
27 |
* $Id: DOMXMLObject.java 1854026 2019-02-21 09:30:01Z coheigea $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import javax.xml.crypto.*; |
|
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
32 |
import javax.xml.crypto.dom.DOMCryptoContext; |
2 | 33 |
import javax.xml.crypto.dsig.*; |
34 |
||
1337 | 35 |
import java.security.Provider; |
2 | 36 |
import java.util.*; |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
37 |
|
18240 | 38 |
import org.w3c.dom.Attr; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
39 |
import org.w3c.dom.Document; |
2 | 40 |
import org.w3c.dom.Element; |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
41 |
import org.w3c.dom.NamedNodeMap; |
2 | 42 |
import org.w3c.dom.Node; |
43 |
||
44 |
/** |
|
45 |
* DOM-based implementation of XMLObject. |
|
46 |
* |
|
47 |
*/ |
|
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
48 |
public final class DOMXMLObject extends DOMStructure implements XMLObject { |
2 | 49 |
|
50 |
private final String id; |
|
51 |
private final String mimeType; |
|
52 |
private final String encoding; |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
53 |
private final List<XMLStructure> content; |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
54 |
private Element objectElem; |
2 | 55 |
|
56 |
/** |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
57 |
* Creates an {@code XMLObject} from the specified parameters. |
2 | 58 |
* |
59 |
* @param content a list of {@link XMLStructure}s. The list |
|
60 |
* is defensively copied to protect against subsequent modification. |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
61 |
* May be {@code null} or empty. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
62 |
* @param id the Id (may be {@code null}) |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
63 |
* @param mimeType the mime type (may be {@code null}) |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
64 |
* @param encoding the encoding (may be {@code null}) |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
65 |
* @throws ClassCastException if {@code content} contains any |
2 | 66 |
* entries that are not of type {@link XMLStructure} |
67 |
*/ |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
68 |
public DOMXMLObject(List<? extends XMLStructure> content, String id, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
69 |
String mimeType, String encoding) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
70 |
{ |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
71 |
if (content == null || content.isEmpty()) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
72 |
this.content = Collections.emptyList(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
73 |
} else { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
74 |
this.content = Collections.unmodifiableList( |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
75 |
new ArrayList<>(content)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
76 |
for (int i = 0, size = this.content.size(); i < size; i++) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
77 |
if (!(this.content.get(i) instanceof XMLStructure)) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
78 |
throw new ClassCastException |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
79 |
("content["+i+"] is not a valid type"); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
80 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
81 |
} |
2 | 82 |
} |
83 |
this.id = id; |
|
84 |
this.mimeType = mimeType; |
|
85 |
this.encoding = encoding; |
|
86 |
} |
|
87 |
||
88 |
/** |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
89 |
* Creates an {@code XMLObject} from an element. |
2 | 90 |
* |
91 |
* @param objElem an Object element |
|
92 |
* @throws MarshalException if there is an error when unmarshalling |
|
93 |
*/ |
|
1337 | 94 |
public DOMXMLObject(Element objElem, XMLCryptoContext context, |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
95 |
Provider provider) |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
96 |
throws MarshalException |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
97 |
{ |
2 | 98 |
// unmarshal attributes |
99 |
this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding"); |
|
18240 | 100 |
|
101 |
Attr attr = objElem.getAttributeNodeNS(null, "Id"); |
|
102 |
if (attr != null) { |
|
103 |
this.id = attr.getValue(); |
|
104 |
objElem.setIdAttributeNode(attr, true); |
|
105 |
} else { |
|
106 |
this.id = null; |
|
107 |
} |
|
2 | 108 |
this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType"); |
109 |
||
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
110 |
List<XMLStructure> newContent = new ArrayList<>(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
111 |
Node firstChild = objElem.getFirstChild(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
112 |
while (firstChild != null) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
113 |
if (firstChild.getNodeType() == Node.ELEMENT_NODE) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
114 |
Element childElem = (Element)firstChild; |
2 | 115 |
String tag = childElem.getLocalName(); |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
116 |
String namespace = childElem.getNamespaceURI(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
117 |
if ("Manifest".equals(tag) && XMLSignature.XMLNS.equals(namespace)) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
118 |
newContent.add(new DOMManifest(childElem, context, provider)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
119 |
} else if ("SignatureProperties".equals(tag) && XMLSignature.XMLNS.equals(namespace)) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
120 |
newContent.add(new DOMSignatureProperties(childElem)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
121 |
} else if ("X509Data".equals(tag) && XMLSignature.XMLNS.equals(namespace)) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
122 |
newContent.add(new DOMX509Data(childElem)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
123 |
} else { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
124 |
//@@@FIXME: check for other dsig structures |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
125 |
newContent.add(new javax.xml.crypto.dom.DOMStructure(firstChild)); |
2 | 126 |
} |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
127 |
} else { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
128 |
newContent.add(new javax.xml.crypto.dom.DOMStructure(firstChild)); |
2 | 129 |
} |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
130 |
firstChild = firstChild.getNextSibling(); |
2 | 131 |
} |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
132 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
133 |
// Here we capture namespace declarations, so that when they're marshalled back |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
134 |
// out, we can make copies of them. Note that attributes are NOT captured. |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
135 |
NamedNodeMap nnm = objElem.getAttributes(); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
136 |
for (int idx = 0 ; idx < nnm.getLength() ; idx++) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
137 |
Node nsDecl = nnm.item(idx); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
138 |
if (DOMUtils.isNamespace(nsDecl)) { |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
139 |
newContent.add(new javax.xml.crypto.dom.DOMStructure(nsDecl)); |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
140 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
141 |
} |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
142 |
|
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
143 |
if (newContent.isEmpty()) { |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
144 |
this.content = Collections.emptyList(); |
2 | 145 |
} else { |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
146 |
this.content = Collections.unmodifiableList(newContent); |
2 | 147 |
} |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
148 |
this.objectElem = objElem; |
2 | 149 |
} |
150 |
||
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
151 |
public List<XMLStructure> getContent() { |
2 | 152 |
return content; |
153 |
} |
|
154 |
||
155 |
public String getId() { |
|
156 |
return id; |
|
157 |
} |
|
158 |
||
159 |
public String getMimeType() { |
|
160 |
return mimeType; |
|
161 |
} |
|
162 |
||
163 |
public String getEncoding() { |
|
164 |
return encoding; |
|
165 |
} |
|
166 |
||
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
167 |
@Override |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
168 |
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) |
2 | 169 |
throws MarshalException { |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
170 |
Document ownerDoc = DOMUtils.getOwnerDocument(parent); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
171 |
|
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
172 |
Element objElem = objectElem != null ? objectElem : null; |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
173 |
if (objElem == null) { |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
174 |
objElem = DOMUtils.createElement(ownerDoc, "Object", |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
175 |
XMLSignature.XMLNS, dsPrefix); |
2 | 176 |
|
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
177 |
// set attributes |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
178 |
DOMUtils.setAttributeID(objElem, "Id", id); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
179 |
DOMUtils.setAttribute(objElem, "MimeType", mimeType); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
180 |
DOMUtils.setAttribute(objElem, "Encoding", encoding); |
2 | 181 |
|
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
182 |
// create and append any elements and mixed content, if necessary |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
183 |
for (XMLStructure object : content) { |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
184 |
if (object instanceof DOMStructure) { |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
185 |
((DOMStructure)object).marshal(objElem, dsPrefix, context); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
186 |
} else { |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
187 |
javax.xml.crypto.dom.DOMStructure domObject = |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
188 |
(javax.xml.crypto.dom.DOMStructure)object; |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
189 |
DOMUtils.appendChild(objElem, domObject.getNode()); |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
190 |
} |
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
191 |
} |
2 | 192 |
} |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
193 |
|
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
194 |
parent.appendChild(objElem); |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
195 |
} |
2 | 196 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
197 |
@SuppressWarnings("unchecked") |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
198 |
@Override |
2 | 199 |
public boolean equals(Object o) { |
200 |
if (this == o) { |
|
201 |
return true; |
|
202 |
} |
|
203 |
||
204 |
if (!(o instanceof XMLObject)) { |
|
205 |
return false; |
|
206 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
207 |
XMLObject oxo = (XMLObject)o; |
2 | 208 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
209 |
boolean idsEqual = id == null ? oxo.getId() == null |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
210 |
: id.equals(oxo.getId()); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
211 |
boolean encodingsEqual = |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
212 |
encoding == null ? oxo.getEncoding() == null |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
213 |
: encoding.equals(oxo.getEncoding()); |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
214 |
boolean mimeTypesEqual = |
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
215 |
mimeType == null ? oxo.getMimeType() == null |
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
216 |
: mimeType.equals(oxo.getMimeType()); |
2 | 217 |
|
50614
3810c9a2efa1
8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents:
47216
diff
changeset
|
218 |
return idsEqual && encodingsEqual && mimeTypesEqual && |
53998
d870bb08194a
8217878: ENVELOPING XML signature no longer works in JDK 11
mullan
parents:
50614
diff
changeset
|
219 |
equalsContent(oxo.getContent()); |
2 | 220 |
} |
221 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
222 |
@Override |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
223 |
public int hashCode() { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
224 |
int result = 17; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
225 |
if (id != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
226 |
result = 31 * result + id.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
227 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
228 |
if (encoding != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
229 |
result = 31 * result + encoding.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
230 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
231 |
if (mimeType != null) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
232 |
result = 31 * result + mimeType.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
233 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
234 |
result = 31 * result + content.hashCode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
235 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
236 |
return result; |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
237 |
} |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
238 |
|
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
239 |
private boolean equalsContent(List<XMLStructure> otherContent) { |
2 | 240 |
if (content.size() != otherContent.size()) { |
241 |
return false; |
|
242 |
} |
|
243 |
for (int i = 0, osize = otherContent.size(); i < osize; i++) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
244 |
XMLStructure oxs = otherContent.get(i); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
245 |
XMLStructure xs = content.get(i); |
2 | 246 |
if (oxs instanceof javax.xml.crypto.dom.DOMStructure) { |
247 |
if (!(xs instanceof javax.xml.crypto.dom.DOMStructure)) { |
|
248 |
return false; |
|
249 |
} |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
250 |
Node onode = ((javax.xml.crypto.dom.DOMStructure)oxs).getNode(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18240
diff
changeset
|
251 |
Node node = ((javax.xml.crypto.dom.DOMStructure)xs).getNode(); |
2 | 252 |
if (!DOMUtils.nodesEqual(node, onode)) { |
253 |
return false; |
|
254 |
} |
|
255 |
} else { |
|
256 |
if (!(xs.equals(oxs))) { |
|
257 |
return false; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
return true; |
|
263 |
} |
|
264 |
} |