From 3fc853cc1e861f455888a92ff0c9995270d2ba2c Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Jul 2011 20:14:02 +0200 Subject: imported 1.1.2 --- .../middleware/shibboleth/wayf/WayfService.html | 724 ++++++++++++--------- 1 file changed, 414 insertions(+), 310 deletions(-) (limited to 'doc/src-xref/edu/internet2/middleware/shibboleth/wayf/WayfService.html') diff --git a/doc/src-xref/edu/internet2/middleware/shibboleth/wayf/WayfService.html b/doc/src-xref/edu/internet2/middleware/shibboleth/wayf/WayfService.html index b19792a..f6b1195 100644 --- a/doc/src-xref/edu/internet2/middleware/shibboleth/wayf/WayfService.html +++ b/doc/src-xref/edu/internet2/middleware/shibboleth/wayf/WayfService.html @@ -1,322 +1,426 @@ - + WayfService xref
View Javadoc
 
-1   /*
-2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
-3    *
-4    * Licensed under the Apache License, Version 2.0 (the "License");
-5    * you may not use this file except in compliance with the License.
-6    * You may obtain a copy of the License at
-7    *
-8    * http://www.apache.org/licenses/LICENSE-2.0
-9    *
-10   * Unless required by applicable law or agreed to in writing, software
-11   * distributed under the License is distributed on an "AS IS" BASIS,
-12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-13   * See the License for the specific language governing permissions and
-14   * limitations under the License.
-15   */
-16  
-17  package edu.internet2.middleware.shibboleth.wayf;
-18  
-19  import java.io.FileInputStream;
-20  import java.io.FileNotFoundException;
-21  import java.lang.reflect.Constructor;
-22  import java.util.ArrayList;
-23  import java.util.Hashtable;
-24  import java.util.Iterator;
-25  import java.util.List;
-26  
-27  import javax.servlet.GenericServlet;
-28  import javax.servlet.ServletException;
-29  import javax.servlet.http.HttpServlet;
-30  import javax.servlet.http.HttpServletRequest;
-31  import javax.servlet.http.HttpServletResponse;
-32  
-33  import org.opensaml.DefaultBootstrap;
-34  import org.opensaml.xml.parse.BasicParserPool;
-35  import org.opensaml.xml.util.DatatypeHelper;
-36  import org.slf4j.Logger;
-37  import org.slf4j.LoggerFactory;
-38  import org.w3c.dom.Document;
-39  import org.w3c.dom.Element;
-40  import org.w3c.dom.NodeList;
-41  
-42  import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
-43  import edu.internet2.middleware.shibboleth.wayf.plugins.Plugin;
-44  
-45  /**
-46   * A servlet implementation of the Shibboleth WAYF service. Allows a browser
-47   * user to select from among a group of origin sites. User selection is
-48   * optionally cached and the user is forwarded to the HandleService appropriate
-49   * to his selection.
-50   */
-51  public class WayfService extends HttpServlet {
-52  
-53      /** Required constant for serializaton. */
-54      private static final long serialVersionUID = 5244503011625804940L;
-55      
-56      /** Handle for outputting error and other messages. */
-57      private static final Logger LOG = LoggerFactory.getLogger(WayfService.class.getName());
-58  
-59      /** Where to get the configuration. */
-60      private String wayfConfigFileLocation;
-61      
-62      /** Logging service. */
-63      private LogbackLoggingService logService;
-64  
-65      /** All the different Discovery Services we deal with. */
-66      private List <DiscoveryServiceHandler> discoveryServices = new ArrayList <DiscoveryServiceHandler>();
-67      
-68      /**
-69       * Initialize the Discovery Service.
-70       * 
-71       * @throws ServletException in the case of something bad happening
-72       *  
-73       * @see GenericServlet#init()
-74       */
-75      public void init() throws ServletException {
-76  
-77          super.init();
-78          
-79          wayfConfigFileLocation = getServletContext().getInitParameter("WAYFConfigFileLocation");
-80          if (wayfConfigFileLocation == null) {
-81              wayfConfigFileLocation = getServletConfig().getInitParameter("WAYFConfigFileLocation");
-82          }
-83          if (wayfConfigFileLocation == null) {
-84              wayfConfigFileLocation = "/wayfconfig.xml";
-85          }
-86  
-87  
-88          try {
-89              //
-90              // Initialize logging
-91              //
-92              String wayfLogfile = getServletContext().getInitParameter("WAYFLogConfig");
-93              if (null == wayfLogfile) {
-94                  wayfLogfile = getServletConfig().getInitParameter("WAYFLogConfig");
-95              }
-96              long pollingFrequency = 1000*60*5;
-97              
-98              String wayfLogfilePollFrequency = getServletContext().getInitParameter("WAYFLogConfigPollFrequency");
-99              if (null == wayfLogfilePollFrequency) {
-100                 wayfLogfilePollFrequency = getServletConfig().getInitParameter("WAYFLogConfigPollFrequency");              
-101             }
-102             if(!DatatypeHelper.isEmpty(wayfLogfilePollFrequency)){
-103                 pollingFrequency = Long.parseLong(wayfLogfilePollFrequency);
-104             }
-105             if (wayfLogfile != null) {
-106                 logService = new LogbackLoggingService(wayfLogfile, pollingFrequency);
-107             }
-108 
-109             LOG.info("Logging initiated");
-110             
-111             //
-112             // Initialize OpenSAML 2 library
-113             //
-114             DefaultBootstrap.bootstrap();   
-115         
-116             BasicParserPool parser = new BasicParserPool();
-117             parser.setNamespaceAware(true);
-118             Document doc;
-119             try {
-120                 doc = parser.parse(new FileInputStream(wayfConfigFileLocation));
-121             } catch (FileNotFoundException e) {
-122                 LOG.error("Could not parse " + wayfConfigFileLocation, e);
-123                 throw new ShibbolethConfigurationException("Could not parse " + wayfConfigFileLocation, e);
-124             }            
-125             NodeList itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS, 
-126                                                                                     "Default");
-127             
-128             HandlerConfig defaultHandlerConfig;
-129             
-130             if (itemElements.getLength() == 1) {
-131                     
-132                 Element element = (Element) itemElements.item(0);
-133                 String attribute = element.getAttribute("location");
-134                 
-135                 if (attribute != null && !attribute.equals("")) {
-136                         
-137                     LOG.error("<Default> element cannot contain a location attribute");
-138                     throw new ShibbolethConfigurationException("<Default> element cannot contain a location attribute");
-139                         
-140                 }
-141     
-142                 attribute = element.getAttribute("default");
-143                 
-144                 if (attribute != null && !attribute.equals("")) {
-145     
-146                     LOG.error("<Default> element cannot contain a default attribute");
-147                     throw new ShibbolethConfigurationException("<Default> element cannot contain a default attribute");
-148                     
-149                 }
-150     
-151                 itemElements = element.getElementsByTagName("Federation");
-152                 
-153                 if (itemElements.getLength() != 0) {
-154                         
-155                     LOG.error("<Default> element cannot contain <Federation> elements");
-156                     throw new ShibbolethConfigurationException("<Default> element cannot contain <Federation> elements");
-157     
-158                 }
-159                                         
-160                 defaultHandlerConfig = new HandlerConfig(element, new HandlerConfig());
-161         
-162             } else if (itemElements.getLength() == 0) {
-163     
-164                     defaultHandlerConfig = new HandlerConfig();
-165             
-166             } else {
-167                     LOG.error("Must specify exactly one <Default> element");
-168                     throw new ShibbolethConfigurationException("Must specify exactly one <Default> element");
-169             }
-170                                           
-171             //
-172             // Load metadata
-173             //
-174             Hashtable <String, IdPSiteSet> siteSets = new Hashtable <String, IdPSiteSet>();
-175     
-176             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
-177                             "MetadataProvider");
-178             
-179             for (int i = 0; i < itemElements.getLength(); i++) {
-180                     
-181                 Element element = (Element) itemElements.item(i);
-182                 
-183                 IdPSiteSet siteset = new IdPSiteSet(element, parser, defaultHandlerConfig.getWarnOnBadBinding());
-184                 
-185                 siteSets.put(siteset.getIdentifier(), siteset);
-186             }
-187             if (siteSets.size() < 1) {
-188                 LOG.error("No Metadata Provider metadata loaded.");
-189                 throw new ShibbolethConfigurationException("Could not load SAML metadata.");
-190             }
-191             //
-192             // Load plugins
-193             //
-194             
-195             Hashtable <String, Plugin> plugins = new Hashtable <String, Plugin>();
-196     
-197             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
-198                             "Plugin");
-199             
-200             for (int i = 0; i < itemElements.getLength(); i++) {
-201                     
-202                 Plugin plugin;
-203                 
-204                 Element element = (Element) itemElements.item(i);
-205                 
-206                 String identifier = element.getAttribute("identifier");
-207         
-208                 if (null == identifier || identifier.equals("")) {
-209                         LOG.error("Could not load plugin with no identifier");
-210                         continue;
-211                 }
-212                 
-213                 String className = element.getAttribute("type");
-214                 if (null == className || className.equals("")) {
-215                         LOG.error("Plugin " + identifier + " did not have a valid type");
-216                 }
-217                 //
-218                 // So try to get hold of the plugin
-219                 //
-220                 try {
-221                     Class<Plugin> pluginClass = (Class<Plugin>) Class.forName(className);
-222                     Class[] classParams = {Element.class};
-223                     Constructor<Plugin> pluginConstructor = pluginClass.getConstructor(classParams);
-224                     Object[] constructorParams = {element};
-225                     
-226                     plugin = pluginConstructor.newInstance(constructorParams);
-227                         
-228                 } catch (Exception e) {
-229                     LOG.error("Plugin " + identifier + " could not be loaded ", e);
-230                     continue;
-231                 } 
-232                 
-233                 plugins.put(identifier, plugin);
-234             }
-235             
-236             
-237             //
-238             // Load service handlers
-239             //
-240             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
-241                             "DiscoveryServiceHandler");
-242             
-243             for (int i = 0; i < itemElements.getLength(); i++) {
-244                     
-245                 discoveryServices.add(new DiscoveryServiceHandler((Element)itemElements.item(i), 
-246                                       siteSets, 
-247                                       plugins, 
-248                                       defaultHandlerConfig));
-249     
-250             }
-251     
-252         } catch (Exception e) {
-253         //
-254         // All other exceptions are from the parsing
-255         //
-256         if (LOG != null) {
-257                 LOG.error("Error parsing DS configuration file.", e);
-258         }
-259         throw new ServletException("Error parsing DS configuration file.", e);
-260     }
-261 
-262     LOG.info("DS initialization completed.");
-263 }
-264 
-265     /**
-266      * Handle an HTTP GET.  Just passes out to the appropriate handler.
-267      * @param req described the request.
-268      * @param res contains the response.
-269      * @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
-270      */
-271     public void doGet(HttpServletRequest req, HttpServletResponse res) {
-272             
-273         LOG.info("Handling DS request.");
-274         // Tell the browser not to cache the WAYF page
-275         res.setHeader("Cache-Control", "no-cache");
-276         res.setHeader("Pragma", "no-cache");
-277         res.setDateHeader("Expires", 0);
-278 
-279         DiscoveryServiceHandler serviceHandler = lookupServiceHandler(req); 
-280         
-281         serviceHandler.doGet(req, res);
-282            
-283     }
-284 
-285     /**
-286      * Given a request (an HTTP Get) find the apropriate DiscoveryService (from the name).
-287      * @param req desribed the request
-288      * @return the apropriate DiscoveryService.
-289      */
-290     private DiscoveryServiceHandler lookupServiceHandler(HttpServletRequest req) {
-291 
-292         Iterator<DiscoveryServiceHandler> it = discoveryServices.iterator();
-293         String requestURL = req.getRequestURL().toString(); 
-294         DiscoveryServiceHandler defaultHandler = null;
-295         
-296         while (it.hasNext()) {
-297             DiscoveryServiceHandler handler = it.next();
-298             
-299             if (requestURL.matches(handler.getLocation())) {
-300                 return handler;
-301             }
-302             if (defaultHandler == null || handler.isDefault()) {
-303                 defaultHandler = handler;
-304             }
-305         }
-306         LOG.warn("Could not find Discovery service Handler for " + requestURL);
-307         return defaultHandler;
-308     }    
-309 }
+1   /*
+2    * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
+3    *
+4    * Licensed under the Apache License, Version 2.0 (the "License");
+5    * you may not use this file except in compliance with the License.
+6    * You may obtain a copy of the License at
+7    *
+8    * http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS,
+12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   * See the License for the specific language governing permissions and
+14   * limitations under the License.
+15   */
+16  
+17  package edu.internet2.middleware.shibboleth.wayf;
+18  
+19  import java.io.FileInputStream;
+20  import java.io.FileNotFoundException;
+21  import java.lang.reflect.Constructor;
+22  import java.util.ArrayList;
+23  import java.util.Hashtable;
+24  import java.util.Iterator;
+25  import java.util.List;
+26  
+27  import javax.servlet.GenericServlet;
+28  import javax.servlet.ServletException;
+29  import javax.servlet.http.HttpServlet;
+30  import javax.servlet.http.HttpServletRequest;
+31  import javax.servlet.http.HttpServletResponse;
+32  import javax.xml.namespace.QName;
+33  
+34  import org.opensaml.DefaultBootstrap;
+35  import org.opensaml.xml.Configuration;
+36  import org.opensaml.xml.XMLObjectBuilderFactory;
+37  import org.opensaml.xml.io.UnmarshallerFactory;
+38  import org.opensaml.xml.parse.BasicParserPool;
+39  import org.opensaml.xml.util.DatatypeHelper;
+40  import org.slf4j.Logger;
+41  import org.slf4j.LoggerFactory;
+42  import org.w3c.dom.Document;
+43  import org.w3c.dom.Element;
+44  import org.w3c.dom.NodeList;
+45  
+46  import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
+47  import edu.internet2.middleware.shibboleth.wayf.idpdisco.Description;
+48  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DescriptionBuilder;
+49  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DescriptionUnmarshaller;
+50  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DiscoHints;
+51  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DiscoHintsBuilder;
+52  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DiscoHintsUnmarshaller;
+53  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DisplayName;
+54  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DisplayNameBuilder;
+55  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DisplayNameUnmarshaller;
+56  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DomainHint;
+57  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DomainHintBuilder;
+58  import edu.internet2.middleware.shibboleth.wayf.idpdisco.DomainHintUnmarshaller;
+59  import edu.internet2.middleware.shibboleth.wayf.idpdisco.GeolocationHint;
+60  import edu.internet2.middleware.shibboleth.wayf.idpdisco.GeolocationHintBuilder;
+61  import edu.internet2.middleware.shibboleth.wayf.idpdisco.GeolocationHintUnmarshaller;
+62  import edu.internet2.middleware.shibboleth.wayf.idpdisco.IPHint;
+63  import edu.internet2.middleware.shibboleth.wayf.idpdisco.IPHintBuilder;
+64  import edu.internet2.middleware.shibboleth.wayf.idpdisco.IPHintUnmarshaller;
+65  import edu.internet2.middleware.shibboleth.wayf.idpdisco.InformationURL;
+66  import edu.internet2.middleware.shibboleth.wayf.idpdisco.InformationURLBuilder;
+67  import edu.internet2.middleware.shibboleth.wayf.idpdisco.InformationURLUnmarshaller;
+68  import edu.internet2.middleware.shibboleth.wayf.idpdisco.Logo;
+69  import edu.internet2.middleware.shibboleth.wayf.idpdisco.LogoBuilder;
+70  import edu.internet2.middleware.shibboleth.wayf.idpdisco.LogoUnmarshaller;
+71  import edu.internet2.middleware.shibboleth.wayf.idpdisco.PrivacyStatementURL;
+72  import edu.internet2.middleware.shibboleth.wayf.idpdisco.PrivacyStatementURLBuilder;
+73  import edu.internet2.middleware.shibboleth.wayf.idpdisco.PrivacyStatementURLUnmarshaller;
+74  import edu.internet2.middleware.shibboleth.wayf.idpdisco.UIInfo;
+75  import edu.internet2.middleware.shibboleth.wayf.idpdisco.UIInfoBuilder;
+76  import edu.internet2.middleware.shibboleth.wayf.idpdisco.UIInfoUnmarshaller;
+77  import edu.internet2.middleware.shibboleth.wayf.plugins.Plugin;
+78  
+79  /**
+80   * A servlet implementation of the Shibboleth WAYF service. Allows a browser
+81   * user to select from among a group of origin sites. User selection is
+82   * optionally cached and the user is forwarded to the HandleService appropriate
+83   * to his selection.
+84   */
+85  public class WayfService extends HttpServlet {
+86  
+87      /** Required constant for serializaton. */
+88      private static final long serialVersionUID = 5244503011625804940L;
+89      
+90      /** Handle for outputting error and other messages. */
+91      private static final Logger LOG = LoggerFactory.getLogger(WayfService.class.getName());
+92  
+93      /** Where to get the configuration. */
+94      private String wayfConfigFileLocation;
+95      
+96      /** Logging service. */
+97      private LogbackLoggingService logService;
+98  
+99      /** All the different Discovery Services we deal with. */
+100     private List <DiscoveryServiceHandler> discoveryServices = new ArrayList <DiscoveryServiceHandler>();
+101     
+102     /**
+103      * help for init.
+104      */
+105     private void setupOtherSamlTypes(){
+106         QName response;
+107         UnmarshallerFactory uFactory = Configuration.getUnmarshallerFactory();
+108         XMLObjectBuilderFactory bFactory = Configuration.getBuilderFactory();
+109         
+110         //
+111         // The UiInfo type
+112         //
+113         response = new QName(UIInfo.MDUI_NS, Description.DEFAULT_ELEMENT_LOCAL_NAME);
+114         uFactory.registerUnmarshaller(response, new DescriptionUnmarshaller());
+115         bFactory.registerBuilder(response, new DescriptionBuilder());
+116         
+117         response = new QName(UIInfo.MDUI_NS, DisplayName.DEFAULT_ELEMENT_LOCAL_NAME);
+118         uFactory.registerUnmarshaller(response, new DisplayNameUnmarshaller());
+119         bFactory.registerBuilder(response, new DisplayNameBuilder());
+120         
+121         response = new QName(UIInfo.MDUI_NS, InformationURL.DEFAULT_ELEMENT_LOCAL_NAME);
+122         uFactory.registerUnmarshaller(response, new InformationURLUnmarshaller());
+123         bFactory.registerBuilder(response, new InformationURLBuilder());
+124 
+125         response = new QName(UIInfo.MDUI_NS, Logo.DEFAULT_ELEMENT_LOCAL_NAME);
+126         uFactory.registerUnmarshaller(response, new LogoUnmarshaller());
+127         bFactory.registerBuilder(response, new LogoBuilder());
+128 
+129         response = new QName(UIInfo.MDUI_NS, PrivacyStatementURL.DEFAULT_ELEMENT_LOCAL_NAME);
+130         uFactory.registerUnmarshaller(response, new PrivacyStatementURLUnmarshaller());
+131         bFactory.registerBuilder(response, new PrivacyStatementURLBuilder());
+132 
+133         response = new QName(UIInfo.MDUI_NS, UIInfo.DEFAULT_ELEMENT_LOCAL_NAME);
+134         uFactory.registerUnmarshaller(response, new UIInfoUnmarshaller());
+135         bFactory.registerBuilder(response, new UIInfoBuilder());
+136         
+137         //
+138         // The DiscoHint Types
+139         //
+140         response = new QName(DiscoHints.MDUI_NS, IPHint.DEFAULT_ELEMENT_LOCAL_NAME);
+141         uFactory.registerUnmarshaller(response, new IPHintUnmarshaller());
+142         bFactory.registerBuilder(response, new IPHintBuilder());
+143         
+144         response = new QName(DiscoHints.MDUI_NS, GeolocationHint.DEFAULT_ELEMENT_LOCAL_NAME);
+145         uFactory.registerUnmarshaller(response, new GeolocationHintUnmarshaller());
+146         bFactory.registerBuilder(response, new GeolocationHintBuilder());
+147 
+148         response = new QName(DiscoHints.MDUI_NS, DomainHint.DEFAULT_ELEMENT_LOCAL_NAME);
+149         uFactory.registerUnmarshaller(response, new DomainHintUnmarshaller());
+150         bFactory.registerBuilder(response, new DomainHintBuilder());
+151 
+152         response = new QName(DiscoHints.MDUI_NS, DiscoHints.DEFAULT_ELEMENT_LOCAL_NAME);
+153         uFactory.registerUnmarshaller(response, new DiscoHintsUnmarshaller());
+154         bFactory.registerBuilder(response, new DiscoHintsBuilder());
+155     }
+156     
+157 
+158     /**
+159      * Initialize the Discovery Service.
+160      * 
+161      * @throws javax.servlet.ServletException in the case of something bad happening
+162      *  
+163      * @see GenericServlet#init()
+164      */
+165     public void init() throws ServletException {
+166 
+167         String loadMetadataExts = null;
+168         
+169         super.init();
+170         
+171         wayfConfigFileLocation = getServletContext().getInitParameter("WAYFConfigFileLocation");
+172         if (wayfConfigFileLocation == null) {
+173             wayfConfigFileLocation = getServletConfig().getInitParameter("WAYFConfigFileLocation");
+174         }
+175         if (wayfConfigFileLocation == null) {
+176             wayfConfigFileLocation = "/wayfconfig.xml";
+177         }
+178 
+179         loadMetadataExts = getServletContext().getInitParameter("loadMetadataExts");
+180         if (loadMetadataExts == null) {
+181             loadMetadataExts = getServletConfig().getInitParameter("loadMetadataExts");
+182         }
+183 
+184         try {
+185             //
+186             // Initialize logging
+187             //
+188             String wayfLogfile = getServletContext().getInitParameter("WAYFLogConfig");
+189             if (null == wayfLogfile) {
+190                 wayfLogfile = getServletConfig().getInitParameter("WAYFLogConfig");
+191             }
+192             long pollingFrequency = 1000*60*5;
+193             
+194             String wayfLogfilePollFrequency = getServletContext().getInitParameter("WAYFLogConfigPollFrequency");
+195             if (null == wayfLogfilePollFrequency) {
+196                 wayfLogfilePollFrequency = getServletConfig().getInitParameter("WAYFLogConfigPollFrequency");              
+197             }
+198             if(!DatatypeHelper.isEmpty(wayfLogfilePollFrequency)){
+199                 pollingFrequency = Long.parseLong(wayfLogfilePollFrequency);
+200             }
+201             if (wayfLogfile != null) {
+202                 logService = new LogbackLoggingService(wayfLogfile, pollingFrequency);
+203             }
+204 
+205             LOG.info("Logging initiated");
+206             
+207             //
+208             // Initialize OpenSAML 2 library
+209             //
+210             DefaultBootstrap.bootstrap();   
+211         
+212             BasicParserPool parser = new BasicParserPool();
+213             parser.setNamespaceAware(true);
+214             Document doc;
+215             try {
+216                 doc = parser.parse(new FileInputStream(wayfConfigFileLocation));
+217             } catch (FileNotFoundException e) {
+218                 LOG.error("Could not parse " + wayfConfigFileLocation, e);
+219                 throw new ShibbolethConfigurationException("Could not parse " + wayfConfigFileLocation, e);
+220             }            
+221             NodeList itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS, 
+222                                                                                     "Default");
+223             
+224             HandlerConfig defaultHandlerConfig;
+225             
+226             if (itemElements.getLength() == 1) {
+227                     
+228                 Element element = (Element) itemElements.item(0);
+229                 String attribute = element.getAttribute("location");
+230                 
+231                 if (attribute != null && !attribute.equals("")) {
+232                         
+233                     LOG.error("<Default> element cannot contain a location attribute");
+234                     throw new ShibbolethConfigurationException("<Default> element cannot contain a location attribute");
+235                         
+236                 }
+237     
+238                 attribute = element.getAttribute("default");
+239                 
+240                 if (attribute != null && !attribute.equals("")) {
+241     
+242                     LOG.error("<Default> element cannot contain a default attribute");
+243                     throw new ShibbolethConfigurationException("<Default> element cannot contain a default attribute");
+244                     
+245                 }
+246     
+247                 itemElements = element.getElementsByTagName("Federation");
+248                 
+249                 if (itemElements.getLength() != 0) {
+250                         
+251                     LOG.error("<Default> element cannot contain <Federation> elements");
+252                     throw new ShibbolethConfigurationException("<Default> element cannot contain <Federation> elements");
+253     
+254                 }
+255                                         
+256                 defaultHandlerConfig = new HandlerConfig(element, new HandlerConfig());
+257         
+258             } else if (itemElements.getLength() == 0) {
+259     
+260                     defaultHandlerConfig = new HandlerConfig();
+261             
+262             } else {
+263                     LOG.error("Must specify exactly one <Default> element");
+264                     throw new ShibbolethConfigurationException("Must specify exactly one <Default> element");
+265             }
+266             
+267             //
+268             // As a trial for V2, load metadata extensions - if enabled
+269             //
+270             if (loadMetadataExts != null) {
+271                 LOG.debug("Setting up <UIInfo> and <DiscoHints> parsers - UNSUPPORTED OPERATION");
+272                 setupOtherSamlTypes();
+273             }
+274                                           
+275             //
+276             // Load metadata
+277             //
+278             Hashtable <String, IdPSiteSet> siteSets = new Hashtable <String, IdPSiteSet>();
+279     
+280             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
+281                             "MetadataProvider");
+282             
+283             for (int i = 0; i < itemElements.getLength(); i++) {
+284                     
+285                 Element element = (Element) itemElements.item(i);
+286                 
+287                 IdPSiteSet siteset = new IdPSiteSet(element, parser, defaultHandlerConfig.getWarnOnBadBinding());
+288                 
+289                 siteSets.put(siteset.getIdentifier(), siteset);
+290             }
+291             if (siteSets.size() < 1) {
+292                 LOG.error("No Metadata Provider metadata loaded.");
+293                 throw new ShibbolethConfigurationException("Could not load SAML metadata.");
+294             }
+295             //
+296             // Load plugins
+297             //
+298             
+299             Hashtable <String, Plugin> plugins = new Hashtable <String, Plugin>();
+300     
+301             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
+302                             "Plugin");
+303             
+304             for (int i = 0; i < itemElements.getLength(); i++) {
+305                     
+306                 Plugin plugin;
+307                 
+308                 Element element = (Element) itemElements.item(i);
+309                 
+310                 String identifier = element.getAttribute("identifier");
+311         
+312                 if (null == identifier || identifier.equals("")) {
+313                         LOG.error("Could not load plugin with no identifier");
+314                         continue;
+315                 }
+316                 
+317                 String className = element.getAttribute("type");
+318                 if (null == className || className.equals("")) {
+319                         LOG.error("Plugin " + identifier + " did not have a valid type");
+320                 }
+321                 //
+322                 // So try to get hold of the plugin
+323                 //
+324                 try {
+325                     Class<Plugin> pluginClass = (Class<Plugin>) Class.forName(className);
+326                     Class[] classParams = {Element.class};
+327                     Constructor<Plugin> pluginConstructor = pluginClass.getConstructor(classParams);
+328                     Object[] constructorParams = {element};
+329                     
+330                     plugin = pluginConstructor.newInstance(constructorParams);
+331                         
+332                 } catch (Exception e) {
+333                     LOG.error("Plugin " + identifier + " could not be loaded ", e);
+334                     continue;
+335                 } 
+336                 
+337                 plugins.put(identifier, plugin);
+338             }
+339             
+340             
+341             //
+342             // Load service handlers
+343             //
+344             itemElements = doc.getDocumentElement().getElementsByTagNameNS(XMLConstants.CONFIG_NS,
+345                             "DiscoveryServiceHandler");
+346             
+347             for (int i = 0; i < itemElements.getLength(); i++) {
+348                     
+349                 discoveryServices.add(new DiscoveryServiceHandler((Element)itemElements.item(i), 
+350                                       siteSets, 
+351                                       plugins, 
+352                                       defaultHandlerConfig));
+353     
+354             }
+355     
+356         } catch (Exception e) {
+357         //
+358         // All other exceptions are from the parsing
+359         //
+360         if (LOG != null) {
+361                 LOG.error("Error parsing DS configuration file.", e);
+362         }
+363         throw new ServletException("Error parsing DS configuration file.", e);
+364     }
+365 
+366     LOG.info("DS initialization completed.");
+367 }
+368 
+369     /**
+370      * Handle an HTTP GET.  Just passes out to the appropriate handler.
+371      * @param req described the request.
+372      * @param res contains the response.
+373      * @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
+374      */
+375     public void doGet(HttpServletRequest req, HttpServletResponse res) {
+376             
+377         LOG.info("Handling DS request.");
+378         // Tell the browser not to cache the WAYF page
+379         res.setHeader("Cache-Control", "no-cache");
+380         res.setHeader("Pragma", "no-cache");
+381         res.setDateHeader("Expires", 0);
+382 
+383         DiscoveryServiceHandler serviceHandler = lookupServiceHandler(req); 
+384         
+385         serviceHandler.doGet(req, res);
+386            
+387     }
+388 
+389     /**
+390      * Given a request (an HTTP Get) find the apropriate DiscoveryService (from the name).
+391      * @param req desribed the request
+392      * @return the apropriate DiscoveryService.
+393      */
+394     private DiscoveryServiceHandler lookupServiceHandler(HttpServletRequest req) {
+395 
+396         Iterator<DiscoveryServiceHandler> it = discoveryServices.iterator();
+397         String requestURL = req.getRequestURL().toString(); 
+398         DiscoveryServiceHandler defaultHandler = null;
+399         
+400         while (it.hasNext()) {
+401             DiscoveryServiceHandler handler = it.next();
+402             
+403             if (requestURL.matches(handler.getLocation())) {
+404                 return handler;
+405             }
+406             if (defaultHandler == null || handler.isDefault()) {
+407                 defaultHandler = handler;
+408             }
+409         }
+410         LOG.warn("Could not find Discovery service Handler for " + requestURL);
+411         return defaultHandler;
+412     }    
+413 }
 

-- cgit v1.1