2 * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package edu.internet2.middleware.shibboleth.idp.provider;
19 import java.util.HashSet;
21 import javax.security.auth.x500.X500Principal;
23 import org.apache.log4j.Logger;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.Node;
26 import org.w3c.dom.NodeList;
28 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
29 import edu.internet2.middleware.shibboleth.common.provider.ShibbolethTrust;
30 import edu.internet2.middleware.shibboleth.idp.IdPConfig;
31 import edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler;
34 * Functionality common to all <code>IdPProtocolHandler</code> implementation.
36 * @author Walter Hoehn
38 public abstract class BaseHandler implements IdPProtocolHandler {
40 private static Logger log = Logger.getLogger(BaseHandler.class.getName());
41 private HashSet locations = new HashSet();
44 * Required DOM-based constructor.
46 public BaseHandler(Element config) throws ShibbolethConfigurationException {
48 // Make sure we have at least one location
49 NodeList locations = config.getElementsByTagNameNS(IdPConfig.configNameSpace, "Location");
50 if (locations.getLength() < 1) {
51 log.error("The <ProtocolHandler/> element must contain at least one <Location/> element.");
52 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
55 // Parse the locations
56 for (int i = 0; i < locations.getLength(); i++) {
57 Node tnode = ((Element) locations.item(i)).getFirstChild();
58 if (tnode != null && tnode.getNodeType() == Node.TEXT_NODE) {
59 String rawURI = tnode.getNodeValue();
61 if (rawURI == null || rawURI.equals("")) {
62 log.error("The <Location/> element inside the <ProtocolHandler/> element must "
63 + "contain a URI or regular expressions.");
64 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
66 this.locations.add(rawURI);
69 log.error("The <Location/> element inside the <ProtocolHandler/> element must contain a "
70 + "URI or regular expression.");
71 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
77 * @see edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler#getLocations()
79 public String[] getLocations() {
81 return (String[]) locations.toArray(new String[0]);
84 protected static String getHostNameFromDN(X500Principal dn) {
86 return ShibbolethTrust.getHostNameFromDN(dn);