[java-shib-attribute] branch main updated: Fix decoding XMLObject data and prevent treatment as null string values.

Scott Cantor cantor.2 at osu.edu
Mon Feb 27 16:40:35 UTC 2023


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

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

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

The following commit(s) were added to refs/heads/main by this push:
     new 1889f6526 Fix decoding XMLObject data and prevent treatment as null string values.
1889f6526 is described below

commit 1889f65268e0e53536dd0aa61490a8f5322cca33
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Feb 27 11:40:04 2023 -0500

    Fix decoding XMLObject data and prevent treatment as null string values.
---
 ...stractCollectionConfigurationLookupStrategy.java |  2 +-
 ...ctMetadataDrivenConfigurationLookupStrategy.java | 11 ++---------
 .../config/ListConfigurationLookupStrategy.java     | 20 +++++++++++++-------
 .../config/SetConfigurationLookupStrategy.java      | 21 ++++++++++++++-------
 .../saml/impl/AttributeInMetadataMatcher.java       |  5 ++---
 .../impl/SAML1StringAttributeTranscoder.java        |  9 +++++++--
 .../impl/SAML2StringAttributeTranscoder.java        |  9 +++++++--
 7 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractCollectionConfigurationLookupStrategy.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractCollectionConfigurationLookupStrategy.java
index 1eca3e3f3..cbf48d2d0 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractCollectionConfigurationLookupStrategy.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractCollectionConfigurationLookupStrategy.java
@@ -134,7 +134,7 @@ public abstract class AbstractCollectionConfigurationLookupStrategy<T1,T2>
             }
         }
         
-        log.error("Unsupported conversion to String from XMLObject type ({})", object.getClass().getName());
+        log.debug("Unsupported conversion to String from XMLObject type ({})", object.getClass().getName());
         return null;
     }
 // Checkstyle: CyclomaticComplexity ON
diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractMetadataDrivenConfigurationLookupStrategy.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractMetadataDrivenConfigurationLookupStrategy.java
index e745ef34c..9ffda5620 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractMetadataDrivenConfigurationLookupStrategy.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/AbstractMetadataDrivenConfigurationLookupStrategy.java
@@ -44,7 +44,6 @@ import org.slf4j.Logger;
 
 import net.shibboleth.idp.attribute.AttributesMapContainer;
 import net.shibboleth.idp.attribute.IdPAttribute;
-import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.shared.annotation.constraint.Live;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
@@ -330,7 +329,7 @@ public abstract class AbstractMetadataDrivenConfigurationLookupStrategy<T> exten
         // Look for "primary" tag name based on profile/property using mapped tags.
         IdPAttribute idpAttribute = findMatchingMappedTag(entity,
                 profileId != null ? profileId + '/' + propertyName : propertyName);
-        if (idpAttribute != null) {
+        if (idpAttribute != null && !idpAttribute.getValues().isEmpty()) {
             log.debug("Found matching tag '{}' for property '{}'", idpAttribute.getId(), propertyName);
             final T result = translate(idpAttribute);
             if (enableCaching) {
@@ -343,7 +342,7 @@ public abstract class AbstractMetadataDrivenConfigurationLookupStrategy<T> exten
         // Check aliases.
         for (final String alias : propertyAliases) {
             idpAttribute = findMatchingMappedTag(entity, alias);
-            if (idpAttribute != null) {
+            if (idpAttribute != null && !idpAttribute.getValues().isEmpty()) {
                 log.debug("Found matching tag '{}' for property '{}'", idpAttribute.getId(), propertyName);
                 final T result = translate(idpAttribute);
                 if (enableCaching) {
@@ -427,12 +426,6 @@ public abstract class AbstractMetadataDrivenConfigurationLookupStrategy<T> exten
      * @return the setting derived from the tag's value(s)
      */
     @Nullable private T translate(@Nonnull final IdPAttribute tag) {
-        
-        if (tag.getValues().isEmpty()) {
-            log.debug("Tag '{}' contained no values, no setting returned for '{}'", tag.getId(), propertyName);
-            return null;
-        }
-        
         return doTranslate(tag);
     }
 
diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/ListConfigurationLookupStrategy.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/ListConfigurationLookupStrategy.java
index 36b45d541..ecccbb594 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/ListConfigurationLookupStrategy.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/ListConfigurationLookupStrategy.java
@@ -81,15 +81,21 @@ public class ListConfigurationLookupStrategy<T> extends AbstractCollectionConfig
         for (final XMLObject value : values) {
             assert value != null;
             
-            if (getPropertyType().isInstance(value)) {
+            final String converted = xmlObjectToString(value);
+            if (converted != null) {
+                try {
+                    result.add(createInstanceFromString(converted));
+                } catch (final Exception e) {
+                    log.error("Error converting tag value into {}", getPropertyType().getSimpleName(), e);
+                }
+            } else if (getPropertyType().isInstance(value)) {
                 result.add(getPropertyType().cast(value));
             } else {
-                final String converted = xmlObjectToString(value);
-                if (converted != null) {
-                    try {
-                        result.add(createInstanceFromString(converted));
-                    } catch (final Exception e) {
-                        log.error("Error converting tag value into {}", getPropertyType().getSimpleName(), e);
+                final List<XMLObject> children = value.getOrderedChildren();
+                if (children != null && children.size() == 1) {
+                    final XMLObject child = children.get(0);
+                    if (getPropertyType().isInstance(child)) {
+                        result.add(getPropertyType().cast(child));
                     }
                 }
             }
diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
index 57b47e7f8..efcc1b6c5 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/config/SetConfigurationLookupStrategy.java
@@ -81,15 +81,22 @@ public class SetConfigurationLookupStrategy<T> extends AbstractCollectionConfigu
         final Set<T> result = new HashSet<>(values.size());
         for (final XMLObject value : values) {
             assert value != null;
-            if (getPropertyType().isInstance(value)) {
+
+            final String converted = xmlObjectToString(value);
+            if (converted != null) {
+                try {
+                    result.add(createInstanceFromString(converted));
+                } catch (final Exception e) {
+                    log.error("Error converting tag value into {}", getPropertyType().getSimpleName(), e);
+                }
+            } else if (getPropertyType().isInstance(value)) {
                 result.add(getPropertyType().cast(value));
             } else {
-                final String converted = xmlObjectToString(value);
-                if (converted != null) {
-                    try {
-                        result.add(createInstanceFromString(converted));
-                    } catch (final Exception e) {
-                        log.error("Error converting tag value into {}", getPropertyType().getSimpleName(), e);
+                final List<XMLObject> children = value.getOrderedChildren();
+                if (children != null && children.size() == 1) {
+                    final XMLObject child = children.get(0);
+                    if (getPropertyType().isInstance(child)) {
+                        result.add(getPropertyType().cast(child));
                     }
                 }
             }
diff --git a/shib-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java b/shib-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
index 6194d28bc..28682ed63 100644
--- a/shib-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
+++ b/shib-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.attribute.filter.matcher.saml.impl;
 
 import java.time.Instant;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -186,11 +185,11 @@ public class AttributeInMetadataMatcher extends AbstractIdentifiableInitializabl
     
         if (null == service) {
             if (matchIfMetadataSilent) {
-                log.debug("{} The peer's metadata did not contain requested attribute information"
+                log.debug("{} The peer's metadata/request did not contain requested attribute information"
                         + ", returning all the input values", getLogPrefix());
                 return CollectionSupport.copyToSet(attribute.getValues());
             }
-            log.debug("{} The peer's metadata did not contain requested attribute information"
+            log.debug("{} The peer's metadata/request did not contain requested attribute information"
                     + ", returning no values", getLogPrefix());
             return CollectionSupport.emptySet();
         }
diff --git a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoder.java b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoder.java
index 335f5b789..23feb785e 100644
--- a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoder.java
+++ b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML1StringAttributeTranscoder.java
@@ -73,7 +73,12 @@ public class SAML1StringAttributeTranscoder extends AbstractSAML1AttributeTransc
             @Nullable final ProfileRequestContext profileRequestContext, @Nonnull final AttributeDesignator attribute,
             @Nonnull final TranscodingRule rule, @Nullable final XMLObject value) {
         
-        return value != null ? StringAttributeValue.valueOf(getStringValue(value)) : null;
+        final String stringValue = getStringValue(value);
+        if (null == stringValue) {
+            return null;
+        }
+        
+        return StringAttributeValue.valueOf(stringValue);
     }
     
-}
+}
\ No newline at end of file
diff --git a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoder.java b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoder.java
index 1885e550a..f2df13a24 100644
--- a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoder.java
+++ b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/transcoding/impl/SAML2StringAttributeTranscoder.java
@@ -73,7 +73,12 @@ public class SAML2StringAttributeTranscoder extends AbstractSAML2AttributeTransc
             @Nullable final ProfileRequestContext profileRequestContext, @Nonnull final Attribute attribute,
             @Nonnull final TranscodingRule rule, @Nullable final XMLObject value) {
         
-        return value != null ? StringAttributeValue.valueOf(getStringValue(value)) : null;
+        final String stringValue = getStringValue(value);
+        if (null == stringValue) {
+            return null;
+        }
+        
+        return StringAttributeValue.valueOf(stringValue);
     }
     
-}
+}
\ No newline at end of file

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


More information about the commits mailing list