Skip to content

Commit 8aaef77

Browse files
authored
Merge pull request #331 from mauromol/preserve-returned-attribute-order
Make the SamlResponse returned attribute map preserve attribute order
2 parents 6233278 + 1fba07d commit 8aaef77

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.ArrayList;
77
import java.util.Calendar;
88
import java.util.HashMap;
9+
import java.util.LinkedHashMap;
910
import java.util.List;
1011
import java.util.Map;
1112
import java.util.Objects;
@@ -573,7 +574,7 @@ public String getNameIdSPNameQualifier() throws Exception {
573574
*
574575
*/
575576
public HashMap<String, List<String>> getAttributes() throws XPathExpressionException, ValidationError {
576-
HashMap<String, List<String>> attributes = new HashMap<String, List<String>>();
577+
HashMap<String, List<String>> attributes = new LinkedHashMap<String, List<String>>();
577578

578579
NodeList nodes = this.queryAssertion("/saml:AttributeStatement/saml:Attribute");
579580

toolkit/src/main/java/com/onelogin/saml2/Auth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class Auth {
121121
/**
122122
* User attributes data.
123123
*/
124-
private Map<String, List<String>> attributes = new HashMap<String, List<String>>();
124+
private Map<String, List<String>> attributes = new LinkedHashMap<String, List<String>>();
125125

126126
/**
127127
* If user is authenticated.

toolkit/src/test/java/com/onelogin/saml2/test/AuthTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.security.cert.CertificateException;
3232
import java.util.ArrayList;
3333
import java.util.HashMap;
34+
import java.util.LinkedHashMap;
3435
import java.util.List;
3536
import java.util.Map;
3637

@@ -524,7 +525,7 @@ public void testProcessResponse() throws Exception {
524525
when(request.getParameterMap()).thenReturn(singletonMap("SAMLResponse", new String[]{samlResponseEncoded}));
525526
Auth auth2 = new Auth(settings, request, response);
526527

527-
HashMap<String, List<String>> expectedAttributes = new HashMap<String, List<String>>();
528+
HashMap<String, List<String>> expectedAttributes = new LinkedHashMap<String, List<String>>();
528529
List<String> attrValues = new ArrayList<String>();
529530
attrValues.add("smartin");
530531
List<String> attrValues2 = new ArrayList<String>();
@@ -538,9 +539,9 @@ public void testProcessResponse() throws Exception {
538539
attrValues5.add("Martin2");
539540
expectedAttributes.put("uid", attrValues);
540541
expectedAttributes.put("mail", attrValues2);
541-
expectedAttributes.put("eduPersonAffiliation", attrValues3);
542542
expectedAttributes.put("cn", attrValues4);
543543
expectedAttributes.put("sn", attrValues5);
544+
expectedAttributes.put("eduPersonAffiliation", attrValues3);
544545
List<String> keys = new ArrayList<String>(expectedAttributes.keySet());
545546

546547
assertFalse(auth2.isAuthenticated());

0 commit comments

Comments
 (0)