Allow AA to respond about transparent handles while decoding opaque ones.
authorcantor <cantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 3 Oct 2003 19:35:08 +0000 (19:35 +0000)
committercantor <cantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 3 Oct 2003 19:35:08 +0000 (19:35 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@767 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/hs/HandleRepositoryFactory.java
src/edu/internet2/middleware/shibboleth/hs/provider/IdentityHandleRepository.java

index 82335db..6f872e0 100644 (file)
@@ -66,32 +66,40 @@ public class HandleRepositoryFactory {
 
        private static Logger log = Logger.getLogger(HandleRepositoryFactory.class.getName());
 
-       public static HandleRepository getInstance(Properties props) throws HandleRepositoryException {
+    public static HandleRepository getInstance(String className, Properties props) throws HandleRepositoryException {
+        if (className == null) {
+            throw new HandleRepositoryException("No Handle Repository implementation specified.");
+        }
+        try {
+            Class implementorClass = Class.forName(className);
+            Class[] params = new Class[] { Properties.class };
+            Constructor implementorConstructor = implementorClass.getConstructor(params);
+            Object[] args = new Object[] { props };
+            log.debug("Initializing Handle Repository of type (" + implementorClass.getName() + ").");
+            return (HandleRepository) implementorConstructor.newInstance(args);
 
-               if (props.getProperty("edu.internet2.middleware.shibboleth.hs.HandleRepository.implementation") == null) {
-                       throw new HandleRepositoryException("No Handle Repository implementaiton specified.");
-               }
-               try {
-                       Class implementorClass =
-                               Class.forName(
-                                       props.getProperty("edu.internet2.middleware.shibboleth.hs.HandleRepository.implementation"));
-                       Class[] params = new Class[] { Properties.class };
-                       Constructor implementorConstructor = implementorClass.getConstructor(params);
-                       Object[] args = new Object[] { props };
-                       log.debug("Initializing Handle Repository of type (" + implementorClass.getName() + ").");
-                       return (HandleRepository) implementorConstructor.newInstance(args);
+        } catch (NoSuchMethodException nsme) {
+            log.error(
+                "Failed to instantiate an Handle Repository: HandleRepository "
+                    + "implementation must contain a constructor that accepts a Properties bundle for "
+                    + "configuration data.");
+            throw new HandleRepositoryException("Failed to instantiate a Handle Repository.");
+        } catch (Exception e) {
 
-               } catch (NoSuchMethodException nsme) {
-                       log.error(
-                               "Failed to instantiate an Handle Repository: HandleRepository "
-                                       + "implementation must contain a constructor that accepts a Properties bundle for "
-                                       + "configuration data.");
-                       throw new HandleRepositoryException("Failed to instantiate a Handle Repository.");
-               } catch (Exception e) {
+            log.error("Failed to instantiate a Handle Repository: " + e + ":" + e.getCause());
+            throw new HandleRepositoryException("Failed to instantiate a Handle Repository: " + e);
 
-                       log.error("Failed to instantiate a Handle Repository: " + e + ":" + e.getCause());
-                       throw new HandleRepositoryException("Failed to instantiate a Handle Repository: " + e);
+        }
+    }
 
+       public static HandleRepository getInstance(Properties props) throws HandleRepositoryException {
+
+               if (props.getProperty("edu.internet2.middleware.shibboleth.hs.HandleRepository.implementation") == null) {
+                       throw new HandleRepositoryException("No Handle Repository implementation specified.");
                }
+               return getInstance(
+            props.getProperty("edu.internet2.middleware.shibboleth.hs.HandleRepository.implementation"),
+            props
+            );
        }
 }
index eed9f06..0b8b18f 100644 (file)
@@ -57,6 +57,7 @@ import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.Constants;
 import edu.internet2.middleware.shibboleth.hs.HandleRepository;
 import edu.internet2.middleware.shibboleth.hs.HandleRepositoryException;
+import edu.internet2.middleware.shibboleth.hs.HandleRepositoryFactory;
 import edu.internet2.middleware.shibboleth.hs.InvalidHandleException;
 
 /**
@@ -68,17 +69,22 @@ public class IdentityHandleRepository extends BaseHandleRepository implements Ha
 
        private static Logger log = Logger.getLogger(IdentityHandleRepository.class.getName());
     
-    private String format;
+    private String format = null;
+    private HandleRepository generator = null;
 
        public IdentityHandleRepository(Properties properties) throws HandleRepositoryException {
                super(properties);
-        if (properties.getProperty("edu.internet2.middleware.shibboleth.hs.IdentityHandleRepository.formatURI")
-            != null) {
-            format = properties.getProperty(
-                        "edu.internet2.middleware.shibboleth.hs.IdentityHandleRepository.formatURI",
-                        null);
-            if (format == null)
-                format = Constants.SHIB_NAMEID_FORMAT_URI;
+        format = properties.getProperty(
+            "edu.internet2.middleware.shibboleth.hs.IdentityHandleRepository.formatURI",
+            Constants.SHIB_NAMEID_FORMAT_URI
+            );
+        String className = properties.getProperty(
+            "edu.internet2.middleware.shibboleth.hs.IdentityHandleRepository.handleGenerator",
+            null
+            );
+        if (className != null) {
+            generator = HandleRepositoryFactory.getInstance(className, properties);
+            log.debug("Handle generation will be implemented by (" + className +  ")");
         }
         log.debug("Attribute Query Handle TTL set to (" + handleTTL + ") milliseconds.");
        }
@@ -87,6 +93,11 @@ public class IdentityHandleRepository extends BaseHandleRepository implements Ha
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getHandle(Principal)
         */
        public String getHandle(AuthNPrincipal principal, StringBuffer format) throws HandleRepositoryException {
+        //Delegate handle creation?
+        if (generator != null) {
+            return generator.getHandle(principal, format);
+        }
+        
                if (principal == null || format == null) {
                        log.error("A principal and format buffer must be supplied for Attribute Query Handle creation.");
                        throw new IllegalArgumentException("A principal and format buffer must be supplied for Attribute Query Handle creation.");
@@ -102,9 +113,8 @@ public class IdentityHandleRepository extends BaseHandleRepository implements Ha
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getPrincipal(String)
         */
        public AuthNPrincipal getPrincipal(String handle, String format) throws HandleRepositoryException, InvalidHandleException {
-        if (!this.format.equals(format)) {
-            log.debug("This Repository does not understand handles with a format URI of " + (format==null ? "null" : format));
-            throw new InvalidHandleException("This Repository does not understand handles with a format URI of " + (format==null ? "null" : format));
+        if (this.format.equals(Constants.SHIB_NAMEID_FORMAT_URI)) {
+            return generator.getPrincipal(handle, format);
         }
         
         return new AuthNPrincipal(handle);