Skip to content

Commit 5920d1b

Browse files
authored
Treat roles as a SortedSet (#55201)
The Saml SP document stored the role mapping in a Set, but this made the order in XContent inconsistent. This switched it to use a TreeSet. Resolves: #54733
1 parent a219694 commit 5920d1b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocument.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.util.List;
3939
import java.util.Objects;
4040
import java.util.Set;
41+
import java.util.SortedSet;
42+
import java.util.TreeSet;
4143
import java.util.function.BiConsumer;
4244
import java.util.stream.Collectors;
4345

@@ -52,14 +54,15 @@ public class SamlServiceProviderDocument implements ToXContentObject, Writeable
5254

5355
public static class Privileges {
5456
public String resource;
55-
public Set<String> rolePatterns = Set.of();
57+
// we use a sorted set so that the order is consistent in XContent APIs
58+
public SortedSet<String> rolePatterns = new TreeSet<>();
5659

5760
public void setResource(String resource) {
5861
this.resource = resource;
5962
}
6063

6164
public void setRolePatterns(Collection<String> rolePatterns) {
62-
this.rolePatterns = Set.copyOf(rolePatterns);
65+
this.rolePatterns = new TreeSet<>(rolePatterns);
6366
}
6467

6568
@Override
@@ -258,7 +261,7 @@ public SamlServiceProviderDocument(StreamInput in) throws IOException {
258261
authenticationExpiryMillis = in.readOptionalVLong();
259262

260263
privileges.resource = in.readString();
261-
privileges.rolePatterns = in.readSet(StreamInput::readString);
264+
privileges.rolePatterns = new TreeSet<>(in.readSet(StreamInput::readString));
262265

263266
attributeNames.principal = in.readString();
264267
attributeNames.email = in.readOptionalString();

x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/sp/SamlServiceProviderDocumentTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void testXContentRoundTripWithMinimalFields() throws Exception {
6868
assertThat(assertXContentRoundTrip(doc2), equalTo(doc1));
6969
}
7070

71-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/54733")
7271
public void testXContentRoundTripWithAllFields() throws Exception {
7372
final SamlServiceProviderDocument doc1 = createFullDocument();
7473
final SamlServiceProviderDocument doc2 = assertXContentRoundTrip(doc1);
@@ -81,7 +80,6 @@ public void testStreamRoundTripWithMinimalFields() throws Exception {
8180
assertThat(assertSerializationRoundTrip(doc2), equalTo(doc1));
8281
}
8382

84-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/54733")
8583
public void testStreamRoundTripWithAllFields() throws Exception {
8684
final SamlServiceProviderDocument doc1 = createFullDocument();
8785
final SamlServiceProviderDocument doc2 = assertXContentRoundTrip(doc1);

0 commit comments

Comments
 (0)