Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit d1ddf18

Browse files
committed
Refactor of Seralizers to remove secureValidation property
git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1873101 13f79535-47bb-0310-9956-ffa450edef68
1 parent e52726c commit d1ddf18

5 files changed

Lines changed: 20 additions & 70 deletions

File tree

src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
public abstract class AbstractSerializer implements Serializer {
4141

4242
private Canonicalizer canon;
43-
protected boolean secureValidation;
4443

4544
public void setCanonicalizer(Canonicalizer canon) {
4645
this.canon = canon;
@@ -153,22 +152,6 @@ public byte[] canonSerializeToByteArray(Node node) throws Exception {
153152
}
154153
}
155154

156-
/**
157-
* @param source
158-
* @param ctx
159-
* @return the Node resulting from the parse of the source
160-
* @throws XMLEncryptionException
161-
*/
162-
public abstract Node deserialize(String source, Node ctx) throws XMLEncryptionException;
163-
164-
/**
165-
* @param source
166-
* @param ctx
167-
* @return the Node resulting from the parse of the source
168-
* @throws XMLEncryptionException
169-
*/
170-
public abstract Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException;
171-
172155
protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncryptionException {
173156
// Create the context to parse the document against
174157
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
@@ -244,12 +227,4 @@ protected static String createContext(String source, Node ctx) {
244227
return sb.toString();
245228
}
246229

247-
public boolean isSecureValidation() {
248-
return secureValidation;
249-
}
250-
251-
public void setSecureValidation(boolean secureValidation) {
252-
this.secureValidation = secureValidation;
253-
}
254-
255230
}

src/main/java/org/apache/xml/security/encryption/DocumentSerializer.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.ByteArrayInputStream;
2222
import java.io.IOException;
2323
import java.io.InputStream;
24-
import java.nio.charset.StandardCharsets;
2524

2625
import javax.xml.parsers.ParserConfigurationException;
2726

@@ -40,34 +39,25 @@ public class DocumentSerializer extends AbstractSerializer {
4039
/**
4140
* @param source
4241
* @param ctx
42+
* @param secureValidation
4343
* @return the Node resulting from the parse of the source
4444
* @throws XMLEncryptionException
4545
*/
46-
public Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException {
46+
public Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException {
4747
byte[] fragment = createContext(source, ctx);
4848
try (InputStream is = new ByteArrayInputStream(fragment)) {
49-
return deserialize(ctx, is);
49+
return deserialize(ctx, is, secureValidation);
5050
}
5151
}
5252

53-
/**
54-
* @param source
55-
* @param ctx
56-
* @return the Node resulting from the parse of the source
57-
* @throws XMLEncryptionException
58-
*/
59-
public Node deserialize(String source, Node ctx) throws XMLEncryptionException {
60-
String fragment = createContext(source, ctx);
61-
return deserialize(ctx, new ByteArrayInputStream(fragment.getBytes(StandardCharsets.UTF_8)));
62-
}
63-
6453
/**
6554
* @param ctx
6655
* @param inputStream
56+
* @param secureValidation
6757
* @return the Node resulting from the parse of the source
6858
* @throws XMLEncryptionException
6959
*/
70-
private Node deserialize(Node ctx, InputStream inputStream) throws XMLEncryptionException {
60+
private Node deserialize(Node ctx, InputStream inputStream, boolean secureValidation) throws XMLEncryptionException {
7161
try {
7262
Document d = XMLUtils.read(inputStream, secureValidation);
7363

src/main/java/org/apache/xml/security/encryption/Serializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public interface Serializer {
6868
/**
6969
* @param source
7070
* @param ctx
71+
* @param secureValidation
7172
* @return the Node resulting from the parse of the source
7273
* @throws XMLEncryptionException
7374
*/
74-
Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException;
75+
Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException;
7576
}

src/main/java/org/apache/xml/security/encryption/TransformSerializer.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.ByteArrayInputStream;
2222
import java.io.IOException;
2323
import java.io.InputStream;
24-
import java.io.StringReader;
2524

2625
import javax.xml.XMLConstants;
2726
import javax.xml.transform.Source;
@@ -45,34 +44,25 @@ public class TransformSerializer extends AbstractSerializer {
4544
/**
4645
* @param source
4746
* @param ctx
47+
* @param secureValidation
4848
* @return the Node resulting from the parse of the source
4949
* @throws XMLEncryptionException
5050
*/
51-
public Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException {
51+
public Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException {
5252
byte[] fragment = createContext(source, ctx);
5353
try (InputStream is = new ByteArrayInputStream(fragment)) {
54-
return deserialize(ctx, new StreamSource(is));
54+
return deserialize(ctx, new StreamSource(is), secureValidation);
5555
}
5656
}
5757

58-
/**
59-
* @param source
60-
* @param ctx
61-
* @return the Node resulting from the parse of the source
62-
* @throws XMLEncryptionException
63-
*/
64-
public Node deserialize(String source, Node ctx) throws XMLEncryptionException {
65-
String fragment = createContext(source, ctx);
66-
return deserialize(ctx, new StreamSource(new StringReader(fragment)));
67-
}
68-
6958
/**
7059
* @param ctx
7160
* @param source
61+
* @param secureValidation
7262
* @return the Node resulting from the parse of the source
7363
* @throws XMLEncryptionException
7464
*/
75-
private Node deserialize(Node ctx, Source source) throws XMLEncryptionException {
65+
private Node deserialize(Node ctx, Source source, boolean secureValidation) throws XMLEncryptionException {
7666
try {
7767
Document contextDocument = null;
7868
if (Node.DOCUMENT_NODE == ctx.getNodeType()) {

src/main/java/org/apache/xml/security/encryption/XMLCipher.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ public class XMLCipher {
232232
public static final int WRAP_MODE = Cipher.WRAP_MODE;
233233

234234
private static final String ENC_ALGORITHMS = TRIPLEDES + "\n" +
235-
AES_128 + "\n" + AES_256 + "\n" + AES_192 + "\n" + RSA_v1dot5 + "\n" +
236-
RSA_OAEP + "\n" + RSA_OAEP_11 + "\n" + TRIPLEDES_KeyWrap + "\n" +
237-
AES_128_KeyWrap + "\n" + AES_256_KeyWrap + "\n" + AES_192_KeyWrap + "\n" +
238-
AES_128_GCM + "\n" + AES_192_GCM + "\n" + AES_256_GCM + "\n" + SEED_128 + "\n" +
239-
CAMELLIA_128 + "\n" + CAMELLIA_192 + "\n" + CAMELLIA_256 + "\n" +
240-
CAMELLIA_128_KeyWrap + "\n" + CAMELLIA_192_KeyWrap + "\n" + CAMELLIA_256_KeyWrap + "\n" +
241-
SEED_128_KeyWrap + "\n";
235+
AES_128 + "\n" + AES_256 + "\n" + AES_192 + "\n" + RSA_v1dot5 + "\n" +
236+
RSA_OAEP + "\n" + RSA_OAEP_11 + "\n" + TRIPLEDES_KeyWrap + "\n" +
237+
AES_128_KeyWrap + "\n" + AES_256_KeyWrap + "\n" + AES_192_KeyWrap + "\n" +
238+
AES_128_GCM + "\n" + AES_192_GCM + "\n" + AES_256_GCM + "\n" + SEED_128 + "\n" +
239+
CAMELLIA_128 + "\n" + CAMELLIA_192 + "\n" + CAMELLIA_256 + "\n" +
240+
CAMELLIA_128_KeyWrap + "\n" + CAMELLIA_192_KeyWrap + "\n" + CAMELLIA_256_KeyWrap + "\n" +
241+
SEED_128_KeyWrap + "\n";
242242

243243
private static final boolean HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER = haveFunctionalIdentityTransformer();
244244

@@ -1090,9 +1090,6 @@ private EncryptedData encryptData(
10901090
if (algorithm == null) {
10911091
throw new XMLEncryptionException("empty", "XMLCipher instance without transformation specified");
10921092
}
1093-
if (serializer instanceof AbstractSerializer) {
1094-
((AbstractSerializer)serializer).setSecureValidation(secureValidation);
1095-
}
10961093
if (element != null && element.getParentNode() == null) {
10971094
throw new XMLEncryptionException("empty", "The element can't be serialized as it has no parent");
10981095
}
@@ -1655,9 +1652,6 @@ private static void removeContent(Node node) {
16551652
*/
16561653
private Document decryptElement(Element element) throws XMLEncryptionException {
16571654
LOG.debug("Decrypting element...");
1658-
if (serializer instanceof AbstractSerializer) {
1659-
((AbstractSerializer)serializer).setSecureValidation(secureValidation);
1660-
}
16611655

16621656
if (element != null && element.getParentNode() == null) {
16631657
throw new XMLEncryptionException("empty", "The element can't be serialized as it has no parent");
@@ -1675,7 +1669,7 @@ private Document decryptElement(Element element) throws XMLEncryptionException {
16751669

16761670
Node sourceParent = element.getParentNode();
16771671
try {
1678-
Node decryptedNode = serializer.deserialize(octets, sourceParent);
1672+
Node decryptedNode = serializer.deserialize(octets, sourceParent, secureValidation);
16791673

16801674
// The de-serialiser returns a node whose children we need to take on.
16811675
if (sourceParent != null && Node.DOCUMENT_NODE == sourceParent.getNodeType()) {

0 commit comments

Comments
 (0)