Refactored resolver attribute classes to eliminate duplicate code introduced by SCT...
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 31 Aug 2006 19:25:21 +0000 (19:25 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 31 Aug 2006 19:25:21 +0000 (19:25 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2005 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/BaseAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/CompositeAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/FormattedAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/MappedAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/PersistentIDAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/RegExAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/SAML2PersistentID.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/ScriptletAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/SimpleAttributeDefinition.java
src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/SimpleBaseAttributeDefinition.java [deleted file]

index 4579106..b2881a6 100644 (file)
 
 package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
 
+import java.security.Principal;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
 import org.apache.log4j.Logger;
 import org.w3c.dom.Element;
 
 import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn;
+import edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugInException;
 import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
 
@@ -32,11 +44,14 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
 
 public abstract class BaseAttributeDefinition extends BaseResolutionPlugIn implements AttributeDefinitionPlugIn {
 
-       /** The time, in seconds, for which attribute created from this definition should be valid. */
-       protected long lifeTime = -1;
        public final static String SHIB_ATTRIBUTE_NAMESPACE_URI = "urn:mace:shibboleth:1.0:attributeNamespace:uri";
        protected String namespace = SHIB_ATTRIBUTE_NAMESPACE_URI;
 
+       protected ValueHandler valueHandler;
+       protected String connectorMapping;
+       /** The time, in seconds, for which attribute created from this definition should be valid. */
+       protected long lifeTime = -1;
+
        private static Logger log = Logger.getLogger(BaseAttributeDefinition.class.getName());
 
        protected BaseAttributeDefinition(Element e) throws ResolutionPlugInException {
@@ -57,17 +72,146 @@ public abstract class BaseAttributeDefinition extends BaseResolutionPlugIn imple
                if (namespaceSpec != null && !namespaceSpec.equals("")) {
                        namespace = namespaceSpec;
                }
+
+               // Parse source name
+               String sourceName = e.getAttribute("sourceName");
+               if (sourceName == null || sourceName.equals("")) {
+                       int index = getId().lastIndexOf("#");
+                       if (index < 0) {
+                               index = getId().lastIndexOf(":");
+                               int slashIndex = getId().lastIndexOf("/");
+                               if (slashIndex > index) {
+                                       index = slashIndex;
+                               }
+                       }
+                       connectorMapping = getId().substring(index + 1);
+               } else {
+                       connectorMapping = sourceName;
+               }
+
+               log.debug("Mapping attribute to name (" + connectorMapping + ") in connector.");
+
+               // Load a value handler
+               String valueHandlerSpec = e.getAttribute("valueHandler");
+
+               if (valueHandlerSpec != null && !valueHandlerSpec.equals("")) {
+                       try {
+                               Class handlerClass = Class.forName(valueHandlerSpec);
+                               valueHandler = (ValueHandler) handlerClass.newInstance();
+                       } catch (ClassNotFoundException cnfe) {
+                               log.error("Value Handler implementation specified for attribute (" + getId() + ") cannot be found: "
+                                               + cnfe);
+                               throw new ResolutionPlugInException("Value Handler implementation specified for attribute (" + getId()
+                                               + ") cannot be found.");
+                       } catch (Exception oe) {
+                               log.error("Value Handler implementation specified for attribute (" + getId()
+                                               + ") coudl not be loaded: " + oe);
+                               throw new ResolutionPlugInException("Value Handler implementation specified for attribute (" + getId()
+                                               + ") could not be loaded.");
+                       }
+               }
+
+               if (valueHandler != null) {
+                       log.debug("Custom Value Handler enabled for attribute (" + getId() + ").");
+               }
        }
 
        /**
-        * Should be run by all sublcasses during resolution.
+        * Should be run by all sublcasses during resolution. Doesn't do resolution in and of itself.
         */
-       protected void standardProcessing(ResolverAttribute attr) {
+       public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
+                       Dependencies depends) throws ResolutionPlugInException {
 
                if (lifeTime != -1) {
-                       attr.setLifetime(lifeTime);
+                       attribute.setLifetime(lifeTime);
+               }
+
+               attribute.setNamespace(namespace);
+
+               if (valueHandler != null) {
+                       attribute.registerValueHandler(valueHandler);
+               }
+
+       }
+
+       protected String convertToString(Object value) {
+
+               /*
+                * This was inspired by the fact that certain attributes (such as userPassword, when read using JNDI) are
+                * returned from data connectors as byte [] rather than String, and doing a .toString() returns something like
+                * B[@aabljadj, which is a reference to the array, rather than the string value.
+                */
+               if (value instanceof byte[]) { return new String((byte[]) value); }
+               if (value instanceof String) { return (String) value; }
+               return value.toString();
+       }
+
+       protected Collection<Object> getAllValuesFromConnectorDeps(Dependencies depends) {
+
+               Set<Object> results = new LinkedHashSet<Object>();
+
+               Iterator connectorDependIt = connectorDependencyIds.iterator();
+               while (connectorDependIt.hasNext()) {
+                       Attributes attrs = depends.getConnectorResolution((String) connectorDependIt.next());
+                       if (attrs != null) {
+                               Attribute attr = attrs.get(connectorMapping);
+                               if (attr != null) {
+                                       log.debug("Found value(s) for attribute (" + getId() + ").");
+                                       try {
+                                               NamingEnumeration valuesEnum = attr.getAll();
+                                               while (valuesEnum.hasMore()) {
+                                                       results.add(valuesEnum.next());
+                                               }
+                                       } catch (NamingException e) {
+                                               log.error("An problem was encountered resolving the dependencies of attribute (" + getId()
+                                                               + "): " + e);
+                                       }
+                               }
+                       }
                }
 
-               attr.setNamespace(namespace);
+               if (results.isEmpty()) {
+                       log.debug("A connector dependency of attribute (" + getId() + ") supplied no values.");
+               }
+               return results;
        }
+
+       protected Collection<Object> getAllValuesFromAttributeDeps(Dependencies depends) {
+
+               Set<Object> results = new LinkedHashSet<Object>();
+
+               Iterator attrDependIt = attributeDependencyIds.iterator();
+               while (attrDependIt.hasNext()) {
+                       ResolverAttribute attribute = depends.getAttributeResolution((String) attrDependIt.next());
+                       if (attribute != null) {
+                               log.debug("Found value(s) for attribute (" + getId() + ").");
+                               for (Iterator iterator = attribute.getValues(); iterator.hasNext();) {
+                                       results.add(iterator.next());
+                               }
+                       } else {
+                               log.error("An attribute dependency of attribute (" + getId()
+                                               + ") was not included in the dependency chain.");
+                       }
+               }
+
+               if (results.isEmpty()) {
+                       log.debug("An attribute dependency of attribute (" + getId() + ") supplied no values.");
+               }
+               return results;
+       }
+
+       protected Collection<Object> getValuesFromAllDeps(ResolverAttribute attribute, Principal principal,
+                       String requester, Dependencies depends) throws ResolutionPlugInException {
+
+               log.debug("Resolving attribute: (" + getId() + ")");
+               Set<Object> results = new LinkedHashSet<Object>();
+               if (!connectorDependencyIds.isEmpty()) {
+                       results.addAll(getAllValuesFromConnectorDeps(depends));
+               }
+               if (!attributeDependencyIds.isEmpty()) {
+                       results.addAll(getAllValuesFromAttributeDeps(depends));
+               }
+               return results;
+       }
+
 }
\ No newline at end of file
index 7cb4369..6bea384 100644 (file)
@@ -66,7 +66,7 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
 /**
  * @author Walter Hoehn
  */
-public class CompositeAttributeDefinition extends SimpleBaseAttributeDefinition implements AttributeDefinitionPlugIn {
+public class CompositeAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
 
        private static Logger log = Logger.getLogger(CompositeAttributeDefinition.class.getName());
 
@@ -77,7 +77,7 @@ public class CompositeAttributeDefinition extends SimpleBaseAttributeDefinition
        private String[] sourceNames;
 
        // Names of source attributes in a Set for convenience of checking membership
-       private Set sourceNamesSet;
+       private Set<String> sourceNamesSet;
 
        // Number of values that each source attribute has (must be same for all attributes)
        private int valueCount = -1;
@@ -101,12 +101,12 @@ public class CompositeAttributeDefinition extends SimpleBaseAttributeDefinition
 
                        // We assume space or comma as separators
                        StringTokenizer st = new StringTokenizer(orderedSourceNames, " ,");
-                       ArrayList sourceNamesList = new ArrayList();
+                       ArrayList<String> sourceNamesList = new ArrayList<String>();
                        while (st.hasMoreTokens()) {
                                String token = st.nextToken().trim();
                                if (token.length() > 0) sourceNamesList.add(token);
                        }
-                       sourceNamesSet = new HashSet();
+                       sourceNamesSet = new HashSet<String>();
                        sourceNamesSet.addAll(sourceNamesList);
                        sourceNames = (String[]) sourceNamesList.toArray(new String[0]);
 
@@ -212,6 +212,8 @@ public class CompositeAttributeDefinition extends SimpleBaseAttributeDefinition
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
+               super.resolve(attribute, principal, requester, responder, depends);
+
                // Collect attribute values from dependencies
                BasicAttributes attributes = new BasicAttributes();
                addAttributesFromConnectors(depends, attributes);
@@ -250,11 +252,6 @@ public class CompositeAttributeDefinition extends SimpleBaseAttributeDefinition
                        }
                }
 
-               standardProcessing(attribute);
-
-               if (valueHandler != null) {
-                       attribute.registerValueHandler(valueHandler);
-               }
                attribute.setResolved();
        }
 
index b2ff002..3316668 100644 (file)
@@ -49,7 +49,7 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
  * @author <a href="mailto:vgoenka@sungardsct.com">Vishal Goenka </a>
  */
 
-public class FormattedAttributeDefinition extends SimpleBaseAttributeDefinition implements AttributeDefinitionPlugIn {
+public class FormattedAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
 
        private static Logger log = Logger.getLogger(FormattedAttributeDefinition.class.getName());
 
@@ -106,15 +106,15 @@ public class FormattedAttributeDefinition extends SimpleBaseAttributeDefinition
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
-               standardProcessing(attribute);
+               super.resolve(attribute, principal, requester, responder, depends);
 
                // Resolve all dependencies to arrive at the source values (unformatted)
-               Collection results = resolveDependencies(attribute, principal, requester, depends);
+               Collection results = getValuesFromAllDeps(attribute, principal, requester, depends);
 
                Iterator resultsIt = results.iterator();
 
                while (resultsIt.hasNext()) {
-                       String value = getString(resultsIt.next());
+                       String value = convertToString(resultsIt.next());
                        if (skipFormatting) attribute.addValue(value);
                        else {
                                try {
index 858e4ac..33b1099 100644 (file)
@@ -50,29 +50,29 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
  * faculty, student, staff and member. A potential mapping may look as follows:
  * 
  * <pre>
- * 
- *  
  *   
  *    
  *     
  *      
  *       
  *        
- *              &lt;ValueMap value=&quot;affiliate&quot;  keyset=&quot;guest, prospect[a-z ]*, friends&quot;                        /&gt;
- *              &lt;ValueMap value=&quot;alum&quot;       keyset=&quot;alum, alumni&quot;                                           /&gt;
- *              &lt;ValueMap value=&quot;employee&quot;   keyset=&quot;employee&quot;                                               /&gt;
- *              &lt;ValueMap value=&quot;faculty&quot;    keyset=&quot;faculty&quot;                                                /&gt;
- *              &lt;ValueMap value=&quot;member&quot;     keyset=&quot;student, faculty, admin[a-z ]*, [a-z ]*admin, employee&quot; /&gt;
- *              &lt;ValueMap value=&quot;staff&quot;      keyset=&quot;admin[a-z ]*, [a-z ]*admin&quot;                             /&gt;
- *              &lt;ValueMap value=&quot;student&quot;    keyset=&quot;student&quot;                                                /&gt;
+ *         
+ *          
+ *                &lt;ValueMap value=&quot;affiliate&quot;  keyset=&quot;guest, prospect[a-z ]*, friends&quot;                        /&gt;
+ *                &lt;ValueMap value=&quot;alum&quot;       keyset=&quot;alum, alumni&quot;                                           /&gt;
+ *                &lt;ValueMap value=&quot;employee&quot;   keyset=&quot;employee&quot;                                               /&gt;
+ *                &lt;ValueMap value=&quot;faculty&quot;    keyset=&quot;faculty&quot;                                                /&gt;
+ *                &lt;ValueMap value=&quot;member&quot;     keyset=&quot;student, faculty, admin[a-z ]*, [a-z ]*admin, employee&quot; /&gt;
+ *                &lt;ValueMap value=&quot;staff&quot;      keyset=&quot;admin[a-z ]*, [a-z ]*admin&quot;                             /&gt;
+ *                &lt;ValueMap value=&quot;student&quot;    keyset=&quot;student&quot;                                                /&gt;
+ *           
+ *          
  *         
  *        
  *       
  *      
  *     
  *    
- *   
- *  
  * </pre>
  * 
  * This many-to-many mapping will result in a Luminis role of 'student' to imply eduPersonAffiliation values of [member,
@@ -97,7 +97,7 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
  * @author <a href="mailto:vgoenka@sungardsct.com">Vishal Goenka </a>
  */
 
-public class MappedAttributeDefinition extends SimpleBaseAttributeDefinition implements AttributeDefinitionPlugIn {
+public class MappedAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
 
        private static Logger log = Logger.getLogger(MappedAttributeDefinition.class.getName());
 
@@ -152,10 +152,10 @@ public class MappedAttributeDefinition extends SimpleBaseAttributeDefinition imp
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
-               standardProcessing(attribute);
+               super.resolve(attribute, principal, requester, responder, depends);
 
                // Resolve all dependencies to arrive at the source values (unformatted)
-               Collection results = resolveDependencies(attribute, principal, requester, depends);
+               Collection results = getValuesFromAllDeps(attribute, principal, requester, depends);
 
                Iterator resultsIt = results.iterator();
 
@@ -164,7 +164,7 @@ public class MappedAttributeDefinition extends SimpleBaseAttributeDefinition imp
 
                while (resultsIt.hasNext()) {
                        // Read the source value (prior to mapping)
-                       String valueExactCase = getString(resultsIt.next());
+                       String valueExactCase = convertToString(resultsIt.next());
                        String value = valueExactCase;
                        boolean mapped = false;
 
index e7af68d..0c5e036 100644 (file)
@@ -166,6 +166,8 @@ public class PersistentIDAttributeDefinition extends BaseAttributeDefinition imp
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
+               super.resolve(attribute, principal, requester, responder, depends);
+
                log.debug("Resolving attribute: (" + getId() + ")");
 
                if (requester == null || requester.equals("")) {
@@ -231,8 +233,6 @@ public class PersistentIDAttributeDefinition extends BaseAttributeDefinition imp
                        return;
                }
 
-               standardProcessing(attribute);
-
                // Hash the data together to produce the persistent ID.
                try {
                        MessageDigest md = MessageDigest.getInstance("SHA");
index c435858..aaafcb3 100644 (file)
@@ -53,7 +53,7 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
  * expression substitution.
  */
 
-public class RegExAttributeDefinition extends SimpleBaseAttributeDefinition implements AttributeDefinitionPlugIn {
+public class RegExAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
 
        private static Logger log = Logger.getLogger(RegExAttributeDefinition.class.getName());
 
@@ -110,15 +110,15 @@ public class RegExAttributeDefinition extends SimpleBaseAttributeDefinition impl
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
-               standardProcessing(attribute);
+               super.resolve(attribute, principal, requester, responder, depends);
 
                // Resolve all dependencies to arrive at the source values (unformatted)
-               Collection results = resolveDependencies(attribute, principal, requester, depends);
+               Collection results = getValuesFromAllDeps(attribute, principal, requester, depends);
 
                Iterator resultsIt = results.iterator();
 
                while (resultsIt.hasNext()) {
-                       String value = getString(resultsIt.next());
+                       String value = convertToString(resultsIt.next());
                        Matcher m = pattern.matcher(value);
                        try {
                                if (partialMatch || m.matches()) attribute.addValue(m.replaceAll(replacement));
index 7574614..4a87eb5 100644 (file)
@@ -161,6 +161,8 @@ public class SAML2PersistentID extends BaseAttributeDefinition implements Attrib
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
+               super.resolve(attribute, principal, requester, responder, depends);
+
                log.debug("Resolving attribute: (" + getId() + ")");
 
                if (requester == null || requester.equals("")) {
@@ -232,8 +234,6 @@ public class SAML2PersistentID extends BaseAttributeDefinition implements Attrib
                        return;
                }
 
-               standardProcessing(attribute);
-
                // Hash the data together to produce the persistent ID.
                try {
                        MessageDigest md = MessageDigest.getInstance("SHA");
index f58b93f..a899a5e 100644 (file)
@@ -94,9 +94,9 @@ public class ScriptletAttributeDefinition extends BaseAttributeDefinition implem
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
-               try {
+               super.resolve(attribute, principal, requester, responder, depends);
 
-                       standardProcessing(attribute);
+               try {
 
                        Interpreter beanShellInterpreter = loadBshInterpreter();
 
index 58f6b16..ac566cc 100644 (file)
@@ -17,7 +17,6 @@
 package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
 
 import java.security.Principal;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Set;
@@ -36,12 +35,10 @@ import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
  * 
  * @author Walter Hoehn (wassa@columbia.edu)
  */
-public class SimpleAttributeDefinition extends SimpleBaseAttributeDefinition implements AttributeDefinitionPlugIn {
+public class SimpleAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
 
        private static Logger log = Logger.getLogger(SimpleAttributeDefinition.class.getName());
-       private String connectorMapping;
        private String smartScope;
-       private ValueHandler valueHandler;
        private boolean allowEmpty = false;
        private boolean downCase = false;
 
@@ -53,24 +50,6 @@ public class SimpleAttributeDefinition extends SimpleBaseAttributeDefinition imp
 
                super(e);
 
-               // Parse source name
-               String sourceName = e.getAttribute("sourceName");
-               if (sourceName == null || sourceName.equals("")) {
-                       int index = getId().lastIndexOf("#");
-                       if (index < 0) {
-                               index = getId().lastIndexOf(":");
-                               int slashIndex = getId().lastIndexOf("/");
-                               if (slashIndex > index) {
-                                       index = slashIndex;
-                               }
-                       }
-                       connectorMapping = getId().substring(index + 1);
-               } else {
-                       connectorMapping = sourceName;
-               }
-
-               log.debug("Mapping attribute to name (" + connectorMapping + ") in connector.");
-
                // Configure smart scoping
                String smartScopingSpec = e.getAttribute("smartScope");
                if (smartScopingSpec != null && !smartScopingSpec.equals("")) {
@@ -82,33 +61,9 @@ public class SimpleAttributeDefinition extends SimpleBaseAttributeDefinition imp
                        log.debug("Smart Scoping disabled for attribute (" + getId() + ").");
                }
 
-               // Load a value handler
-               String valueHandlerSpec = e.getAttribute("valueHandler");
-
-               if (valueHandlerSpec != null && !valueHandlerSpec.equals("")) {
-                       if (smartScope == null) {
-                               try {
-                                       Class handlerClass = Class.forName(valueHandlerSpec);
-                                       valueHandler = (ValueHandler) handlerClass.newInstance();
-                               } catch (ClassNotFoundException cnfe) {
-                                       log.error("Value Handler implementation specified for attribute (" + getId()
-                                                       + ") cannot be found: " + cnfe);
-                                       throw new ResolutionPlugInException("Value Handler implementation specified for attribute ("
-                                                       + getId() + ") cannot be found.");
-                               } catch (Exception oe) {
-                                       log.error("Value Handler implementation specified for attribute (" + getId()
-                                                       + ") coudl not be loaded: " + oe);
-                                       throw new ResolutionPlugInException("Value Handler implementation specified for attribute ("
-                                                       + getId() + ") could not be loaded.");
-                               }
-                       } else {
-                               log.error("Specification of \"valueHandler\' cannot be used in combination with \"smartScope\". "
-                                               + " Ignoring Value Handler for attribute (" + getId() + ").");
-                       }
-               }
-
-               if (valueHandler != null) {
-                       log.debug("Custom Value Handler enabled for attribute (" + getId() + ").");
+               if (smartScope != null && valueHandler != null) {
+                       log.error("Specification of \"valueHandler\' cannot be used in combination with \"smartScope\". "
+                                       + " Ignoring Value Handler for attribute (" + getId() + ").");
                }
 
                // Decide whether or not to allow empty string values
@@ -140,24 +95,21 @@ public class SimpleAttributeDefinition extends SimpleBaseAttributeDefinition imp
        public void resolve(ResolverAttribute attribute, Principal principal, String requester, String responder,
                        Dependencies depends) throws ResolutionPlugInException {
 
+               super.resolve(attribute, principal, requester, responder, depends);
+
                log.debug("Resolving attribute: (" + getId() + ")");
-               Set results = new LinkedHashSet();
+               Set<Object> results = new LinkedHashSet<Object>();
                if (!connectorDependencyIds.isEmpty()) {
-                       results.addAll(Arrays.asList(getValuesFromConnectors(depends)));
+                       results.addAll(getAllValuesFromConnectorDeps(depends));
                }
 
                if (!attributeDependencyIds.isEmpty()) {
-                       results.addAll(Arrays.asList(getValuesFromAttributes(depends)));
+                       results.addAll(getAllValuesFromAttributeDeps(depends));
                }
 
-               standardProcessing(attribute);
-
                if (smartScope != null) {
                        attribute.registerValueHandler(new ScopedStringValueHandler(smartScope));
                }
-               if (smartScope == null && valueHandler != null) {
-                       attribute.registerValueHandler(valueHandler);
-               }
 
                Iterator resultsIt = results.iterator();
                while (resultsIt.hasNext()) {
diff --git a/src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/SimpleBaseAttributeDefinition.java b/src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/SimpleBaseAttributeDefinition.java
deleted file mode 100644 (file)
index 1a73fbb..0000000
+++ /dev/null
@@ -1,187 +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.
- */
-
-/*
- * Contributed by SunGard SCT.
- */
-
-package edu.internet2.middleware.shibboleth.aa.attrresolv.provider;
-
-import java.security.Principal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Element;
-
-import edu.internet2.middleware.shibboleth.aa.attrresolv.AttributeDefinitionPlugIn;
-import edu.internet2.middleware.shibboleth.aa.attrresolv.Dependencies;
-import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolutionPlugInException;
-import edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverAttribute;
-
-/**
- * This is an abstract class that all other attribute definitions in this package extend. It provides processing of
- * common attributes as well as dependency resolutions.
- * 
- * @author <a href="mailto:vgoenka@sungardsct.com">Vishal Goenka </a>
- */
-abstract class SimpleBaseAttributeDefinition extends BaseAttributeDefinition implements AttributeDefinitionPlugIn {
-
-       private static Logger log = Logger.getLogger(SimpleBaseAttributeDefinition.class.getName());
-
-       protected ValueHandler valueHandler;
-       protected String connectorMapping;
-
-       protected SimpleBaseAttributeDefinition(Element e) throws ResolutionPlugInException {
-
-               super(e);
-
-               String sourceName = e.getAttribute("sourceName");
-               if (sourceName == null || sourceName.equals("")) {
-                       int index = getId().lastIndexOf("#");
-                       if (index < 0) {
-                               index = getId().lastIndexOf(":");
-                               int slashIndex = getId().lastIndexOf("/");
-                               if (slashIndex > index) {
-                                       index = slashIndex;
-                               }
-                       }
-                       connectorMapping = getId().substring(index + 1);
-               } else {
-                       connectorMapping = sourceName;
-               }
-
-               String valueHandlerSpec = e.getAttribute("valueHandler");
-
-               if (valueHandlerSpec != null && !valueHandlerSpec.equals("")) {
-                       try {
-                               Class handlerClass = Class.forName(valueHandlerSpec);
-                               valueHandler = (ValueHandler) handlerClass.newInstance();
-                       } catch (ClassNotFoundException cnfe) {
-                               log.error("Value Handler implementation specified for attribute (" + getId() + ") cannot be found: "
-                                               + cnfe);
-                               throw new ResolutionPlugInException("Value Handler implementation specified for attribute (" + getId()
-                                               + ") cannot be found.");
-                       } catch (Exception oe) {
-                               log.error("Value Handler implementation specified for attribute (" + getId()
-                                               + ") coudl not be loaded: " + oe);
-                               throw new ResolutionPlugInException("Value Handler implementation specified for attribute (" + getId()
-                                               + ") could not be loaded.");
-                       }
-               }
-
-               if (valueHandler != null) {
-                       log.debug("Custom Value Handler enabled for attribute (" + getId() + ").");
-               }
-
-       }
-
-       protected Collection resolveDependencies(ResolverAttribute attribute, Principal principal, String requester,
-                       Dependencies depends) throws ResolutionPlugInException {
-
-               log.debug("Resolving attribute: (" + getId() + ")");
-
-               Set results = new LinkedHashSet();
-               if (!connectorDependencyIds.isEmpty()) {
-                       results.addAll(Arrays.asList(getValuesFromConnectors(depends)));
-               }
-
-               if (!attributeDependencyIds.isEmpty()) {
-                       results.addAll(Arrays.asList(getValuesFromAttributes(depends)));
-               }
-
-               if (valueHandler != null) {
-                       attribute.registerValueHandler(valueHandler);
-               }
-
-               return results;
-       }
-
-       protected Object[] getValuesFromAttributes(Dependencies depends) {
-
-               Set results = new LinkedHashSet();
-
-               Iterator attrDependIt = attributeDependencyIds.iterator();
-               while (attrDependIt.hasNext()) {
-                       ResolverAttribute attribute = depends.getAttributeResolution((String) attrDependIt.next());
-                       if (attribute != null) {
-                               log.debug("Found value(s) for attribute (" + getId() + ").");
-                               for (Iterator iterator = attribute.getValues(); iterator.hasNext();) {
-                                       results.add(iterator.next());
-                               }
-                       } else {
-                               log.error("An attribute dependency of attribute (" + getId()
-                                               + ") was not included in the dependency chain.");
-                       }
-               }
-
-               if (results.isEmpty()) {
-                       log.debug("An attribute dependency of attribute (" + getId() + ") supplied no values.");
-               }
-               return results.toArray();
-       }
-
-       protected Object[] getValuesFromConnectors(Dependencies depends) {
-
-               Set results = new LinkedHashSet();
-
-               Iterator connectorDependIt = connectorDependencyIds.iterator();
-               while (connectorDependIt.hasNext()) {
-                       Attributes attrs = depends.getConnectorResolution((String) connectorDependIt.next());
-                       if (attrs != null) {
-                               Attribute attr = attrs.get(connectorMapping);
-                               if (attr != null) {
-                                       log.debug("Found value(s) for attribute (" + getId() + ").");
-                                       try {
-                                               NamingEnumeration valuesEnum = attr.getAll();
-                                               while (valuesEnum.hasMore()) {
-                                                       results.add(valuesEnum.next());
-                                               }
-                                       } catch (NamingException e) {
-                                               log.error("An problem was encountered resolving the dependencies of attribute (" + getId()
-                                                               + "): " + e);
-                                       }
-                               }
-                       }
-               }
-
-               if (results.isEmpty()) {
-                       log.debug("A connector dependency of attribute (" + getId() + ") supplied no values.");
-               }
-               return results.toArray();
-       }
-
-       protected String getString(Object value) {
-
-               // if (value instanceof String) return (String)value;
-               // This was inspired by the fact that certain attributes (such as userPassword, when read using JNDI) are
-               // returned
-               // from data connectors as byte [] rather than String, and doing a .toString() returns something like
-               // B[@aabljadj,
-               // which is a reference to the array, rather than the string value.
-               if (value instanceof byte[]) return new String((byte[]) value);
-               return value.toString();
-       }
-
-}
\ No newline at end of file