Started to implement protocol handler configuration.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 15 Mar 2005 04:43:37 +0000 (04:43 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 15 Mar 2005 04:43:37 +0000 (04:43 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1297 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/IdPResponder.java
src/edu/internet2/middleware/shibboleth/idp/ProtocolHandlerFactory.java [new file with mode: 0644]
src/schemas/shibboleth-idpconfig-1.0.xsd

index af2d729..c01c195 100644 (file)
@@ -26,8 +26,6 @@
 package edu.internet2.middleware.shibboleth.idp;
 
 import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Random;
 
@@ -144,8 +142,8 @@ public class IdPResponder extends HttpServlet {
                        try {
                                resolver = new AttributeResolver(configuration);
 
-                               itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(
-                                               IdPConfig.originConfigNamespace, "ReleasePolicyEngine");
+                               itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(IdPConfig.configNameSpace,
+                                               "ReleasePolicyEngine");
 
                                if (itemElements.getLength() > 1) {
                                        log.warn("Encountered multiple <ReleasePolicyEngine> configuration elements.  Using first...");
@@ -169,12 +167,20 @@ public class IdPResponder extends HttpServlet {
                        // Load protocol handlers and support library
                        protocolSupport = new IdPProtocolSupport(configuration, transactionLog, nameMapper, spMapper, arpEngine,
                                        resolver);
-                       log.debug("Starting with Shibboleth v1 protocol handling enabled.");
+                       itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(IdPConfig.configNameSpace,
+                                       "ProtocolHandler");
+
+                       //TODO Default if no handlers are specified
 
+                       for (int i = 0; i < itemElements.getLength(); i++) {
+                               IdPProtocolHandler handler = ProtocolHandlerFactory.getInstance((Element) itemElements.item(i));
+                       }
+                       //TODO finish fleshing this out
+                       log.debug("Starting with Shibboleth v1 protocol handling enabled.");
                        protocolHandlers.put("https://wraith.memphis.edu/shibboleth/SSO", new ShibbolethV1SSOHandler());
 
                        // Load metadata
-                       itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(IdPConfig.originConfigNamespace,
+                       itemElements = originConfig.getDocumentElement().getElementsByTagNameNS(IdPConfig.configNameSpace,
                                        "FederationProvider");
                        for (int i = 0; i < itemElements.getLength(); i++) {
                                protocolSupport.addFederationProvider((Element) itemElements.item(i));
@@ -242,7 +248,7 @@ public class IdPResponder extends HttpServlet {
 
                MDC.put("serviceId", "[IdP] " + idgen.nextInt());
                MDC.put("remoteAddr", request.getRemoteAddr());
-               log.debug("Recieved a request via POST for endpoint (" + request.getRequestURI() + ").");
+               log.debug("Recieved a request via POST for endpoint (" + request.getRequestURL() + ").");
 
                // Parse SOAP request and marshall SAML request object
                SAMLRequest samlRequest = null;
@@ -270,9 +276,10 @@ public class IdPResponder extends HttpServlet {
                        }
 
                        // Determine which protocol handler is active for this endpoint
-                       IdPProtocolHandler activeHandler = (IdPProtocolHandler) protocolHandlers.get(request.getRequestURI());
+                       IdPProtocolHandler activeHandler = (IdPProtocolHandler) protocolHandlers.get(request.getRequestURL()
+                                       .toString());
                        if (activeHandler == null) {
-                               log.error("No protocol handler registered for endpoint (" + request.getRequestURI() + ").");
+                               log.error("No protocol handler registered for endpoint (" + request.getRequestURL() + ").");
                                throw new SAMLException("Request submitted to an invalid endpoint.");
                        }
 
diff --git a/src/edu/internet2/middleware/shibboleth/idp/ProtocolHandlerFactory.java b/src/edu/internet2/middleware/shibboleth/idp/ProtocolHandlerFactory.java
new file mode 100644 (file)
index 0000000..0d5627c
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
+ * All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted
+ * provided that the following conditions are met: Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution, if any, must include the following acknowledgment: "This product includes software
+ * developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2 Project.
+ * Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
+ * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2, nor
+ * the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
+ * products derived from this software without specific prior written permission. For written permission, please contact
+ * shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2, UCAID, or the
+ * University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name, without prior
+ * written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS PROVIDED BY THE
+ * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE
+ * DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE. IN NO
+ * EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC.
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package edu.internet2.middleware.shibboleth.idp;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+
+import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
+
+/**
+ * Factory class for loading <code>ProtocolHandler</code> implementations based on xml configuration.
+ * 
+ * @author Walter Hoehn
+ */
+public class ProtocolHandlerFactory {
+
+       private static Logger log = Logger.getLogger(ProtocolHandlerFactory.class.getName());
+
+       public static IdPProtocolHandler getInstance(Element config) throws ShibbolethConfigurationException {
+
+               String implementation = config.getAttribute("implementation");
+               if (implementation == null || implementation.equals("")) {
+                       log.error("No Protocol Handler implementation specified.  Attribute (implementation) is "
+                                       + "required with element <ProtocolHandler/>.");
+                       throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+
+               } else {
+
+                       try {
+                               log.debug("Loading Protocol Handler implementation: (" + implementation + ").");
+                               Class implClass = Class.forName(implementation);
+                               Constructor constructor = implClass.getConstructor(new Class[]{Element.class});
+                               Object rawImpl = constructor.newInstance(new Object[]{config});
+
+                               if (rawImpl instanceof IdPProtocolHandler) {
+                                       return (IdPProtocolHandler) rawImpl;
+                               } else {
+                                       log.error("Invalid configuration, supplied implementation class for the Protocol Handler "
+                                                       + "does not properly implement the required IdPProtocolHandler interface.");
+                                       throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+                               }
+
+                       } catch (ClassNotFoundException e) {
+                               log.error("Invalid configuration, supplied implementation class for the Protocol Handler "
+                                               + "could not be found: " + e.getMessage());
+                               throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+
+                       } catch (NoSuchMethodException e) {
+                               log.error("Invalid configuration, supplied implementation class for the Protocol Handler is "
+                                               + "not valid.  A DOM Element constructor is required: " + e.getMessage());
+                               throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+
+                       } catch (InvocationTargetException e) {
+                               Throwable cause = e.getCause();
+                               if (cause != null) {
+                                       log.error(cause.getMessage());
+                               }
+                               log.error("Invalid configuration, supplied implementation class for the Protocol Handler"
+                                               + " could not be loaded: " + e.getMessage());
+                               throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+                       } catch (Exception e) {
+                               log.error("Invalid configuration, supplied implementation class for the Protocol Handler"
+                                               + " could not be loaded: " + e.getMessage());
+                               throw new ShibbolethConfigurationException("Invalid configuration data supplied.");
+                       }
+               }
+       }
+
+}
\ No newline at end of file
index dc9e488..bdeec96 100644 (file)
 
                                <xs:element ref="credentials:Credentials"/>
 
+                               <xs:element name="ProtocolHandler" minOccurs="0" maxOccurs="unbounded">
+                                       <xs:complexType>
+                                               <xs:sequence>
+                                                       <xs:element name="Endpoint" type="xs:anyURI" minOccurs="1" maxOccurs="unbounded" />
+                                                       <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+                                               </xs:sequence>
+                                               <xs:attribute name="implementation" type="xs:string" use="required" />
+                                               <xs:anyAttribute namespace="##any" processContents="lax"/>
+                                       </xs:complexType>
+                               </xs:element>
+
                                <xs:element name="FederationProvider" minOccurs="0" maxOccurs="unbounded">
                                        <xs:complexType>
                                                <xs:sequence>
                                                <xs:anyAttribute namespace="##any" processContents="lax"/>
                                        </xs:complexType>
                                </xs:element>
+                               
                        </xs:sequence>
 
                        <xs:attribute name="resolverConfig" type="xs:string" use="optional" default="/conf/resolver.xml"/>