[java-identity-provider COMMIT] in /trunk: idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/Abstr...

noreply at shibboleth.net noreply at shibboleth.net
Fri Jun 13 08:12:39 EDT 2014


Author: rdw
Date: Fri Jun 13 08:12:38 2014
New Revision: 6081

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=6081&view=rev
Log:
IDP 376.  Move code to the base class to allow multiple output types.

Modified:
    trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/AbstractSAMLAttributesMapper.java
    trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/attribute/mapping/impl/RequestedAttributesMapper.java

Modified: trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/AbstractSAMLAttributesMapper.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/AbstractSAMLAttributesMapper.java?rev=6081&r1=6080&r2=6081&view=diff
==============================================================================
--- trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/AbstractSAMLAttributesMapper.java (original)
+++ trunk/idp-saml-api/src/main/java/net/shibboleth/idp/saml/attribute/mapping/AbstractSAMLAttributesMapper.java Fri Jun 13 08:12:38 2014
@@ -17,6 +17,7 @@
 
 package net.shibboleth.idp.saml.attribute.mapping;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -25,7 +26,11 @@
 
 import javax.annotation.Nonnull;
 
+import net.shibboleth.idp.attribute.AttributeEncoder;
 import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.resolver.AttributeDefinition;
+import net.shibboleth.idp.attribute.resolver.AttributeResolver;
+import net.shibboleth.idp.saml.attribute.encoding.AttributeMapperProcessor;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -36,7 +41,9 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Supplier;
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Multimap;
 
 /**
@@ -59,6 +66,60 @@
 
     /** The String used to prefix log message. */
     private String logPrefix;
+
+    /**
+     * Default Constructor.
+     *
+     */
+    public AbstractSAMLAttributesMapper() {
+    }
+    
+    /**
+     * Constructor to create the mapping from an existing resolver. <br/>
+     * This code inverts the {@link AttributeEncoder} (internal attribute -> SAML Attributes) into
+     * {@link AttributeMapper} (SAML [RequestedAttributes] -> internal [Requested] Attributes). <br/>
+     * to generate the {@link AbstractSAMLAttributeMapper} (with no
+     * {@link AbstractSAMLAttributeMapper#getAttributeIds(). These are accumulated into a {@link Multimap}, where the
+     * key is the {@link AbstractSAMLAttributeMapper} and the values are the (IdP) attribute names. The collection of
+     * {@link AttributeMapper}s can then be extracted from the map, and the appropriate internal names added (these
+     * being the value of the {@link Multimap})
+     * 
+     * @param resolver The resolver
+     * @param mapperFactory A factory to generate new mappers of the correct type.
+     */
+    public AbstractSAMLAttributesMapper(AttributeResolver resolver,
+            Supplier<AbstractSAMLAttributeMapper<InType, OutType>> mapperFactory) {
+
+        super();
+        setId(resolver.getId());
+
+        final Multimap<AbstractSAMLAttributeMapper<InType, OutType>, String> theMappers;
+
+        theMappers = HashMultimap.create();
+
+        for (AttributeDefinition attributeDef : resolver.getAttributeDefinitions().values()) {
+            for (AttributeEncoder encode : attributeDef.getAttributeEncoders()) {
+                if (encode instanceof AttributeMapperProcessor) {
+                    // There is an appropriate reverse mappers
+                    AttributeMapperProcessor factory = (AttributeMapperProcessor) encode;
+                    AbstractSAMLAttributeMapper<InType, OutType> mapper = mapperFactory.get();
+                    factory.populateAttributeMapper(mapper);
+
+                    theMappers.put(mapper, attributeDef.getId());
+                }
+            }
+        }
+
+        mappers = new ArrayList<AttributeMapper<InType, OutType>>(theMappers.values().size());
+
+        for (Entry<AbstractSAMLAttributeMapper<InType, OutType>, Collection<String>> entry : theMappers.asMap()
+                .entrySet()) {
+
+            AbstractSAMLAttributeMapper<InType, OutType> mapper = entry.getKey();
+            mapper.setAttributeIds(new ArrayList<String>(entry.getValue()));
+            mappers.add(mapper);
+        }
+    }
 
     /**
      * Get the mappers.
@@ -84,8 +145,7 @@
      * @param prototypes the SAML attributes
      * @return a map from IdP AttributeId to RequestedAttributes (or NULL).
      */
-    @Override

[... 128 lines stripped ...]


More information about the commits mailing list