Skip to content

Commit

Permalink
- De-duplicate user profile attribute values (avoid memory overconsum…
Browse files Browse the repository at this point in the history
…ption)
  • Loading branch information
leleuj committed May 23, 2024
1 parent fdbe7b1 commit 7895d0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions documentation/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ layout: doc
title: Release notes:
---

**v5.7.6**:
- De-duplicate user profile attribute values (avoid memory overconsumption)

**v5.7.5**:
- Add the `oidc.withState` config property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private boolean canMergeAttributes(final Map<String, Object> map, final String k

private <T> Collection<T> mergeCollectionAttributes(final Collection<T> existingCollection, final Collection<T> newCollection)
{
return Streams.concat(existingCollection.stream(), newCollection.stream()).collect(Collectors.toList());
return Streams.concat(existingCollection.stream(), newCollection.stream()).distinct().collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.pac4j.core.profile;

import static org.junit.Assert.*;

import java.net.URISyntaxException;
import java.util.*;

import org.junit.Test;
import org.pac4j.core.exception.TechnicalException;
import org.pac4j.core.profile.definition.CommonProfileDefinition;
import org.pac4j.core.util.*;
import org.pac4j.core.util.Pac4jConstants;
import org.pac4j.core.util.TestsConstants;
import org.pac4j.core.util.TestsHelper;
import org.pac4j.core.util.serializer.JavaSerializer;

import java.net.URISyntaxException;
import java.util.*;

import static org.junit.Assert.*;

/**
* This class tests the {@link CommonProfile} class.
* @author Jerome Leleu
Expand Down Expand Up @@ -140,6 +142,24 @@ public void testAddAttributeMultipleValuesOldBehaviour() {
assertEquals(Arrays.asList("Value2", "Value3"), userProfile.getAttribute(KEY));
}

@Test
public void testAddAttributeDuplicateValues() {
UserProfile userProfile = new CommonProfile(true);
userProfile.addAttribute(KEY, List.of(VALUE));
userProfile.addAttribute(KEY, List.of(VALUE));
assertEquals(1, userProfile.getAttributes().size());
assertEquals(Arrays.asList(VALUE), userProfile.getAttribute(KEY));
}

@Test
public void testAddAttributeDeDuplicateValues() {
UserProfile userProfile = new CommonProfile(true);
userProfile.addAttribute(KEY, List.of(VALUE, "Value2"));
userProfile.addAttribute(KEY, List.of(VALUE, "Value3"));
assertEquals(1, userProfile.getAttributes().size());
assertEquals(Arrays.asList(VALUE, "Value2", "Value3"), userProfile.getAttribute(KEY));
}

@Test
public void testAddAuthenticationAttribute() {
final var userProfile = new CommonProfile();
Expand Down

0 comments on commit 7895d0f

Please sign in to comment.