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/03/28 12:54:21 UTC
svn commit: r1582717 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/stax/ext/XMLSec.java
main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
test/java/javax/xml/crypto/test/dsig/TestUtils.java
Author: coheigea
Date: Fri Mar 28 11:54:21 2014
New Revision: 1582717
URL: http://svn.apache.org/r1582717
Log:
Move schema loading etc. into XMLSec
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/XMLSecurityConstants.java
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=1582717&r1=1582716&r2=1582717&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 Fri Mar 28 11:54:21 2014
@@ -25,11 +25,22 @@ 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.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;
/**
* This is the central class of the streaming XML-security framework.<br/>
@@ -48,12 +59,76 @@ public class XMLSec {
throw new RuntimeException("security-config.xml not found in classpath");
}
Init.init(resource.toURI());
+
+ try {
+ XMLSecurityConstants.setJaxbContext(
+ JAXBContext.newInstance(
+ org.apache.xml.security.binding.xmlenc.ObjectFactory.class,
+ org.apache.xml.security.binding.xmlenc11.ObjectFactory.class,
+ org.apache.xml.security.binding.xmldsig.ObjectFactory.class,
+ org.apache.xml.security.binding.xmldsig11.ObjectFactory.class,
+ 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);
+
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ }
} catch (XMLSecurityException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (URISyntaxException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
+
+ public static void init() {
+ // Do nothing
+ }
/**
* Creates and configures an outbound streaming security engine
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java?rev=1582717&r1=1582716&r2=1582717&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java Fri Mar 28 11:54:21 2014
@@ -18,14 +18,9 @@
*/
package org.apache.xml.security.stax.ext;
-import org.apache.xml.security.exceptions.XMLSecurityException;
-import org.apache.xml.security.stax.impl.util.ConcreteLSInput;
-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 java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
-import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
@@ -33,13 +28,9 @@ import javax.xml.datatype.DatatypeConfig
import javax.xml.datatype.DatatypeFactory;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
+import org.apache.xml.security.exceptions.XMLSecurityException;
/**
* XMLSecurityConstants for global use
@@ -75,66 +66,6 @@ public class XMLSecurityConstants {
xmlOutputFactoryNonRepairingNs = XMLOutputFactory.newInstance();
xmlOutputFactoryNonRepairingNs.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
-
- try {
- setJaxbContext(
- JAXBContext.newInstance(
- org.apache.xml.security.binding.xmlenc.ObjectFactory.class,
- org.apache.xml.security.binding.xmlenc11.ObjectFactory.class,
- org.apache.xml.security.binding.xmldsig.ObjectFactory.class,
- org.apache.xml.security.binding.xmldsig11.ObjectFactory.class,
- 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)),
- }
- );
- setJaxbSchemas(schema);
-
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- } catch (SAXException e) {
- throw new RuntimeException(e);
- }
}
protected XMLSecurityConstants() {
@@ -157,7 +88,7 @@ public class XMLSecurityConstants {
}
}
- protected static synchronized void setJaxbContext(JAXBContext jaxbContext) {
+ public static synchronized void setJaxbContext(JAXBContext jaxbContext) {
XMLSecurityConstants.jaxbContext = jaxbContext;
}
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=1582717&r1=1582716&r2=1582717&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 Fri Mar 28 11:54:21 2014
@@ -42,6 +42,7 @@ 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.utils.XMLUtils;
import org.w3c.dom.*;
@@ -88,7 +89,7 @@ public class TestUtils {
}
public static void validateSecurityOrEncryptionElement(Node toValidate) throws SAXException, IOException {
-
+ XMLSec.init();
Schema schema = XMLSecurityConstants.getJaxbSchemas();
Validator validator = schema.newValidator();
DOMSource source = new DOMSource(toValidate);