[java-shib-attribute] 05/05: JSATTR-29 All exporting data connectors resolved when specific attributes are requested

Scott Cantor cantor.2 at osu.edu
Thu Jul 25 17:41:42 UTC 2024


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

scantor pushed a commit to branch maint-5.1
in repository java-shib-attribute.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=e21f288f6b32d59773ac0b57c6e8bb6aabb5ff2d

commit e21f288f6b32d59773ac0b57c6e8bb6aabb5ff2d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jul 19 16:06:04 2024 +0100

    JSATTR-29 All exporting data connectors resolved when specific attributes are requested
    
    https://shibboleth.atlassian.net/issues/JSATTR-29
---
 .../resolver/impl/AttributeResolverImpl.java       | 35 ++++++++++++++++++----
 .../resolver/impl/AttributeResolverImplTest.java   | 32 ++++++++++++++++----
 2 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
index ad085d920..d5163c74f 100644
--- a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
+++ b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImpl.java
@@ -206,11 +206,25 @@ public class AttributeResolverImpl extends AbstractIdentifiableInitializableComp
             }
             attributeContext = resolutionContext.ensureSubcontext(AttributeContext.class);
 
+            final Collection<String> attributeIds = new HashSet<>(getToBeResolvedAttributeIds(resolutionContext));
             boolean hasExportingDataConnector = false;
 
             for (final Entry<String, DataConnector> dataConnectorEntry : dataConnectors.entrySet()) {
-                if (!dataConnectorEntry.getValue().getExportAttributes().isEmpty()) {
-                    hasExportingDataConnector = true;
+                final Collection<String> exportAttributes = dataConnectorEntry.getValue().getExportAttributes();
+                if (exportAttributes.isEmpty()) {
+                    continue;
+                }
+                hasExportingDataConnector = true;
+                boolean resolve = noAttributesRequested(resolutionContext);
+                if (!resolve) {
+                    for (String exportedAttributeId : exportAttributes) {
+						resolve = attributeIds.contains(exportedAttributeId);
+						if (resolve) {
+							break;
+						}
+					}
+                }
+                if (resolve) {
                     final String key = dataConnectorEntry.getKey();
                     assert key!=null;
                     resolveDataConnector(key, resolutionContext);
@@ -223,7 +237,6 @@ public class AttributeResolverImpl extends AbstractIdentifiableInitializableComp
                 return;
             }
     
-            final Collection<String> attributeIds = getToBeResolvedAttributeIds(resolutionContext);
             log.debug("{} Attempting to resolve the following attribute definitions {}", logPrefix, attributeIds);
     
             for (final String attributeId : attributeIds) {
@@ -252,9 +265,9 @@ public class AttributeResolverImpl extends AbstractIdentifiableInitializableComp
      * Gets the list of attributes, identified by IDs, that should be resolved. If the
      * {@link AttributeResolutionContext#getRequestedIdPAttributeNames()} is not empty then those attributes are the
      * ones to be resolved, otherwise all registered attribute definitions are to be resolved.
-     * 
+     *
      * @param resolutionContext current resolution context
-     * 
+     *
      * @return list of attributes, identified by IDs, that should be resolved
      */
     @Nonnull @Live protected Collection<String> getToBeResolvedAttributeIds(
@@ -262,15 +275,25 @@ public class AttributeResolverImpl extends AbstractIdentifiableInitializableComp
         Constraint.isNotNull(resolutionContext, "Attribute resolution context cannot be null");
 
         // if no attributes requested, then resolve everything
-        if (resolutionContext.getRequestedIdPAttributeNames().isEmpty()) {
+        if (noAttributesRequested(resolutionContext)) {
             final Collection<String> attributeIds = new LazyList<>();
             attributeIds.addAll(attributeDefinitions.keySet());
             return attributeIds;
         }
         return resolutionContext.getRequestedIdPAttributeNames();
+    }
 
+    /**
+     * Were attributes requested or is thisa get everything situation?
+     * @param resolutionContext current resolution context
+     * @return whether some attiibutes were explictly requested
+     */
+    protected boolean noAttributesRequested(@Nonnull final AttributeResolutionContext resolutionContext) {
+        Constraint.isNotNull(resolutionContext, "Attribute resolution context cannot be null");
+	    return resolutionContext.getRequestedIdPAttributeNames().isEmpty();
     }
 
+
     /**
      * Resolve the {@link AttributeDefinition} which has the specified ID.
      * 
diff --git a/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
index 9dfe16475..60b3d05cc 100644
--- a/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
+++ b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverImplTest.java
@@ -195,7 +195,9 @@ public class AttributeResolverImplTest {
         final IdPAttribute attribute3 = new IdPAttribute("ad3");
         attribute3.setValues(CollectionSupport.singletonList(new StringAttributeValue("value3")));
         final IdPAttribute attribute4 = new IdPAttribute("ad4");
-        attribute4.setValues(CollectionSupport.singletonList(new StringAttributeValue("value3")));
+        attribute4.setValues(CollectionSupport.singletonList(new StringAttributeValue("value4")));
+        final IdPAttribute attribute5 = new IdPAttribute("ad5");
+        attribute5.setValues(CollectionSupport.singletonList(new StringAttributeValue("value5")));
 
         // Connector2 contributes attribute2, attribute3 attribute4 (but not 1)
         // Connector2 exports 2 & 3 (and would export 1 if it created it)
@@ -204,10 +206,11 @@ public class AttributeResolverImplTest {
         connector2.setValues(CollectionSupport.listOf(attribute2, attribute3, attribute4));
         connector2.setExportAttributes(CollectionSupport.listOf(attribute2.getId(), attribute3.getId(), attribute1.getId()));
 
-        // Connector 3 contributes nothing
+        // Connector 3 contributes & exports attribute 5
         final StaticDataConnector connector3 = new StaticDataConnector();
         connector3.setId("dc3");
-        connector3.setValues(CollectionSupport.singletonList(attribute4));
+        connector3.setValues(CollectionSupport.singletonList(attribute5));
+        connector3.setExportAttributes(CollectionSupport.singleton(attribute5.getId()));
 
         final AttributeResolverImpl resolver = newAttributeResolverImpl("foo", null, List.of(connector2, connector3));
 
@@ -216,13 +219,30 @@ public class AttributeResolverImplTest {
         }
         resolver.initialize();
 
-        final AttributeResolutionContext context = new AttributeResolutionContext();
+        AttributeResolutionContext context = new AttributeResolutionContext();
+        AttributeResolverWorkContext workContext = context.ensureSubcontext(AttributeResolverWorkContext.class);
         resolver.resolveAttributes(context);
 
-        // should have resolved 2, 3
-        assertEquals(context.getResolvedIdPAttributes().size(), 2);
+        // Both data connectors resolved
+        assertEquals(workContext.getResolvedDataConnectors().size(), 2);
+
+        // should have resolved 2, 3, 5
+        assertEquals(context.getResolvedIdPAttributes().size(), 3);
         assertEquals(context.getResolvedIdPAttributes().get(attribute2.getId()), attribute2);
         assertEquals(context.getResolvedIdPAttributes().get(attribute3.getId()), attribute3);
+        assertEquals(context.getResolvedIdPAttributes().get(attribute5.getId()), attribute5);
+
+        context = new AttributeResolutionContext();
+        workContext = context.ensureSubcontext(AttributeResolverWorkContext.class);
+        context.setRequestedIdPAttributeNames(CollectionSupport.singleton(attribute5.getId()));
+        resolver.resolveAttributes(context);
+
+        // Only one data connector resolved
+        assertEquals(workContext.getResolvedDataConnectors().size(), 1);
+
+        // should have resolved 2
+        assertEquals(context.getResolvedIdPAttributes().size(), 1);
+        assertEquals(context.getResolvedIdPAttributes().get(attribute5.getId()), attribute5);
     }
 
     /**

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


More information about the commits mailing list