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.security.cert.X509Certificate;
20 import java.util.HashSet;
22 import javax.security.auth.x500.X500Principal;
24 import org.apache.log4j.Logger;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
29 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
30 import edu.internet2.middleware.shibboleth.common.provider.ShibbolethTrust;
31 import edu.internet2.middleware.shibboleth.idp.IdPConfig;
32 import edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler;
35 * Functionality common to all <code>IdPProtocolHandler</code> implementation.
37 * @author Walter Hoehn
39 public abstract class BaseHandler implements IdPProtocolHandler {
41 private static Logger log = Logger.getLogger(BaseHandler.class.getName());
42 private HashSet locations = new HashSet();
45 * Required DOM-based constructor.
47 public BaseHandler(Element config) throws ShibbolethConfigurationException {
49 // Make sure we have at least one location
50 NodeList locations = config.getElementsByTagNameNS(IdPConfig.configNameSpace, "Location");
51 if (locations.getLength() < 1) {
52 log.error("The <ProtocolHandler/> element must contain at least one <Location/> element.");
53 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
56 // Parse the locations
57 for (int i = 0; i < locations.getLength(); i++) {
58 Node tnode = ((Element) locations.item(i)).getFirstChild();
59 if (tnode != null && tnode.getNodeType() == Node.TEXT_NODE) {
60 String rawURI = tnode.getNodeValue();
62 if (rawURI == null || rawURI.equals("")) {
63 log.error("The <Location/> element inside the <ProtocolHandler/> element must "
64 + "contain a URI or regular expressions.");
65 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
67 this.locations.add(rawURI);
70 log.error("The <Location/> element inside the <ProtocolHandler/> element must contain a "
71 + "URI or regular expression.");
72 throw new ShibbolethConfigurationException("Unable to load ProtocolHandler.");
78 * @see edu.internet2.middleware.shibboleth.idp.IdPProtocolHandler#getLocations()
80 public String[] getLocations() {
82 return (String[]) locations.toArray(new String[0]);
85 protected static String getHostNameFromDN(X500Principal dn) {
87 return ShibbolethTrust.getHostNameFromDN(dn);
90 protected static String[] getCredentialNames(X509Certificate cert) {
91 return ShibbolethTrust.getCredentialNames(cert);