Skip to content

Commit efca20e

Browse files
authored
Add 8.19 transport version for IdP Extension Attr (#129233)
This adds a new patch level TransportVersion in preparation for backporting #128805
1 parent a520953 commit efca20e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static TransportVersion def(int id) {
195195
public static final TransportVersion ML_INFERENCE_MISTRAL_CHAT_COMPLETION_ADDED_8_19 = def(8_841_0_47);
196196
public static final TransportVersion ML_INFERENCE_ELASTIC_RERANK_ADDED_8_19 = def(8_841_0_48);
197197
public static final TransportVersion NONE_CHUNKING_STRATEGY_8_19 = def(8_841_0_49);
198+
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19 = def(8_841_0_50);
198199
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
199200
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
200201
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_2 = def(9_000_0_11);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.function.BiConsumer;
4444

4545
import static org.elasticsearch.TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST;
46+
import static org.elasticsearch.TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19;
4647

4748
/**
4849
* This class models the storage of a {@link SamlServiceProvider} as an Elasticsearch document.
@@ -276,7 +277,8 @@ public SamlServiceProviderDocument(StreamInput in) throws IOException {
276277
attributeNames.name = in.readOptionalString();
277278
attributeNames.roles = in.readOptionalString();
278279

279-
if (in.getTransportVersion().onOrAfter(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST)) {
280+
if (in.getTransportVersion().isPatchFrom(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19)
281+
|| in.getTransportVersion().onOrAfter(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST)) {
280282
attributeNames.extensions = in.readCollectionAsImmutableSet(StreamInput::readString);
281283
}
282284

@@ -305,7 +307,8 @@ public void writeTo(StreamOutput out) throws IOException {
305307
out.writeOptionalString(attributeNames.name);
306308
out.writeOptionalString(attributeNames.roles);
307309

308-
if (out.getTransportVersion().onOrAfter(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST)) {
310+
if (out.getTransportVersion().isPatchFrom(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19)
311+
|| out.getTransportVersion().onOrAfter(IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST)) {
309312
out.writeStringCollection(attributeNames.extensions);
310313
}
311314

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Set;
3333

3434
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
35+
import static org.hamcrest.Matchers.empty;
3536
import static org.hamcrest.Matchers.emptyIterable;
3637
import static org.hamcrest.Matchers.equalTo;
3738
import static org.hamcrest.Matchers.not;
@@ -90,6 +91,31 @@ public void testStreamRoundTripWithAllFields() throws Exception {
9091
assertThat(assertSerializationRoundTrip(doc2), equalTo(doc1));
9192
}
9293

94+
public void testSerializationBeforeExtensionAttributes() throws Exception {
95+
final SamlServiceProviderDocument original = createFullDocument();
96+
final TransportVersion version = randomBoolean()
97+
? TransportVersionUtils.randomVersionBetween(
98+
random(),
99+
TransportVersions.V_9_0_0,
100+
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST)
101+
)
102+
: TransportVersionUtils.randomVersionBetween(
103+
random(),
104+
TransportVersions.V_8_0_0,
105+
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST_8_19)
106+
);
107+
final SamlServiceProviderDocument copy = copyWriteable(
108+
original,
109+
new NamedWriteableRegistry(List.of()),
110+
SamlServiceProviderDocument::new,
111+
version
112+
);
113+
assertThat(copy.attributeNames.extensions, empty());
114+
115+
copy.attributeNames.setExtensions(original.attributeNames.extensions);
116+
assertThat(copy, equalTo(original));
117+
}
118+
93119
private SamlServiceProviderDocument createFullDocument() throws GeneralSecurityException, IOException {
94120
final List<X509Credential> credentials = readCredentials();
95121
final List<X509Certificate> certificates = credentials.stream().map(X509Credential::getEntityCertificate).toList();
@@ -121,6 +147,7 @@ private SamlServiceProviderDocument createFullDocument() throws GeneralSecurityE
121147
doc1.attributeNames.setEmail("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
122148
doc1.attributeNames.setName("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
123149
doc1.attributeNames.setRoles("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8));
150+
doc1.attributeNames.setExtensions(List.of("urn:" + randomAlphaOfLengthBetween(4, 8) + "." + randomAlphaOfLengthBetween(4, 8)));
124151
return doc1;
125152
}
126153

@@ -162,7 +189,7 @@ private SamlServiceProviderDocument assertXContentRoundTrip(SamlServiceProviderD
162189
private SamlServiceProviderDocument assertSerializationRoundTrip(SamlServiceProviderDocument doc) throws IOException {
163190
final TransportVersion version = TransportVersionUtils.randomVersionBetween(
164191
random(),
165-
TransportVersions.V_8_0_0,
192+
TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ALLOW_LIST,
166193
TransportVersion.current()
167194
);
168195
final SamlServiceProviderDocument read = copyWriteable(

0 commit comments

Comments
 (0)