Skip to content

Commit 3cfaf0d

Browse files
committed
Avoid LinkedMultiValueMap in Serializable Object
Closes gh-11785
1 parent fbfa13b commit 3cfaf0d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collection;
2424
import java.util.Collections;
2525
import java.util.HashMap;
26+
import java.util.LinkedHashMap;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.function.Consumer;
@@ -659,7 +660,7 @@ private static Map<String, List<Object>> getAssertionAttributes(Assertion assert
659660
attributeMap.addAll(attribute.getName(), attributeValues);
660661
}
661662
}
662-
return attributeMap;
663+
return new LinkedHashMap<>(attributeMap); // gh-11785
663664
}
664665

665666
private static List<String> getSessionIndexes(Assertion assertion) {

saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProviderTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import javax.xml.namespace.QName;
3434

35+
import com.fasterxml.jackson.databind.ObjectMapper;
3536
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
3637
import org.junit.jupiter.api.Test;
3738
import org.opensaml.core.xml.XMLObject;
@@ -68,6 +69,7 @@
6869

6970
import org.springframework.core.convert.converter.Converter;
7071
import org.springframework.security.core.Authentication;
72+
import org.springframework.security.jackson2.SecurityJackson2Modules;
7173
import org.springframework.security.saml2.Saml2Exception;
7274
import org.springframework.security.saml2.core.Saml2Error;
7375
import org.springframework.security.saml2.core.Saml2ErrorCodes;
@@ -349,6 +351,23 @@ public void authenticateWhenAssertionContainsAttributesThenItSucceeds() {
349351
assertThat(principal.getSessionIndexes()).contains("session-index");
350352
}
351353

354+
// gh-11785
355+
@Test
356+
public void deserializeWhenAssertionContainsAttributesThenWorks() throws Exception {
357+
ObjectMapper mapper = new ObjectMapper();
358+
ClassLoader loader = getClass().getClassLoader();
359+
mapper.registerModules(SecurityJackson2Modules.getModules(loader));
360+
Response response = response();
361+
Assertion assertion = assertion();
362+
List<AttributeStatement> attributes = TestOpenSamlObjects.attributeStatements();
363+
assertion.getAttributeStatements().addAll(attributes);
364+
response.getAssertions().add(signed(assertion));
365+
Saml2AuthenticationToken token = token(response, verifying(registration()));
366+
Authentication authentication = this.provider.authenticate(token);
367+
String result = mapper.writeValueAsString(authentication);
368+
mapper.readValue(result, Authentication.class);
369+
}
370+
352371
@Test
353372
public void authenticateWhenAssertionContainsCustomAttributesThenItSucceeds() {
354373
Response response = response();

0 commit comments

Comments
 (0)