Default protocol handler configuration is used if none is specified in idp.xml.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 13 May 2005 20:23:48 +0000 (20:23 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 13 May 2005 20:23:48 +0000 (20:23 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1479 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/idp/IdPProtocolHandler.java
src/edu/internet2/middleware/shibboleth/idp/IdPResponder.java
src/edu/internet2/middleware/shibboleth/idp/provider/BaseHandler.java

index e1578f5..1628aa0 100644 (file)
@@ -26,7 +26,6 @@
 package edu.internet2.middleware.shibboleth.idp;
 
 import java.io.IOException;
-import java.net.URI;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -65,5 +64,5 @@ public interface IdPProtocolHandler {
        /**
         * Returns the locations for which this handler should process requests.
         */
-       public URI[] getLocations();
+       public String[] getLocations();
 }
\ No newline at end of file
index 74b549b..150db3a 100644 (file)
@@ -26,7 +26,6 @@
 package edu.internet2.middleware.shibboleth.idp;
 
 import java.io.IOException;
-import java.net.URI;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Random;
@@ -37,6 +36,8 @@ import javax.servlet.UnavailableException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.MDC;
@@ -186,26 +187,23 @@ public class IdPResponder extends HttpServlet {
 
                        // Default if no handlers are specified
                        if (itemElements.getLength() < 1) {
-                               // TODO work out defaulting
+                               itemElements = getDefaultHandlers();
 
                                // If handlers were specified, load them and register them against their locations
-                       } else {
-                               EACHHANDLER : for (int i = 0; i < itemElements.getLength(); i++) {
-                                       IdPProtocolHandler handler = ProtocolHandlerFactory.getInstance((Element) itemElements.item(i));
-                                       URI[] locations = handler.getLocations();
-                                       EACHLOCATION : for (int j = 0; j < locations.length; j++) {
-                                               if (protocolHandlers.containsKey(locations[j].toString())) {
-                                                       log.error("Multiple protocol handlers are registered to listen at ("
-                                                                       + locations[j]
-                                                                       + ").  Ignoring all except ("
-                                                                       + ((IdPProtocolHandler) protocolHandlers.get(locations[j].toString()))
-                                                                                       .getHandlerName() + ").");
-                                                       continue EACHLOCATION;
-                                               }
-                                               log.info("Registering handler (" + handler.getHandlerName() + ") to listen at (" + locations[j]
-                                                               + ").");
-                                               protocolHandlers.put(locations[j].toString(), handler);
+                       }
+                       EACHHANDLER : for (int i = 0; i < itemElements.getLength(); i++) {
+                               IdPProtocolHandler handler = ProtocolHandlerFactory.getInstance((Element) itemElements.item(i));
+                               String[] locations = handler.getLocations();
+                               EACHLOCATION : for (int j = 0; j < locations.length; j++) {
+                                       if (protocolHandlers.containsKey(locations[j])) {
+                                               log.error("Multiple protocol handlers are registered to listen at (" + locations[j]
+                                                               + ").  Ignoring all except ("
+                                                               + ((IdPProtocolHandler) protocolHandlers.get(locations[j])).getHandlerName() + ").");
+                                               continue EACHLOCATION;
                                        }
+                                       log.info("Registering handler (" + handler.getHandlerName() + ") to listen at (" + locations[j]
+                                                       + ").");
+                                       protocolHandlers.put(locations[j].toString(), handler);
                                }
                        }
 
@@ -320,6 +318,47 @@ public class IdPResponder extends HttpServlet {
                return activeHandler;
        }
 
+       private NodeList getDefaultHandlers() throws ShibbolethConfigurationException {
+
+               log.debug("Loading default protocol handler configuration.");
+               try {
+                       DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+                       docFactory.setNamespaceAware(true);
+                       Document placeHolder = docFactory.newDocumentBuilder().newDocument();
+                       Element baseNode = placeHolder.createElementNS(IdPConfig.configNameSpace, "IdPConfig");
+
+                       Element ssoHandler = placeHolder.createElementNS(IdPConfig.configNameSpace, "ProtocolHandler");
+                       ssoHandler.setAttribute("implementation",
+                                       "edu.internet2.middleware.shibboleth.idp.provider.ShibbolethV1SSOHandler");
+                       Element ssoLocation = placeHolder.createElementNS(IdPConfig.configNameSpace, "Location");
+                       ssoLocation.appendChild(placeHolder.createTextNode("https?://[^/]+(:443)?/shibboleth/SSO"));
+                       ssoHandler.appendChild(ssoLocation);
+                       baseNode.appendChild(ssoHandler);
+
+                       Element attributeHandler = placeHolder.createElementNS(IdPConfig.configNameSpace, "ProtocolHandler");
+                       attributeHandler.setAttribute("implementation",
+                                       "edu.internet2.middleware.shibboleth.idp.provider.SAMLv1_AttributeQueryHandler");
+                       Element attributeLocation = placeHolder.createElementNS(IdPConfig.configNameSpace, "Location");
+                       attributeLocation.appendChild(placeHolder.createTextNode("https?://[^/]+:8443/shibboleth/AA"));
+                       attributeHandler.appendChild(attributeLocation);
+                       baseNode.appendChild(attributeHandler);
+
+                       Element artifactHandler = placeHolder.createElementNS(IdPConfig.configNameSpace, "ProtocolHandler");
+                       artifactHandler.setAttribute("implementation",
+                                       "edu.internet2.middleware.shibboleth.idp.provider.SAMLv1_1ArtifactQueryHandler");
+                       Element artifactLocation = placeHolder.createElementNS(IdPConfig.configNameSpace, "Location");
+                       artifactLocation.appendChild(placeHolder.createTextNode("https?://[^/]+:8443/shibboleth/Artifact"));
+                       artifactHandler.appendChild(artifactLocation);
+                       baseNode.appendChild(artifactHandler);
+
+                       return baseNode.getElementsByTagNameNS(IdPConfig.configNameSpace, "ProtocolHandler");
+
+               } catch (ParserConfigurationException e) {
+                       log.fatal("Encoutered an error while loading default protocol handlers: " + e);
+                       throw new ShibbolethConfigurationException("Could not load protocol handlers.");
+               }
+       }
+
        private void sendFailureToSAMLBinding(HttpServletResponse httpResponse, SAMLRequest samlRequest,
                        SAMLException exception) throws ServletException {
 
index 985466e..7050f21 100644 (file)
@@ -25,8 +25,6 @@
 
 package edu.internet2.middleware.shibboleth.idp.provider;
 
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.HashSet;
 
 import javax.security.auth.x500.X500Principal;
@@ -70,21 +68,15 @@ public abstract class BaseHandler implements IdPProtocolHandler {
                                String rawURI = tnode.getNodeValue();
 
                                if (rawURI == null || rawURI.equals("")) {
-                                       log.error("The <Location/> element inside the <ProtocolHandler/> element must contain a URI.");
-                                       throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
-                               }
-
-                               try {
-                                       URI location = new URI(rawURI);
-                                       this.locations.add(location);
-                               } catch (URISyntaxException e) {
-                                       log.error("The <Location/> element inside the <ProtocolHandler/> element contains "
-                                                       + "an improperly formatted URI: " + e);
+                                       log.error("The <Location/> element inside the <ProtocolHandler/> element must "
+                                                       + "contain a URI or regular expressions.");
                                        throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
                                }
+                               this.locations.add(rawURI);
 
                        } else {
-                               log.error("The <Location/> element inside the <ProtocolHandler/> element must contain a URI.");
+                               log.error("The <Location/> element inside the <ProtocolHandler/> element must contain a "
+                                               + "URI or regular expression.");
                                throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
                        }
                }
@@ -93,9 +85,9 @@ public abstract class BaseHandler implements IdPProtocolHandler {
        /*
         * @see edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler#getLocations()
         */
-       public URI[] getLocations() {
+       public String[] getLocations() {
 
-               return (URI[]) locations.toArray(new URI[0]);
+               return (String[]) locations.toArray(new String[0]);
        }
 
        protected static String getHostNameFromDN(X500Principal dn) {