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
diff --git a/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java b/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java
index f598377..3254fa5 100644
--- a/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java
+++ b/src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java
@@ -40,7 +40,6 @@
public abstract class AbstractSerializer implements Serializer {
private Canonicalizer canon;
- protected boolean secureValidation;
public void setCanonicalizer(Canonicalizer canon) {
this.canon = canon;
@@ -153,22 +152,6 @@
}
}
- /**
- * @param source
- * @param ctx
- * @return the Node resulting from the parse of the source
- * @throws XMLEncryptionException
- */
- public abstract Node deserialize(String source, Node ctx) throws XMLEncryptionException;
-
- /**
- * @param source
- * @param ctx
- * @return the Node resulting from the parse of the source
- * @throws XMLEncryptionException
- */
- public abstract Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException;
-
protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncryptionException {
// Create the context to parse the document against
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
@@ -244,12 +227,4 @@
return sb.toString();
}
- public boolean isSecureValidation() {
- return secureValidation;
- }
-
- public void setSecureValidation(boolean secureValidation) {
- this.secureValidation = secureValidation;
- }
-
}
diff --git a/src/main/java/org/apache/xml/security/encryption/DocumentSerializer.java b/src/main/java/org/apache/xml/security/encryption/DocumentSerializer.java
index 0991e4d..408a523 100644
--- a/src/main/java/org/apache/xml/security/encryption/DocumentSerializer.java
+++ b/src/main/java/org/apache/xml/security/encryption/DocumentSerializer.java
@@ -21,7 +21,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import javax.xml.parsers.ParserConfigurationException;
@@ -40,34 +39,25 @@
/**
* @param source
* @param ctx
+ * @param secureValidation
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
- public Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException {
+ public Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException {
byte[] fragment = createContext(source, ctx);
try (InputStream is = new ByteArrayInputStream(fragment)) {
- return deserialize(ctx, is);
+ return deserialize(ctx, is, secureValidation);
}
}
/**
- * @param source
- * @param ctx
- * @return the Node resulting from the parse of the source
- * @throws XMLEncryptionException
- */
- public Node deserialize(String source, Node ctx) throws XMLEncryptionException {
- String fragment = createContext(source, ctx);
- return deserialize(ctx, new ByteArrayInputStream(fragment.getBytes(StandardCharsets.UTF_8)));
- }
-
- /**
* @param ctx
* @param inputStream
+ * @param secureValidation
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
- private Node deserialize(Node ctx, InputStream inputStream) throws XMLEncryptionException {
+ private Node deserialize(Node ctx, InputStream inputStream, boolean secureValidation) throws XMLEncryptionException {
try {
Document d = XMLUtils.read(inputStream, secureValidation);
diff --git a/src/main/java/org/apache/xml/security/encryption/Serializer.java b/src/main/java/org/apache/xml/security/encryption/Serializer.java
index 94d9277..4b20a0f 100644
--- a/src/main/java/org/apache/xml/security/encryption/Serializer.java
+++ b/src/main/java/org/apache/xml/security/encryption/Serializer.java
@@ -68,8 +68,9 @@
/**
* @param source
* @param ctx
+ * @param secureValidation
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
- Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException;
+ Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException;
}
diff --git a/src/main/java/org/apache/xml/security/encryption/TransformSerializer.java b/src/main/java/org/apache/xml/security/encryption/TransformSerializer.java
index 8254653..4efb57b 100644
--- a/src/main/java/org/apache/xml/security/encryption/TransformSerializer.java
+++ b/src/main/java/org/apache/xml/security/encryption/TransformSerializer.java
@@ -21,7 +21,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.StringReader;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
@@ -45,34 +44,25 @@
/**
* @param source
* @param ctx
+ * @param secureValidation
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
- public Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException, IOException {
+ public Node deserialize(byte[] source, Node ctx, boolean secureValidation) throws XMLEncryptionException, IOException {
byte[] fragment = createContext(source, ctx);
try (InputStream is = new ByteArrayInputStream(fragment)) {
- return deserialize(ctx, new StreamSource(is));
+ return deserialize(ctx, new StreamSource(is), secureValidation);
}
}
/**
- * @param source
* @param ctx
+ * @param source
+ * @param secureValidation
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
- public Node deserialize(String source, Node ctx) throws XMLEncryptionException {
- String fragment = createContext(source, ctx);
- return deserialize(ctx, new StreamSource(new StringReader(fragment)));
- }
-
- /**
- * @param ctx
- * @param source
- * @return the Node resulting from the parse of the source
- * @throws XMLEncryptionException
- */
- private Node deserialize(Node ctx, Source source) throws XMLEncryptionException {
+ private Node deserialize(Node ctx, Source source, boolean secureValidation) throws XMLEncryptionException {
try {
Document contextDocument = null;
if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
diff --git a/src/main/java/org/apache/xml/security/encryption/XMLCipher.java b/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
index 11a4a79..063f0d7 100644
--- a/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
+++ b/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
@@ -232,13 +232,13 @@
public static final int WRAP_MODE = Cipher.WRAP_MODE;
private static final String ENC_ALGORITHMS = TRIPLEDES + "\n" +
- AES_128 + "\n" + AES_256 + "\n" + AES_192 + "\n" + RSA_v1dot5 + "\n" +
- RSA_OAEP + "\n" + RSA_OAEP_11 + "\n" + TRIPLEDES_KeyWrap + "\n" +
- AES_128_KeyWrap + "\n" + AES_256_KeyWrap + "\n" + AES_192_KeyWrap + "\n" +
- AES_128_GCM + "\n" + AES_192_GCM + "\n" + AES_256_GCM + "\n" + SEED_128 + "\n" +
- CAMELLIA_128 + "\n" + CAMELLIA_192 + "\n" + CAMELLIA_256 + "\n" +
- CAMELLIA_128_KeyWrap + "\n" + CAMELLIA_192_KeyWrap + "\n" + CAMELLIA_256_KeyWrap + "\n" +
- SEED_128_KeyWrap + "\n";
+ AES_128 + "\n" + AES_256 + "\n" + AES_192 + "\n" + RSA_v1dot5 + "\n" +
+ RSA_OAEP + "\n" + RSA_OAEP_11 + "\n" + TRIPLEDES_KeyWrap + "\n" +
+ AES_128_KeyWrap + "\n" + AES_256_KeyWrap + "\n" + AES_192_KeyWrap + "\n" +
+ AES_128_GCM + "\n" + AES_192_GCM + "\n" + AES_256_GCM + "\n" + SEED_128 + "\n" +
+ CAMELLIA_128 + "\n" + CAMELLIA_192 + "\n" + CAMELLIA_256 + "\n" +
+ CAMELLIA_128_KeyWrap + "\n" + CAMELLIA_192_KeyWrap + "\n" + CAMELLIA_256_KeyWrap + "\n" +
+ SEED_128_KeyWrap + "\n";
private static final boolean HAVE_FUNCTIONAL_IDENTITY_TRANSFORMER = haveFunctionalIdentityTransformer();
@@ -1090,9 +1090,6 @@
if (algorithm == null) {
throw new XMLEncryptionException("empty", "XMLCipher instance without transformation specified");
}
- if (serializer instanceof AbstractSerializer) {
- ((AbstractSerializer)serializer).setSecureValidation(secureValidation);
- }
if (element != null && element.getParentNode() == null) {
throw new XMLEncryptionException("empty", "The element can't be serialized as it has no parent");
}
@@ -1655,9 +1652,6 @@
*/
private Document decryptElement(Element element) throws XMLEncryptionException {
LOG.debug("Decrypting element...");
- if (serializer instanceof AbstractSerializer) {
- ((AbstractSerializer)serializer).setSecureValidation(secureValidation);
- }
if (element != null && element.getParentNode() == null) {
throw new XMLEncryptionException("empty", "The element can't be serialized as it has no parent");
@@ -1675,7 +1669,7 @@
Node sourceParent = element.getParentNode();
try {
- Node decryptedNode = serializer.deserialize(octets, sourceParent);
+ Node decryptedNode = serializer.deserialize(octets, sourceParent, secureValidation);
// The de-serialiser returns a node whose children we need to take on.
if (sourceParent != null && Node.DOCUMENT_NODE == sourceParent.getNodeType()) {