Move hard-coded test principal into its own NameIdentifierMapping implementation...
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Sat, 18 Sep 2004 23:04:06 +0000 (23:04 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Sat, 18 Sep 2004 23:04:06 +0000 (23:04 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1084 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/AAServlet.java
src/edu/internet2/middleware/shibboleth/common/NameMapper.java

index 8e28884..505062c 100755 (executable)
@@ -74,7 +74,6 @@ import edu.internet2.middleware.shibboleth.aa.arp.ArpEngine;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpException;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeResolver;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeResolverException;
-import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.Credential;
 import edu.internet2.middleware.shibboleth.common.Credentials;
 import edu.internet2.middleware.shibboleth.common.InvalidNameIdentifierException;
@@ -296,13 +295,8 @@ public class AAServlet extends TargetFederationComponent {
 
                        Principal principal = null;
                        try {
-                               // for testing
-                               if (attributeQuery.getSubject().getName().getFormat().equals("urn:mace:shibboleth:test:nameIdentifier")) {
-                                       principal = new AuthNPrincipal("test-handle");
-                               } else {
-                                       principal = nameMapper.getPrincipal(attributeQuery.getSubject().getName(), relyingParty,
+                               principal = nameMapper.getPrincipal(attributeQuery.getSubject().getName(), relyingParty,
                                                        relyingParty.getIdentityProvider());
-                               }
                                log.info("Request is for principal (" + principal.getName() + ").");
 
                        } catch (InvalidNameIdentifierException invalidNameE) {
index 61bbf09..d583ccd 100644 (file)
@@ -2,26 +2,25 @@
  * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
  * All rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted
  * provided that the following conditions are met: Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution, if any, must include the following acknowledgment: "This product includes
- * software developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2
- * Project. Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
- * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2,
- * nor the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
- * products derived from this software without specific prior written permission. For written permission, please
- * contact shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2,
- * UCAID, or the University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name,
- * without prior written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS
- * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
- * NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS
- * WITH LICENSEE. IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED
- * INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution, if any, must include the following acknowledgment: "This product includes software
+ * developed by the University Corporation for Advanced Internet Development <http://www.ucaid.edu> Internet2 Project.
+ * Alternately, this acknowledegement may appear in the software itself, if and wherever such third-party
+ * acknowledgments normally appear. Neither the name of Shibboleth nor the names of its contributors, nor Internet2, nor
+ * the University Corporation for Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote
+ * products derived from this software without specific prior written permission. For written permission, please contact
+ * shibboleth@shibboleth.org Products derived from this software may not be called Shibboleth, Internet2, UCAID, or the
+ * University Corporation for Advanced Internet Development, nor may Shibboleth appear in their name, without prior
+ * written permission of the University Corporation for Advanced Internet Development. THIS SOFTWARE IS PROVIDED BY THE
+ * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE
+ * DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE, ACCURACY, AND EFFORT IS WITH LICENSEE. IN NO
+ * EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC.
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 package edu.internet2.middleware.shibboleth.common;
@@ -101,8 +100,8 @@ public class NameMapper {
        }
 
        /**
-        * Constructs a {@link NameIdentifierMapping}based on XML configuration data and adds it to this
-        * {@link NameMapper}, registering it according to its format.
+        * 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}
@@ -179,9 +178,15 @@ public class NameMapper {
         * @return the mapping or <code>null</code> if no mapping is registered for the given format
         */
        public NameIdentifierMapping getNameIdentifierMapping(URI format) {
+               
+               if (format.toString().equals("urn:mace:shibboleth:test:nameIdentifier")) {
+                       return new TestNameIdentifierMapping();
+               }
+               
                if (!initialized) {
                        return defaultMapping;
                }
+               
                return (NameIdentifierMapping) byFormat.get(format);
        }
 
@@ -249,4 +254,47 @@ public class NameMapper {
                }
        }
 
+       /**
+        * <code>NameIdentifierMapping</code> implement that always maps to the same principal name.  Used for testing.
+        */
+       public class TestNameIdentifierMapping implements NameIdentifierMapping {
+
+               private TestNameIdentifierMapping() {
+                       //Constructor to prevent others from creating this class
+               }
+               
+               /* (non-Javadoc)
+                * 
+                * @see edu.internet2.middleware.shibboleth.common.NameIdentifierMapping#getNameIdentifierFormat()
+                */
+               public URI getNameIdentifierFormat() {
+                       try {
+                               return new URI("urn:mace:shibboleth:test:nameIdentifier");
+                       } catch (URISyntaxException e) {
+                               log.error("Name Mapping \"format\" is not a valid URI: " + e);
+                               throw new RuntimeException("Internal error: Encountered an error generating a standard URI.");
+                       }
+               }
+
+               /*
+                * (non-Javadoc)
+                * 
+                * @see edu.internet2.middleware.shibboleth.common.NameIdentifierMapping#getPrincipal(org.opensaml.SAMLNameIdentifier,
+                *      edu.internet2.middleware.shibboleth.common.ServiceProvider,
+                *      edu.internet2.middleware.shibboleth.common.IdentityProvider)
+                */
+               public AuthNPrincipal getPrincipal(SAMLNameIdentifier nameId, ServiceProvider sProv, IdentityProvider idProv) throws NameIdentifierMappingException, InvalidNameIdentifierException {
+                       log.info("Request references built-in test principal.");
+                       return new AuthNPrincipal("test-handle");
+               }
+
+               /*
+                * (non-Javadoc)
+                * 
+                * @see edu.internet2.middleware.shibboleth.common.NameIdentifierMapping#destroy()
+                */
+               public void destroy() {
+                       //Nothing to do
+                       }
+               }
 }