[java-opensaml] branch master updated: OSJ-309 - EntityAttribute metadata filter generates duplicate attributes
Scott Cantor
cantor.2 at osu.edu
Wed Apr 15 18:20:57 EDT 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=9342dbeda25b140bbbd435363f22ab61d8b83c6f
The following commit(s) were added to refs/heads/master by this push:
new 9342dbe OSJ-309 - EntityAttribute metadata filter generates duplicate attributes
9342dbe is described below
commit 9342dbeda25b140bbbd435363f22ab61d8b83c6f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Apr 15 18:20:54 2020 -0400
OSJ-309 - EntityAttribute metadata filter generates duplicate attributes
https://issues.shibboleth.net/jira/browse/OSJ-309
Handle duplicate Attributes but leave values for now.
---
.../filter/impl/EntityAttributesFilter.java | 66 ++++++++++++++++++----
.../filter/impl/EntityAttributesFilterTest.java | 17 +++++-
2 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilter.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilter.java
index ab803d0..9781702 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilter.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilter.java
@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
@@ -165,19 +166,10 @@ public class EntityAttributesFilter extends AbstractInitializableComponent imple
if (entityAttributesCollection.isEmpty()) {
entityAttributesCollection.add(entityAttributesBuilder.buildObject());
}
+
final EntityAttributes entityAttributes =
(EntityAttributes) entityAttributesCollection.iterator().next();
-
- for (final Attribute attribute : entry.getValue()) {
- try {
- log.info("Adding EntityAttribute ({}) to EntityDescriptor ({})", attribute.getName(),
- descriptor.getEntityID());
- final Attribute copy = XMLObjectSupport.cloneXMLObject(attribute);
- entityAttributes.getAttributes().add(copy);
- } catch (final MarshallingException | UnmarshallingException e) {
- log.error("Error cloning Attribute", e);
- }
- }
+ entry.getValue().forEach(a -> addEntityAttribute(descriptor, entityAttributes, a));
}
}
}
@@ -199,6 +191,58 @@ public class EntityAttributesFilter extends AbstractInitializableComponent imple
filterEntityDescriptor(entity);
}
}
+
+ /**
+ * Get or create {@link Attribute} based on the input/template object.
+ *
+ * @param descriptor parent entity
+ * @param container extension container
+ * @param input input object
+ */
+ @Nonnull private void addEntityAttribute(@Nonnull final EntityDescriptor descriptor,
+ @Nonnull final EntityAttributes container, @Nonnull final Attribute input) {
+
+ Attribute toMutate = null;
+
+ for (final Attribute attribute : container.getAttributes()) {
+ if (Objects.equals(input.getName(), attribute.getName())) {
+
+ String format1 = input.getNameFormat();
+ String format2 = attribute.getNameFormat();
+
+ if (Attribute.UNSPECIFIED.equals(format1)) {
+ format1 = null;
+ }
+ if (Attribute.UNSPECIFIED.equals(format2)) {
+ format2 = null;
+ }
+ if (Objects.equals(format1, format2)) {
+ toMutate = attribute;
+ break;
+ }
+ }
+ }
+
+ if (toMutate != null) {
+ for (final XMLObject newValue : input.getAttributeValues()) {
+ try {
+ log.info("Adding value to existing EntityAttribute ({}) on EntityDescriptor ({})", input.getName(),
+ descriptor.getEntityID());
+ toMutate.getAttributeValues().add(XMLObjectSupport.cloneXMLObject(newValue));
+ } catch (final MarshallingException | UnmarshallingException e) {
+ log.error("Error cloning AttributeValue", e);
+ }
+ }
+ } else {
+ try {
+ log.info("Adding new EntityAttribute ({}) to EntityDescriptor ({})", input.getName(),
+ descriptor.getEntityID());
+ container.getAttributes().add(XMLObjectSupport.cloneXMLObject(input));
+ } catch (final MarshallingException | UnmarshallingException e) {
+ log.error("Error cloning Attribute", e);
+ }
+ }
+ }
/**
* Apply whitelist to metadata on input.
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilterTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilterTest.java
index 9f0ee87..1bb0872 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilterTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/metadata/resolver/filter/impl/EntityAttributesFilterTest.java
@@ -21,6 +21,7 @@ import java.io.File;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.function.Predicate;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
@@ -80,10 +81,18 @@ public class EntityAttributesFilterTest extends XMLObjectBaseTestCase implements
final XSString value = valueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
value.setValue("bar");
tag.getAttributeValues().add(value);
- final Collection<Attribute> tags = Collections.singletonList(tag);
+
+ final Attribute tag2 = tagBuilder.buildObject();
+ tag2.setName("http://macedir.org/entity-category");
+ tag2.setNameFormat(Attribute.URI_REFERENCE);
+ final XSString value2 = valueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
+ value2.setValue("http://refeds.org/category/research-and-scholarship");
+ tag2.getAttributeValues().add(value2);
+
+ final Collection<Attribute> tags = List.of(tag, tag2);
final EntityAttributesFilter filter = new EntityAttributesFilter();
- filter.setRules(Collections.<Predicate<EntityDescriptor>,Collection<Attribute>>singletonMap(this, tags));
+ filter.setRules(Collections.singletonMap(this, tags));
filter.initialize();
metadataProvider.setMetadataFilter(filter);
@@ -101,7 +110,9 @@ public class EntityAttributesFilterTest extends XMLObjectBaseTestCase implements
Assert.assertNotNull(extTags);
Assert.assertEquals(extTags.getAttributes().size(), 2);
Assert.assertEquals(extTags.getAttributes().get(0).getName(), "http://macedir.org/entity-category");
+ Assert.assertEquals(extTags.getAttributes().get(0).getAttributeValues().size(), 4);
Assert.assertEquals(extTags.getAttributes().get(1).getName(), "foo");
+ Assert.assertEquals(extTags.getAttributes().get(1).getAttributeValues().size(), 1);
key = new EntityIdCriterion("https://cms.psu.edu/Shibboleth");
entity = metadataProvider.resolveSingle(new CriteriaSet(key));
@@ -121,7 +132,7 @@ public class EntityAttributesFilterTest extends XMLObjectBaseTestCase implements
final Collection<Attribute> tags = Collections.singletonList(tag);
final EntityAttributesFilter filter = new EntityAttributesFilter();
- filter.setRules(Collections.<Predicate<EntityDescriptor>,Collection<Attribute>>singletonMap(this, tags));
+ filter.setRules(Collections.singletonMap(this, tags));
filter.setAttributeFilter(input -> "foo".equals(input.getName()));
filter.initialize();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list