[java-shib-attribute] branch main updated: IDP-2375 - Aliased decoded IdPAttributes are lost during subsequent use
Scott Cantor
cantor.2 at osu.edu
Tue Apr 22 14:43:31 UTC 2025
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=7efdc682c184e167b179640f1b60238411cb513b
The following commit(s) were added to refs/heads/main by this push:
new 7efdc682c IDP-2375 - Aliased decoded IdPAttributes are lost during subsequent use
7efdc682c is described below
commit 7efdc682c184e167b179640f1b60238411cb513b
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Apr 22 10:43:28 2025 -0400
IDP-2375 - Aliased decoded IdPAttributes are lost during subsequent use
https://shibboleth.atlassian.net/browse/IDP-2375
Adjust helper methods to return mutable maps.
Add additional methods to optimize merging use cases.
---
.../idp/attribute/IdPAttributeSupport.java | 121 +++++++++++++++------
1 file changed, 89 insertions(+), 32 deletions(-)
diff --git a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttributeSupport.java b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttributeSupport.java
index 044d293b4..5cfa6f8dd 100644
--- a/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttributeSupport.java
+++ b/shib-attribute-api/src/main/java/net/shibboleth/idp/attribute/IdPAttributeSupport.java
@@ -16,7 +16,6 @@ package net.shibboleth.idp.attribute;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,49 +24,106 @@ import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import net.shibboleth.shared.annotation.constraint.Live;
import net.shibboleth.shared.collection.CollectionSupport;
/**
- * Class for general support functions for managing IdPAttributes.
+ * Class for general support functions for managing {@link IdPAttribute} objects.
+ *
+ * @since 5.2.0
*/
-public class IdPAttributeSupport {
+public final class IdPAttributeSupport {
- /** Convert a Buckets of attributes into a Map of attributes.
- * If an attribute with a duplicate Id is found then we issue a warning and
- * an arbitrary attribute is chosen.
- * @param attributes a collection of attributes.
- * @return These attributes in a map where the key is the attribute's ID and the value the attributes
+ /** Private constructor. */
+ private IdPAttributeSupport() {
+ }
+
+ /**
+ * Convert a collection of {@link IdPAttribute} objects into a mutable {@link Map} keyed by
+ * {@link IdPAttribute#getId()}.
+ *
+ * <p>If an attribute with a duplicate ID is found,
+ * then we issue a warning and an arbitrary one is chosen.</p>
+ *
+ * @param attributes collection of attributes
+ *
+ * @return the input attributes in a map keyed by {@link IdPAttribute#getId()}
*/
- @Nonnull public static Map<String, IdPAttribute> toMapNoDuplicates(@Nullable Collection<IdPAttribute> attributes) {
+ @Nonnull @Live public static Map<String,IdPAttribute> toMapNoDuplicates(
+ @Nullable final Collection<IdPAttribute> attributes) {
+
+ final Map<String,IdPAttribute> accumulator = new HashMap<>();
+
if (attributes == null) {
- return CollectionSupport.emptyMap();
+ return accumulator;
}
- return attributes.
- stream().
- collect(CollectionSupport.nonnullCollector(Collectors.toUnmodifiableMap(IdPAttribute::getId,
- a -> a,
- CollectionSupport.warningMergeFunction("AttrtibuteContext", true)))).get();
+
+ accumulator.putAll(
+ attributes.stream().
+ collect(CollectionSupport.nonnullCollector(Collectors.toUnmodifiableMap(IdPAttribute::getId,
+ a -> a,
+ CollectionSupport.warningMergeFunction("AttrtibuteContext", true)))).get());
+ return accumulator;
+ }
+
+ /**
+ * Convert a collection of {@link IdPAttribute} objects into a mutable {@link Map} keyed by
+ * {@link IdPAttribute#getId()}.
+ *
+ * <p>If an attribute with a duplicate ID is found, then we merge the values into a single attribute.</p>
+ *
+ * @param attributes collection of attributes
+ *
+ * @return the input attributes in a map keyed by {@link IdPAttribute#getId()}
+ */
+ @Nonnull @Live public static Map<String,IdPAttribute> toMapMergeDuplicates(
+ @Nullable final Collection<IdPAttribute> attributes) {
+
+ final Map<String, IdPAttribute> accumulator = new HashMap<>();
+ return withMapMergeDuplicates(accumulator, attributes);
}
+ /**
+ * Add a collection of {@link IdPAttribute} objects into a mutable input {@link Map} keyed by
+ * {@link IdPAttribute#getId()}.
+ *
+ * <p>If an attribute with a duplicate ID is found, then we merge the values into a single attribute.</p>
+ *
+ * @param existingAttributes an existing mutable map to merge into
+ * @param newAttributes collection to merge into map
+ *
+ * @return the input map after merging is done
+ */
+ @Nonnull @Live public static Map<String,IdPAttribute> withMapMergeDuplicates(
+ @Nonnull @Live final Map<String,IdPAttribute> existingAttributes,
+ @Nonnull final Map<String,IdPAttribute> newAttributes) {
+ return withMapMergeDuplicates(existingAttributes, newAttributes.values());
+ }
- /** Convert a Buckets of attributes into a Map of attributes.
- * If an attribute with a duplicate Id is found then we merge the values into a single attribute.
- * @param attributes a collection of attributes.
- * @return These attributes in a map where the key is the attribute's ID and the value the attributes
- * @throws AttributeEncodingException if a clone operation fails.
+ /**
+ * Add a collection of {@link IdPAttribute} objects into a mutable input {@link Map} keyed by
+ * {@link IdPAttribute#getId()}.
+ *
+ * <p>If an attribute with a duplicate ID is found, then we merge the values into a single attribute.</p>
+ *
+ * @param existingAttributes an existing mutable map to merge into
+ * @param newAttributes collection to merge into map
+ *
+ * @return the input map after merging is done
*/
- @Nonnull public static Map<String, IdPAttribute> toMapMergeDuplicates(@Nullable Collection<IdPAttribute> attributes) {
- final Map<String, IdPAttribute> accumulator;
- if (attributes == null) {
- return CollectionSupport.emptyMap();
+ @Nonnull @Live public static Map<String,IdPAttribute> withMapMergeDuplicates(
+ @Nonnull @Live final Map<String,IdPAttribute> existingAttributes,
+ @Nullable final Collection<IdPAttribute> newAttributes) {
+
+ if (newAttributes == null) {
+ return existingAttributes;
}
- accumulator = new HashMap<>(attributes.size());
- for (IdPAttribute attribute:attributes) {
+ for (final IdPAttribute attribute : newAttributes) {
- final IdPAttribute oldAttr = accumulator.get(attribute.getId());
+ final IdPAttribute oldAttr = existingAttributes.get(attribute.getId());
if (oldAttr == null) {
- accumulator.put(attribute.getId(), attribute);
+ existingAttributes.put(attribute.getId(), attribute);
} else {
final IdPAttribute newAttribute;
try {
@@ -78,11 +134,12 @@ public class IdPAttributeSupport {
final List<IdPAttributeValue> values = new ArrayList<IdPAttributeValue>(newAttribute.getValues());
values.addAll(attribute.getValues());
newAttribute.setValues(values);
- accumulator.remove(attribute.getId());
- accumulator.put(newAttribute.getId(), newAttribute);
+ existingAttributes.remove(attribute.getId());
+ existingAttributes.put(newAttribute.getId(), newAttribute);
}
}
- return Collections.unmodifiableMap(accumulator);
+ return existingAttributes;
}
-}
+
+}
\ 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