You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2014/04/07 07:12:13 UTC
svn commit: r1585383 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/stax/ext/ main/resources/
test/java/javax/xml/crypto/test/dsig/
Author: coheigea
Date: Mon Apr 7 05:12:12 2014
New Revision: 1585383
URL: http://svn.apache.org/r1585383
Log:
Only load schemas if a configuration property is set
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSec.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java
santuario/xml-security-java/trunk/src/main/resources/security-config.xml
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSec.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSec.java?rev=1585383&r1=1585382&r2=1585383&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSec.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSec.java Mon Apr 7 05:12:12 2014
@@ -25,21 +25,15 @@ import java.security.interfaces.RSAPriva
import java.util.HashSet;
import javax.crypto.SecretKey;
-import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.apache.xml.security.stax.config.ConfigurationProperties;
import org.apache.xml.security.stax.config.Init;
-import org.apache.xml.security.stax.impl.util.ConcreteLSInput;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
import org.apache.xml.security.utils.ClassLoaderUtils;
-import org.w3c.dom.ls.LSInput;
-import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.SAXException;
/**
@@ -70,50 +64,12 @@ public class XMLSec {
org.apache.xml.security.binding.excc14n.ObjectFactory.class
)
);
- SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- schemaFactory.setResourceResolver(new LSResourceResolver() {
- @Override
- public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
- if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
- ConcreteLSInput concreteLSInput = new ConcreteLSInput();
- concreteLSInput.setByteStream(
- ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
- return concreteLSInput;
- } else if ("XMLSchema.dtd".equals(systemId)) {
- ConcreteLSInput concreteLSInput = new ConcreteLSInput();
- concreteLSInput.setByteStream(
- ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
- return concreteLSInput;
- } else if ("datatypes.dtd".equals(systemId)) {
- ConcreteLSInput concreteLSInput = new ConcreteLSInput();
- concreteLSInput.setByteStream(
- ClassLoaderUtils.getResourceAsStream("bindings/schemas/datatypes.dtd", XMLSecurityConstants.class));
- return concreteLSInput;
- } else if ("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd".equals(systemId)) {
- ConcreteLSInput concreteLSInput = new ConcreteLSInput();
- concreteLSInput.setByteStream(
- ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class));
- return concreteLSInput;
- } else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
- ConcreteLSInput concreteLSInput = new ConcreteLSInput();
- concreteLSInput.setByteStream(
- ClassLoaderUtils.getResourceAsStream("bindings/schemas/xml.xsd", XMLSecurityConstants.class));
- return concreteLSInput;
- }
- return null;
- }
- });
- Schema schema = schemaFactory.newSchema(
- new Source[]{
- new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/exc-c14n.xsd", XMLSecurityConstants.class)),
- new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class)),
- new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema.xsd", XMLSecurityConstants.class)),
- new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema-11.xsd", XMLSecurityConstants.class)),
- new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig11-schema.xsd", XMLSecurityConstants.class)),
- }
- );
- XMLSecurityConstants.setJaxbSchemas(schema);
-
+
+ String loadSchemas = ConfigurationProperties.getProperty("LoadSchemas");
+ if (Boolean.parseBoolean(loadSchemas)) {
+ Schema schema = XMLSecurityUtils.loadXMLSecuritySchemas();
+ XMLSecurityConstants.setJaxbSchemas(schema);
+ }
} catch (JAXBException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java?rev=1585383&r1=1585382&r2=1585383&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java Mon Apr 7 05:12:12 2014
@@ -28,15 +28,25 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.ext.stax.XMLSecNamespace;
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
import org.apache.xml.security.stax.impl.algorithms.ECDSAUtils;
+import org.apache.xml.security.stax.impl.util.ConcreteLSInput;
import org.apache.xml.security.stax.securityEvent.*;
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
+import org.apache.xml.security.utils.ClassLoaderUtils;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+import org.xml.sax.SAXException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
+import javax.xml.XMLConstants;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -439,4 +449,50 @@ public class XMLSecurityUtils {
return keySpec;
}
+ public static Schema loadXMLSecuritySchemas() throws SAXException {
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ schemaFactory.setResourceResolver(new LSResourceResolver() {
+ @Override
+ public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
+ if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
+ ConcreteLSInput concreteLSInput = new ConcreteLSInput();
+ concreteLSInput.setByteStream(
+ ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
+ return concreteLSInput;
+ } else if ("XMLSchema.dtd".equals(systemId)) {
+ ConcreteLSInput concreteLSInput = new ConcreteLSInput();
+ concreteLSInput.setByteStream(
+ ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
+ return concreteLSInput;
+ } else if ("datatypes.dtd".equals(systemId)) {
+ ConcreteLSInput concreteLSInput = new ConcreteLSInput();
+ concreteLSInput.setByteStream(
+ ClassLoaderUtils.getResourceAsStream("bindings/schemas/datatypes.dtd", XMLSecurityConstants.class));
+ return concreteLSInput;
+ } else if ("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd".equals(systemId)) {
+ ConcreteLSInput concreteLSInput = new ConcreteLSInput();
+ concreteLSInput.setByteStream(
+ ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class));
+ return concreteLSInput;
+ } else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
+ ConcreteLSInput concreteLSInput = new ConcreteLSInput();
+ concreteLSInput.setByteStream(
+ ClassLoaderUtils.getResourceAsStream("bindings/schemas/xml.xsd", XMLSecurityConstants.class));
+ return concreteLSInput;
+ }
+ return null;
+ }
+ });
+ Schema schema = schemaFactory.newSchema(
+ new Source[]{
+ new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/exc-c14n.xsd", XMLSecurityConstants.class)),
+ new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class)),
+ new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema.xsd", XMLSecurityConstants.class)),
+ new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema-11.xsd", XMLSecurityConstants.class)),
+ new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig11-schema.xsd", XMLSecurityConstants.class)),
+ }
+ );
+ return schema;
+ }
+
}
Modified: santuario/xml-security-java/trunk/src/main/resources/security-config.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/resources/security-config.xml?rev=1585383&r1=1585382&r2=1585383&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/resources/security-config.xml (original)
+++ santuario/xml-security-java/trunk/src/main/resources/security-config.xml Mon Apr 7 05:12:12 2014
@@ -13,6 +13,7 @@
<Property NAME="MaximumAllowedEncryptedDataEvents" VAL="200"/>
<Property NAME="DefaultLanguageCode" VAL="en"/>
<Property NAME="DefaultCountryCode" VAL="US"/>
+ <Property NAME="LoadSchemas" VAL="false"/>
</Properties>
<SecurityHeaderHandlers>
</SecurityHeaderHandlers>
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java?rev=1585383&r1=1585382&r2=1585383&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java Mon Apr 7 05:12:12 2014
@@ -21,31 +21,63 @@
*/
package javax.xml.crypto.test.dsig;
-import java.io.*;
-import java.security.*;
-import java.security.spec.*;
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.security.KeyFactory;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.DSAPrivateKeySpec;
+import java.security.spec.DSAPublicKeySpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.security.spec.RSAPrivateKeySpec;
+import java.security.spec.RSAPublicKeySpec;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import javax.crypto.SecretKey;
-import javax.xml.crypto.dsig.*;
+import javax.xml.crypto.Data;
+import javax.xml.crypto.NodeSetData;
+import javax.xml.crypto.OctetStreamData;
+import javax.xml.crypto.URIDereferencer;
+import javax.xml.crypto.URIReference;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.XMLSignatureException;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import javax.xml.crypto.dsig.XMLValidateContext;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
-import javax.xml.crypto.dsig.spec.*;
-import javax.xml.crypto.dom.*;
-import javax.xml.crypto.*;
-
-import java.math.BigInteger;
-
-import javax.xml.transform.*;
-import javax.xml.transform.dom.*;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
-import javax.xml.parsers.DocumentBuilder;
import org.apache.xml.security.stax.ext.XMLSec;
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityUtils;
import org.apache.xml.security.utils.XMLUtils;
-import org.w3c.dom.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/*
@@ -90,6 +122,9 @@ public class TestUtils {
public static void validateSecurityOrEncryptionElement(Node toValidate) throws SAXException, IOException {
XMLSec.init();
+ if (XMLSecurityConstants.getJaxbSchemas() == null) {
+ XMLSecurityConstants.setJaxbSchemas(XMLSecurityUtils.loadXMLSecuritySchemas());
+ }
Schema schema = XMLSecurityConstants.getJaxbSchemas();
Validator validator = schema.newValidator();
DOMSource source = new DOMSource(toValidate);