NameMapper won't be used in 2.0.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 18 Sep 2006 20:50:46 +0000 (20:50 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 18 Sep 2006 20:50:46 +0000 (20:50 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2037 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/NameMapper.java [deleted file]
src/edu/internet2/middleware/shibboleth/idp/IdPProtocolSupport.java
src/edu/internet2/middleware/shibboleth/idp/IdPResponder.java

diff --git a/src/edu/internet2/middleware/shibboleth/common/NameMapper.java b/src/edu/internet2/middleware/shibboleth/common/NameMapper.java
deleted file mode 100644 (file)
index bf288ee..0000000
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package edu.internet2.middleware.shibboleth.common;
-
-import java.io.StringReader;
-import java.lang.reflect.Constructor;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.Principal;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.opensaml.SAMLNameIdentifier;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-
-import edu.internet2.middleware.shibboleth.common.provider.SharedMemoryShibHandle;
-import edu.internet2.middleware.shibboleth.xml.Parser;
-
-/**
- * Facility for managing mappings from SAML Name Identifiers to local {@link LocalPrincipal}objects. Mappings are
- * registered by Name Identifier format and can be associated with a <code>String</code> id and recovered based on the
- * same.
- * 
- * @author Walter Hoehn
- * @see NameIdentifierMapping
- */
-public class NameMapper {
-
-       private static Logger log = Logger.getLogger(NameMapper.class.getName());
-       private Map<URI, NameIdentifierMapping> byFormat = new HashMap<URI, NameIdentifierMapping>();
-       private Map<String, NameIdentifierMapping> byId = new HashMap<String, NameIdentifierMapping>();
-       private static Map<String, Class> registeredMappingTypes = Collections
-                       .synchronizedMap(new HashMap<String, Class>());
-       /** true if mappings have been added */
-       protected boolean initialized = false;
-       /** Mapping to use if no other mappings have been added */
-       protected SharedMemoryShibHandle defaultMapping;
-
-       // Preload aliases for bundled mappings
-       static {
-               try {
-                       registeredMappingTypes.put("CryptoHandleGenerator", Class
-                                       .forName("edu.internet2.middleware.shibboleth.common.provider.CryptoShibHandle"));
-
-                       registeredMappingTypes.put("SharedMemoryShibHandle", Class
-                                       .forName("edu.internet2.middleware.shibboleth.common.provider.SharedMemoryShibHandle"));
-
-                       registeredMappingTypes.put("Principal", Class
-                                       .forName("edu.internet2.middleware.shibboleth.common.provider.PrincipalNameIdentifier"));
-
-               } catch (ClassNotFoundException e) {
-                       log.error("Unable to pre-register Name mapping implementation types.");
-               }
-       }
-
-       /**
-        * Constructs the name mapper and loads a default name mapping.
-        */
-       public NameMapper() {
-
-               try {
-                       // Load the default mapping
-                       String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-                                       + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\" format=\"urn:mace:shibboleth:1.0:nameIdentifier\""
-                                       + "             handleTTL=\"1800\"/>";
-                       Parser.DOMParser parser = new Parser.DOMParser(false);
-                       parser.parse(new InputSource(new StringReader(rawConfig)));
-                       defaultMapping = new SharedMemoryShibHandle(parser.getDocument().getDocumentElement());
-
-               } catch (Exception e) {
-                       log.error("Unable to register default Name Identifier Mapping: " + e);
-                       initialize();
-               }
-       }
-
-       protected void initialize() {
-
-               initialized = true;
-               defaultMapping = null;
-       }
-
-       /**
-        * Constructs a {@link NameIdentifierMapping}based on XML configuration data and adds it to this {@link NameMapper},
-        * registering it according to its format.
-        * 
-        * @param e
-        *            An XML representation of a {@link NameIdentifierMapping}
-        * @throws NameIdentifierMappingException
-        *             If the mapping could not be constructed according to the supplied configuration
-        */
-       public void addNameMapping(Element e) throws NameIdentifierMappingException {
-
-               if (!e.getLocalName().equals("NameMapping")) { throw new IllegalArgumentException(); }
-
-               log.info("Found Name Mapping. Loading...");
-
-               String type = ((Element) e).getAttribute("type");
-               String implementation = ((Element) e).getAttribute("class");
-               if (type != null && (!type.equals("")) && implementation != null && (!implementation.equals(""))) {
-                       log.error("Name Mapping has both a \"type\" and a \"class\" attribute. Only \"type\" will take effect.");
-               }
-
-               if (type != null && (!type.equals(""))) {
-
-                       Class registeredImplementation = (Class) registeredMappingTypes.get(type);
-                       if (registeredImplementation == null) {
-                               log.error("Name Mapping refers to an unregistered implementation type.");
-                               throw new NameIdentifierMappingException("Invalid mapping implementation specified.");
-                       }
-
-                       log.debug("Found type (" + type + ") registered with an implementation class of ("
-                                       + registeredImplementation.getName() + ").");
-                       addNameMapping(loadNameIdentifierMapping(registeredImplementation, e));
-
-               } else if (implementation != null && (!implementation.equals(""))) {
-
-                       try {
-                               Class implementorClass = Class.forName(implementation);
-                               addNameMapping(loadNameIdentifierMapping(implementorClass, e));
-
-                       } catch (ClassNotFoundException cnfe) {
-                               log.error("Name Mapping refers to an implementation class that cannot be loaded: " + cnfe);
-                               throw new NameIdentifierMappingException("Invalid mapping implementation specified.");
-                       }
-
-               } else {
-                       log.error("Name Mapping requires either a \"type\" or a \"class\" attribute.");
-                       throw new NameIdentifierMappingException("No mapping implementation specified.");
-               }
-
-       }
-
-       /**
-        * Adds a {@link NameIdentifierMapping}to this name mapper, registering it according to its format.
-        * 
-        * @param mapping
-        *            the mapping to add
-        */
-       public void addNameMapping(NameIdentifierMapping mapping) {
-
-               initialize();
-
-               if (byFormat.containsKey(mapping.getNameIdentifierFormat())) {
-                       log.error("Attempted to register multiple Name Mappings with the same format.  Skipping duplicates...");
-                       return;
-               }
-               byFormat.put(mapping.getNameIdentifierFormat(), mapping);
-
-               if (mapping.getId() != null && !mapping.getId().equals("")) {
-                       byId.put(mapping.getId(), mapping);
-               }
-
-       }
-
-       /**
-        * Returns the {@link NameIdentifierMapping}registered for a given format.
-        * 
-        * @param format
-        *            the registered format
-        * @return the mapping or <code>null</code> if no mapping is registered for the given format
-        */
-       public NameIdentifierMapping getNameIdentifierMapping(URI format) {
-
-               if (!initialized) { return defaultMapping; }
-
-               return byFormat.get(format);
-       }
-
-       /**
-        * Returns the <code>NameIdentifierMapping</code> registered for a given id
-        * 
-        * @param id
-        *            the registered id
-        * @return the mapping or <tt>null</tt> if no mapping is registered for the given id
-        */
-       public NameIdentifierMapping getNameIdentifierMappingById(String id) {
-
-               if (id == null || id.equals("")) {
-                       if (!initialized) { return defaultMapping; }
-
-                       if (byFormat.size() == 1) {
-                               Iterator<NameIdentifierMapping> values = byFormat.values().iterator();
-                               NameIdentifierMapping mapping = values.next();
-                               return mapping;
-                       }
-               }
-
-               return byId.get(id);
-       }
-
-       protected NameIdentifierMapping loadNameIdentifierMapping(Class implementation, Element config)
-                       throws NameIdentifierMappingException {
-
-               try {
-                       Class[] params = new Class[]{Element.class};
-                       Constructor implementorConstructor = implementation.getConstructor(params);
-                       Object[] args = new Object[]{config};
-                       log.debug("Initializing Name Identifier Mapping of type (" + implementation.getName() + ").");
-                       return (NameIdentifierMapping) implementorConstructor.newInstance(args);
-
-               } catch (NoSuchMethodException nsme) {
-                       log.error("Failed to instantiate a Name Identifier Mapping: NameIdentifierMapping "
-                                       + "implementation must contain a constructor that accepts an Element object for "
-                                       + "configuration data.");
-                       throw new NameIdentifierMappingException("Failed to instantiate a Name Identifier Mapping.");
-
-               } catch (Exception e) {
-                       log.error("Failed to instantiate a Name Identifier Mapping: " + e + ":" + e.getCause());
-                       throw new NameIdentifierMappingException("Failed to instantiate a Name Identifier Mapping: " + e);
-
-               }
-
-       }
-
-       /**
-        * Maps a SAML Name Identifier to a local principal using the appropriate registered mapping.
-        * 
-        * @param nameId
-        *            the SAML Name Identifier that should be converted
-        * @param sProv
-        *            the provider initiating the request
-        * @param idProv
-        *            the provider handling the request
-        * @return the local principal
-        * @throws NameIdentifierMappingException
-        *             If the {@link NameMapper}encounters an internal error
-        * @throws InvalidNameIdentifierException
-        *             If the {@link SAMLNameIdentifier}contains invalid data
-        */
-       public Principal getPrincipal(SAMLNameIdentifier nameId, ServiceProvider sProv, IdentityProvider idProv)
-                       throws NameIdentifierMappingException, InvalidNameIdentifierException {
-
-               NameIdentifierMapping mapping = null;
-               log.debug("Name Identifier format: (" + nameId.getFormat() + ").");
-               try {
-                       mapping = getNameIdentifierMapping(new URI(nameId.getFormat()));
-               } catch (URISyntaxException e) {
-                       log.error("Invalid Name Identifier format.");
-               }
-               if (mapping == null) { throw new NameIdentifierMappingException("Name Identifier format not registered."); }
-               return mapping.getPrincipal(nameId, sProv, idProv);
-       }
-
-       /**
-        * Maps a local principal to a SAML Name Identifier using the mapping registered under a given id.
-        * 
-        * @param id
-        *            the id under which the effective <code>NameIdentifierMapping</code> is registered
-        * @param principal
-        *            the principal to map
-        * @param sProv
-        *            the provider initiating the request
-        * @param idProv
-        *            the provider handling the request
-        * @return
-        * @throws NameIdentifierMappingException
-        *             If the <code>NameMapper</code> encounters an internal error
-        */
-       public SAMLNameIdentifier getNameIdentifier(String id, LocalPrincipal principal, ServiceProvider sProv,
-                       IdentityProvider idProv) throws NameIdentifierMappingException {
-
-               NameIdentifierMapping mapping = getNameIdentifierMappingById(id);
-
-               if (mapping == null) { throw new NameIdentifierMappingException("Name Identifier id not registered."); }
-               return mapping.getNameIdentifier(principal, sProv, idProv);
-       }
-
-       /**
-        * Cleanup resources that won't be released when this object is garbage-collected
-        */
-       public void destroy() {
-
-               Iterator mappingIterator = byFormat.values().iterator();
-               while (mappingIterator.hasNext()) {
-                       ((NameIdentifierMapping) mappingIterator.next()).destroy();
-               }
-       }
-}
\ No newline at end of file
index 7b7628e..576029d 100644 (file)
@@ -45,7 +45,6 @@ import edu.internet2.middleware.shibboleth.aa.arp.ArpProcessingException;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeResolver;
 import edu.internet2.middleware.shibboleth.artifact.ArtifactMapper;
 import edu.internet2.middleware.shibboleth.common.Credential;
-import edu.internet2.middleware.shibboleth.common.NameMapper;
 import edu.internet2.middleware.shibboleth.common.RelyingParty;
 import edu.internet2.middleware.shibboleth.common.RelyingPartyMapper;
 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
@@ -63,7 +62,6 @@ public class IdPProtocolSupport implements MetadataProvider {
        private static Logger log = Logger.getLogger(IdPProtocolSupport.class.getName());
        private Logger transactionLog;
        private IdPConfig config;
-       private NameMapper nameMapper;
        private RelyingPartyMapper spMapper;
        private ArpEngine arpEngine;
        private AttributeResolver resolver;
@@ -72,13 +70,11 @@ public class IdPProtocolSupport implements MetadataProvider {
        private TrustEngine<X509EntityCredential> trust = new ShibbolethTrustEngine();
        private ChainingMetadataProvider wrappedMetadataProvider = new ChainingMetadataProvider();
 
-       IdPProtocolSupport(IdPConfig config, Logger transactionLog, NameMapper nameMapper, RelyingPartyMapper spMapper,
-                       ArpEngine arpEngine, AttributeResolver resolver, ArtifactMapper artifactMapper)
-                       throws ShibbolethConfigurationException {
+       IdPProtocolSupport(IdPConfig config, Logger transactionLog, RelyingPartyMapper spMapper, ArpEngine arpEngine,
+                       AttributeResolver resolver, ArtifactMapper artifactMapper) throws ShibbolethConfigurationException {
 
                this.transactionLog = transactionLog;
                this.config = config;
-               this.nameMapper = nameMapper;
                this.spMapper = spMapper;
                spMapper.setMetadata(this);
                this.arpEngine = arpEngine;
@@ -99,11 +95,6 @@ public class IdPProtocolSupport implements MetadataProvider {
                return config;
        }
 
-       public NameMapper getNameMapper() {
-
-               return nameMapper;
-       }
-
        public RelyingPartyMapper getRelyingPartyMapper() {
 
                return spMapper;
index f26a074..6f46be8 100644 (file)
@@ -47,9 +47,6 @@ import edu.internet2.middleware.shibboleth.artifact.ArtifactMapper;
 import edu.internet2.middleware.shibboleth.artifact.ArtifactMapperFactory;
 import edu.internet2.middleware.shibboleth.artifact.provider.MemoryArtifactMapper;
 import edu.internet2.middleware.shibboleth.common.Credentials;
-import edu.internet2.middleware.shibboleth.common.NameIdentifierMapping;
-import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
-import edu.internet2.middleware.shibboleth.common.NameMapper;
 import edu.internet2.middleware.shibboleth.common.RelyingPartyMapper;
 import edu.internet2.middleware.shibboleth.common.RelyingPartyMapperException;
 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
@@ -109,19 +106,6 @@ public class IdPResponder extends HttpServlet {
                        // Load global configuration properties
                        configuration = new IdPConfig(idPConfig.getDocumentElement());
 
-                       // Load name mappings
-                       NameMapper nameMapper = new NameMapper();
-                       itemElements = idPConfig.getDocumentElement().getElementsByTagNameNS(
-                                       NameIdentifierMapping.mappingNamespace, "NameMapping");
-
-                       for (int i = 0; i < itemElements.getLength(); i++) {
-                               try {
-                                       nameMapper.addNameMapping((Element) itemElements.item(i));
-                               } catch (NameIdentifierMappingException e) {
-                                       log.error("Name Identifier mapping could not be loaded: " + e);
-                               }
-                       }
-
                        // Load signing credentials
                        itemElements = idPConfig.getDocumentElement().getElementsByTagNameNS(Credentials.credentialsNamespace,
                                        "Credentials");
@@ -185,8 +169,8 @@ public class IdPResponder extends HttpServlet {
                        }
 
                        // Load protocol handlers and support library
-                       protocolSupport = new IdPProtocolSupport(configuration, transactionLog, nameMapper, spMapper, arpEngine,
-                                       resolver, artifactMapper);
+                       protocolSupport = new IdPProtocolSupport(configuration, transactionLog, spMapper, arpEngine, resolver,
+                                       artifactMapper);
                        itemElements = idPConfig.getDocumentElement().getElementsByTagNameNS(IdPConfig.configNameSpace,
                                        "ProtocolHandler");