Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6110

AbstractSTSClient MEX: download XML schema from Location

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.13
    • Fix Version/s: 3.0.3, 2.7.14, 3.1
    • Component/s: STS
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      For MEX data like:

        <MetadataSection
          Dialect="http://www.w3.org/2001/XMLSchema"
          Identifier="http://something">
              <Location>https://some/location.xsd</Location>
        </MetadataSection>
      

      the AbstractSTSClient should probably start downloading when getAny() gives NULL.

      I stumbled upon this by implementing a WS-Trust STS with a WSDL that contains schema imports instead of an embedded XML schema.

      The next patch adds this feature (quick and dirty).

      --- src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java.orig	2014-11-19 17:49:37.964705313 +0100
      +++ src/main/java/org/apache/cxf/ws/security/trust/AbstractSTSClient.java	2014-11-19 18:19:01.989607217 +0100
      @@ -41,6 +41,9 @@
       import javax.wsdl.extensions.ExtensibilityElement;
       import javax.wsdl.extensions.schema.Schema;
       import javax.xml.namespace.QName;
      +import javax.xml.parsers.DocumentBuilder;
      +import javax.xml.parsers.DocumentBuilderFactory;
      +import javax.xml.parsers.ParserConfigurationException;
       import javax.xml.stream.XMLStreamException;
       import javax.xml.stream.XMLStreamWriter;
       import javax.xml.transform.dom.DOMSource;
      @@ -48,6 +51,7 @@
       import org.w3c.dom.Document;
       import org.w3c.dom.Element;
       import org.w3c.dom.Node;
      +import org.xml.sax.SAXException;
       import org.apache.cxf.Bus;
       import org.apache.cxf.BusException;
       import org.apache.cxf.binding.soap.SoapBindingConstants;
      @@ -525,6 +529,11 @@
                                   bus.getExtension(WSDLManager.class).getDefinition((Element)s.getAny());
                           } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                               Element schemaElement = (Element)s.getAny();
      +                        if (schemaElement ==  null) {
      +                            String schemaLocation = s.getLocation();
      +                            LOG.info("XSD schema location: " + schemaLocation);
      +                            schemaElement = downloadSchema(schemaLocation);
      +                        }
                               QName schemaName = 
                                   new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                               WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
      @@ -586,10 +595,20 @@
                           client = new ClientImpl(bus, endpoint);
                       }
                   } catch (Exception ex) {
      -                throw new TrustException(LOG, "WS_MEX_ERROR", ex);
      +                throw new TrustException("WS_MEX_ERROR", LOG, ex);
                   }
               }
           }
      +
      +    private Element downloadSchema(String schemaLocation)
      +        throws ParserConfigurationException, SAXException, IOException {
      +        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      +        documentBuilderFactory.setNamespaceAware(true);
      +        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      +        Document document = documentBuilder.parse(schemaLocation);
      +        return document.getDocumentElement();
      +    }
      +
           protected String findMEXLocation(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
               if (ref.getMetadata() != null && ref.getMetadata().getAny() != null) {
                   for (Object any : ref.getMetadata().getAny()) {
      

        Attachments

          Activity

            People

            • Assignee:
              coheigea Colm O hEigeartaigh
              Reporter:
              frank.cornelis Frank Cornelis
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: