[java-identity-provider] branch master updated: IDP-1576 Exported Attributes need Display Information

Rod Widdowson rdw at steadingsoftware.com
Wed Mar 4 11:03:47 EST 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=6395335c327affd8fe12a592d4e3781e2d028744

The following commit(s) were added to refs/heads/master by this push:
       new  6395335   IDP-1576 Exported Attributes need Display Information
6395335 is described below

commit 6395335c327affd8fe12a592d4e3781e2d028744
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Mar 4 14:35:07 2020 +0000

    IDP-1576 Exported Attributes need Display Information
    
    https://issues.shibboleth.net/jira/browse/IDP-1576
---
 .../resolver/AbstractAttributeDefinition.java      | 34 +---------
 .../attribute/resolver/AbstractResolverPlugin.java | 78 ++++++++++++++++++++++
 .../resolver/impl/AttributeResolverImpl.java       | 21 ++----
 3 files changed, 85 insertions(+), 48 deletions(-)

diff --git a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
index 719899c..53c0383 100644
--- a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
+++ b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractAttributeDefinition.java
@@ -27,13 +27,11 @@ import org.slf4j.LoggerFactory;
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolverWorkContext;
-import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.primitive.DeprecationSupport;
 import net.shibboleth.utilities.java.support.primitive.DeprecationSupport.ObjectType;
-import net.shibboleth.utilities.java.support.service.ServiceableComponent;
 
 /** Base class for attribute definition resolver plugins. */
 @ThreadSafe
@@ -142,37 +140,7 @@ public abstract class AbstractAttributeDefinition extends AbstractResolverPlugin
                     resolvedAttribute.getValues());
         }
 
-        if (resolutionContext.getTranscoderRegistry() != null) {
-            ServiceableComponent<AttributeTranscoderRegistry> component = null;
-            try {
-                component = resolutionContext.getTranscoderRegistry().getServiceableComponent();
-                if (component != null) {
-                    
-                    if (resolvedAttribute.getDisplayNames().isEmpty()) {
-                        resolvedAttribute.setDisplayNames(
-                                component.getComponent().getDisplayNames(resolvedAttribute));
-                        log.trace("{} associated display names with the resolved attribute: {}", getLogPrefix(),
-                                resolvedAttribute.getDisplayNames());
-                    }
-
-                    if (resolvedAttribute.getDisplayDescriptions().isEmpty()) {
-                        resolvedAttribute.setDisplayDescriptions(
-                                component.getComponent().getDescriptions(resolvedAttribute));
-                        log.trace("{} associated descriptions with the resolved attribute: {}", getLogPrefix(),
-                                resolvedAttribute.getDisplayDescriptions());
-                    }
-
-                } else {
-                    log.warn("No transcoder registry available, unable to attach displayName/description metadata");
-                }
-            } finally {
-                if (component != null) {
-                    component.unpinComponent();
-                }
-            }
-        } else {
-            log.debug("No transcoder registry supplied, unable to attach displayName/description metadata");
-        }
+        addDisplayInformation(resolutionContext, resolvedAttribute);
 
         return resolvedAttribute;
     }
diff --git a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
index 26ce79c..50b7854 100644
--- a/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
+++ b/idp-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/AbstractResolverPlugin.java
@@ -36,15 +36,19 @@ import org.springframework.beans.factory.DisposableBean;
 
 import com.google.common.base.Predicates;
 
+import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolverWorkContext;
+import net.shibboleth.idp.attribute.transcoding.AttributeTranscoderRegistry;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
 import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.service.ServiceableComponent;
 
 /**
  * Base class for all {@link ResolverPlugin}s.
@@ -61,6 +65,9 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
     /** Whether an {@link AttributeResolutionContext} that occurred resolving attributes will be re-thrown. */
     private boolean propagateResolutionExceptions = true;
 
+    /** Whether we add DisplayInformation to derived attributes.  */
+    private boolean suppressDisplayInformation;
+
     /** Strategy to get the {@link ProfileRequestContext}. */
     @Nonnull private Function<AttributeResolutionContext, ProfileRequestContext> profileContextStrategy;
 
@@ -80,6 +87,25 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
         dataConnectorDependencies = Collections.emptySet(); 
     }
 
+    /** Does this plugin allow addition of Display Information?
+     * @return whether we are suppressing
+     *  */
+    public boolean isSuppressDisplayInformation() {
+        return suppressDisplayInformation;
+    }
+
+    /**
+     * Set whether we suppress addition of Display Information.
+     *
+     * @param what true if we suppress the addition.
+     */
+    public void setSuppressDisplayInformation(final boolean what) {
+        ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+        ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
+
+        suppressDisplayInformation = what;
+    }
+
     /** {@inheritDoc} */
     @Override public boolean isPropagateResolutionExceptions() {
         return propagateResolutionExceptions;
@@ -98,6 +124,7 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
         propagateResolutionExceptions = propagate;
     }
 
+
     /**
      * Gets the mechanism to find out the {@link ProfileRequestContext}.
      * 
@@ -258,6 +285,51 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
         }
     }
 
+    /** Look at the resolution context for an attribute registry and use it to garnish the
+     * attribute.
+     *
+     * Controllable via the {@link AbstractResolverPlugin#isSuppressDisplayInformation()} method.
+     * @param resolutionContext where to get the registry from
+     * @param attribute what to garnish
+     */
+    public void addDisplayInformation(@Nonnull final AttributeResolutionContext resolutionContext,
+            @Nonnull final IdPAttribute attribute) {
+
+        if (isSuppressDisplayInformation()) {
+            log.trace("{} no display information added", getLogPrefix());
+        } else  if (resolutionContext.getTranscoderRegistry() != null) {
+            ServiceableComponent<AttributeTranscoderRegistry> component = null;
+            try {
+                component = resolutionContext.getTranscoderRegistry().getServiceableComponent();
+                if (component != null) {
+
+                    if (attribute.getDisplayNames().isEmpty()) {
+                        attribute.setDisplayNames(
+                                component.getComponent().getDisplayNames(attribute));
+                        log.trace("{} associated display names with the resolved attribute: {}", getLogPrefix(),
+                                attribute.getDisplayNames());
+                    }
+
+                    if (attribute.getDisplayDescriptions().isEmpty()) {
+                        attribute.setDisplayDescriptions(
+                                component.getComponent().getDescriptions(attribute));
+                        log.trace("{} associated descriptions with the resolved attribute: {}", getLogPrefix(),
+                                attribute.getDisplayDescriptions());
+                    }
+
+                } else {
+                    log.warn("No transcoder registry available, unable to attach displayName/description metadata");
+                }
+            } finally {
+                if (component != null) {
+                    component.unpinComponent();
+                }
+            }
+        } else {
+            log.debug("No transcoder registry supplied, unable to attach displayName/description metadata");
+        }
+    }
+
     /** {@inheritDoc} */
     @Override protected void doDestroy() {
         activationCondition = Predicates.alwaysFalse();
@@ -343,4 +415,10 @@ public abstract class AbstractResolverPlugin<ResolvedType> extends AbstractIdent
         }
     }
 
+    /**
+     * Return a string which is to be prepended to all log messages.
+     *
+     * @return a log prefix
+     */
+    @Nonnull @NotEmpty protected abstract String getLogPrefix();
 }
\ No newline at end of file
diff --git a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
index eece5da..8555315 100644
--- a/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
+++ b/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -525,13 +524,14 @@ public class AttributeResolverImpl extends AbstractServiceableComponent<Attribut
     }
 
     /**
-     * Helper function to collect attributes from suitabl data connectors.
+     * Helper function to collect attributes and their data & metadata from suitable data connectors.
      * @param resolvedAttributes bucket to collect attributes into
+     * @param resolutionContext the context we are working in
      * @param workContext context to extract attributes from
      */
-    // CheckStyle: CyclomaticComplexit OFF
     private void collectExportingDataConnectors(final Map<String, IdPAttribute> resolvedAttributes,
-            final AttributeResolverWorkContext workContext) {
+           final AttributeResolutionContext resolutionContext,
+           final AttributeResolverWorkContext workContext) {
 
         for (final ResolvedDataConnector dataConnector: workContext.getResolvedDataConnectors().values()) {
 
@@ -557,20 +557,11 @@ public class AttributeResolverImpl extends AbstractServiceableComponent<Attribut
                 }
                 final IdPAttribute newAttr = new IdPAttribute(attribute.getId());
                 newAttr.setValues(values);
-                if (attribute.getDisplayNames().size() > 0) {
-                    newAttr.setDisplayNames(attribute.getDisplayNames());
-                } else {
-                    newAttr.setDisplayNames(Map.of(Locale.getDefault(),
-                            dataConnector.getId() + "/" + attribute.getId()));
-                }
-                if (attribute.getDisplayDescriptions().size() > 0) {
-                    newAttr.setDisplayDescriptions(attribute.getDisplayDescriptions());
-                }
+                dataConnector.addDisplayInformation(resolutionContext, newAttr);
                 resolvedAttributes.put(attribute.getId(), newAttr);
             }
         }
     }
-    // CheckStyle: CyclomaticComplexit ON
 
     /**
      * Finalizes the set of resolved attributes and places them in the {@link AttributeResolutionContext}. The result of
@@ -595,7 +586,7 @@ public class AttributeResolverImpl extends AbstractServiceableComponent<Attribut
 
         collectResolvedAttributes(resolvedAttributes, workContext, false) ;
 
-        collectExportingDataConnectors(resolvedAttributes, workContext);
+        collectExportingDataConnectors(resolvedAttributes, resolutionContext, workContext);
 
         resolutionContext.setResolvedIdPAttributes(resolvedAttributes.values());
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list