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:05 UTC

svn commit: r1582715 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax: config/ ext/ securityToken/

Author: coheigea
Date: Fri Mar 28 11:54:04 2014
New Revision: 1582715

URL: http://svn.apache.org/r1582715
Log:
Use ClassLoaderUtils to load resources/classes

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/Init.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/SecurityHeaderHandlerMapper.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java
    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/main/java/org/apache/xml/security/stax/ext/XMLSecurityUtils.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/securityToken/SecurityTokenFactory.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/Init.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/Init.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/Init.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/Init.java Fri Mar 28 11:54:04 2014
@@ -20,6 +20,7 @@ package org.apache.xml.security.stax.con
 
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.stax.ext.XMLSecurityConfigurationException;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 import org.apache.xml.security.utils.I18n;
 import org.apache.xml.security.configuration.ConfigurationType;
 import org.apache.xml.security.configuration.ObjectFactory;
@@ -33,6 +34,7 @@ import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
+
 import java.net.URI;
 import java.net.URL;
 
@@ -54,7 +56,8 @@ public class Init {
                 JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
                 final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-                Schema schema = schemaFactory.newSchema(Init.class.getClassLoader().getResource("schemas/security-config.xsd"));
+                Schema schema = schemaFactory.newSchema(
+                        ClassLoaderUtils.getResource("schemas/security-config.xsd", Init.class));
                 unmarshaller.setSchema(schema);
                 final UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
 
@@ -63,7 +66,7 @@ public class Init {
                 saxParserFactory.setNamespaceAware(true);
                 SAXParser saxParser = saxParserFactory.newSAXParser();
                 if (uri == null) {
-                    URL resource = Init.class.getClassLoader().getResource("security-config.xml");
+                    URL resource = ClassLoaderUtils.getResource("security-config.xml", Init.class);
                     if (resource == null) {
                         //kind of chicken-egg problem here
                         I18n.init("en", "US");

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/ResourceResolverMapper.java Fri Mar 28 11:54:04 2014
@@ -21,7 +21,7 @@ package org.apache.xml.security.stax.con
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.stax.ext.ResourceResolver;
 import org.apache.xml.security.stax.ext.ResourceResolverLookup;
-import org.apache.xml.security.stax.ext.XMLSecurityUtils;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 import org.apache.xml.security.configuration.ResolverType;
 import org.apache.xml.security.configuration.ResourceResolversType;
 
@@ -44,7 +44,8 @@ public class ResourceResolverMapper {
         resourceResolvers = new ArrayList<ResourceResolverLookup>(handlerList.size() + 1);
         for (int i = 0; i < handlerList.size(); i++) {
             ResolverType uriResolverType = handlerList.get(i);
-            resourceResolvers.add((ResourceResolverLookup) XMLSecurityUtils.loadClass(uriResolverType.getJAVACLASS()).newInstance());
+            resourceResolvers.add((ResourceResolverLookup) 
+                    ClassLoaderUtils.loadClass(uriResolverType.getJAVACLASS(), ResourceResolverMapper.class).newInstance());
         }
     }
 

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/SecurityHeaderHandlerMapper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/SecurityHeaderHandlerMapper.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/SecurityHeaderHandlerMapper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/SecurityHeaderHandlerMapper.java Fri Mar 28 11:54:04 2014
@@ -18,11 +18,12 @@
  */
 package org.apache.xml.security.stax.config;
 
-import org.apache.xml.security.stax.ext.XMLSecurityUtils;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 import org.apache.xml.security.configuration.HandlerType;
 import org.apache.xml.security.configuration.SecurityHeaderHandlersType;
 
 import javax.xml.namespace.QName;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -46,7 +47,8 @@ public class SecurityHeaderHandlerMapper
         for (int i = 0; i < handlerList.size(); i++) {
             HandlerType handlerType = handlerList.get(i);
             QName qName = new QName(handlerType.getURI(), handlerType.getNAME());
-            handlerClassMap.put(qName, XMLSecurityUtils.loadClass(handlerType.getJAVACLASS()));
+            handlerClassMap.put(qName, 
+                    ClassLoaderUtils.loadClass(handlerType.getJAVACLASS(), SecurityHeaderHandlerMapper.class));
         }
     }
 

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/TransformerAlgorithmMapper.java Fri Mar 28 11:54:04 2014
@@ -20,7 +20,7 @@ package org.apache.xml.security.stax.con
 
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.stax.ext.XMLSecurityConstants;
-import org.apache.xml.security.stax.ext.XMLSecurityUtils;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 import org.apache.xml.security.configuration.TransformAlgorithmType;
 import org.apache.xml.security.configuration.TransformAlgorithmsType;
 
@@ -52,11 +52,14 @@ public class TransformerAlgorithmMapper 
         for (int i = 0; i < algorithms.size(); i++) {
             TransformAlgorithmType algorithmType = algorithms.get(i);
             if (algorithmType.getINOUT() == null) {
-                algorithmsClassMapInOut.put(algorithmType.getURI(), XMLSecurityUtils.loadClass(algorithmType.getJAVACLASS()));
+                algorithmsClassMapInOut.put(algorithmType.getURI(), 
+                        ClassLoaderUtils.loadClass(algorithmType.getJAVACLASS(), TransformerAlgorithmMapper.class));
             } else if ("IN".equals(algorithmType.getINOUT().value())) {
-                algorithmsClassMapIn.put(algorithmType.getURI(), XMLSecurityUtils.loadClass(algorithmType.getJAVACLASS()));
+                algorithmsClassMapIn.put(algorithmType.getURI(), 
+                        ClassLoaderUtils.loadClass(algorithmType.getJAVACLASS(), TransformerAlgorithmMapper.class));
             } else if ("OUT".equals(algorithmType.getINOUT().value())) {
-                algorithmsClassMapOut.put(algorithmType.getURI(), XMLSecurityUtils.loadClass(algorithmType.getJAVACLASS()));
+                algorithmsClassMapOut.put(algorithmType.getURI(), 
+                        ClassLoaderUtils.loadClass(algorithmType.getJAVACLASS(), TransformerAlgorithmMapper.class));
             } else {
                 throw new IllegalArgumentException("INOUT parameter " + algorithmType.getINOUT().value() + " unsupported");
             }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/config/XIncludeHandler.java Fri Mar 28 11:54:04 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.xml.security.stax.config;
 
+import org.apache.xml.security.utils.ClassLoaderUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -41,6 +42,7 @@ import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
+
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -134,7 +136,7 @@ public class XIncludeHandler extends Def
             }
             String xpointer = atts.getValue("xpointer");
 
-            URL url = this.getClass().getClassLoader().getResource(href);
+            URL url = ClassLoaderUtils.getResource(href, XIncludeHandler.class);
             if (url == null) {
                 throw new SAXException("XML file not found: " + href);
             }

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=1582715&r1=1582714&r2=1582715&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:04 2014
@@ -29,6 +29,7 @@ import javax.crypto.SecretKey;
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 
 /**
  * This is the central class of the streaming XML-security framework.<br/>
@@ -42,7 +43,7 @@ public class XMLSec {
     
     static {
         try {
-            URL resource = XMLSec.class.getClassLoader().getResource("security-config.xml");
+            URL resource = ClassLoaderUtils.getResource("security-config.xml", XMLSec.class);
             if (resource == null) {
                 throw new RuntimeException("security-config.xml not found in classpath");
             }

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=1582715&r1=1582714&r2=1582715&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:04 2014
@@ -20,6 +20,7 @@ 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;
@@ -91,23 +92,28 @@ public class XMLSecurityConstants {
                 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(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/XMLSchema.dtd"));
+                        concreteLSInput.setByteStream(
+                                ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
                         return concreteLSInput;
                     } else if ("XMLSchema.dtd".equals(systemId)) {
                         ConcreteLSInput concreteLSInput = new ConcreteLSInput();
-                        concreteLSInput.setByteStream(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/XMLSchema.dtd"));
+                        concreteLSInput.setByteStream(
+                                ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
                         return concreteLSInput;
                     } else if ("datatypes.dtd".equals(systemId)) {
                         ConcreteLSInput concreteLSInput = new ConcreteLSInput();
-                        concreteLSInput.setByteStream(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/datatypes.dtd"));
+                        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(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd"));
+                        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(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xml.xsd"));
+                        concreteLSInput.setByteStream(
+                                ClassLoaderUtils.getResourceAsStream("bindings/schemas/xml.xsd", XMLSecurityConstants.class));
                         return concreteLSInput;
                     }
                     return null;
@@ -115,11 +121,11 @@ public class XMLSecurityConstants {
             });
             Schema schema = schemaFactory.newSchema(
                     new Source[]{
-                            new StreamSource(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/exc-c14n.xsd")),
-                            new StreamSource(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd")),
-                            new StreamSource(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xenc-schema.xsd")),
-                            new StreamSource(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xenc-schema-11.xsd")),
-                            new StreamSource(XMLSecurityConstants.class.getClassLoader().getResourceAsStream("bindings/schemas/xmldsig11-schema.xsd")),
+                            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);

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=1582715&r1=1582714&r2=1582715&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 Fri Mar 28 11:54:04 2014
@@ -109,10 +109,6 @@ public class XMLSecurityUtils {
         }
     }
 
-    public static Class<?> loadClass(String className) throws ClassNotFoundException {
-        return Thread.currentThread().getContextClassLoader().loadClass(className);
-    }
-
     public static Transformer getTransformer(
             Transformer transformer, OutputStream outputStream, Map<String, Object> properties, String algorithm,
             XMLSecurityConstants.DIRECTION direction) throws XMLSecurityException {

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/securityToken/SecurityTokenFactory.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/securityToken/SecurityTokenFactory.java?rev=1582715&r1=1582714&r2=1582715&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/securityToken/SecurityTokenFactory.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/securityToken/SecurityTokenFactory.java Fri Mar 28 11:54:04 2014
@@ -23,6 +23,7 @@ import org.apache.xml.security.exception
 import org.apache.xml.security.stax.config.ConfigurationProperties;
 import org.apache.xml.security.stax.ext.InboundSecurityContext;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
+import org.apache.xml.security.utils.ClassLoaderUtils;
 
 /**
  * Factory to create SecurityToken Objects from keys in XML
@@ -44,7 +45,7 @@ public abstract class SecurityTokenFacto
             try {
                 @SuppressWarnings("unchecked")
                 Class<SecurityTokenFactory> securityTokenFactoryClass =
-                        (Class<SecurityTokenFactory>) SecurityTokenFactory.class.getClassLoader().loadClass(stf);
+                        (Class<SecurityTokenFactory>) ClassLoaderUtils.loadClass(stf, SecurityTokenFactory.class);
                 securityTokenFactory = securityTokenFactoryClass.newInstance();
             } catch (ClassNotFoundException e) {
                 throw new XMLSecurityException("algorithm.ClassDoesNotExist", new Object[]{stf}, e);