Skip to content

Commit 70368c2

Browse files
authored
Add transport version support for IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 (#128798)
1 parent d77351c commit 70368c2

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

docs/changelog/128798.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 128798
2+
summary: Add transport version support for IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19
3+
area: IdentityProvider
4+
type: enhancement
5+
issues: []

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static TransportVersion def(int id) {
184184
public static final TransportVersion ML_INFERENCE_SAGEMAKER_CHAT_COMPLETION_8_19 = def(8_841_0_37);
185185
public static final TransportVersion ML_INFERENCE_VERTEXAI_CHATCOMPLETION_ADDED_8_19 = def(8_841_0_38);
186186
public static final TransportVersion INFERENCE_CUSTOM_SERVICE_ADDED_8_19 = def(8_841_0_39);
187+
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 = def(8_841_0_40);
187188
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
188189
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
189190
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/action/SamlInitiateSingleSignOnRequest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public SamlInitiateSingleSignOnRequest(StreamInput in) throws IOException {
3131
spEntityId = in.readString();
3232
assertionConsumerService = in.readString();
3333
samlAuthenticationState = in.readOptionalWriteable(SamlAuthenticationState::new);
34-
if (in.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
34+
if (in.getTransportVersion().isPatchFrom(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
35+
|| in.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
3536
attributes = in.readOptionalWriteable(SamlInitiateSingleSignOnAttributes::new);
3637
}
3738
}
@@ -99,7 +100,8 @@ public void writeTo(StreamOutput out) throws IOException {
99100
out.writeString(spEntityId);
100101
out.writeString(assertionConsumerService);
101102
out.writeOptionalWriteable(samlAuthenticationState);
102-
if (out.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
103+
if (out.getTransportVersion().isPatchFrom(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
104+
|| out.getTransportVersion().onOrAfter(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)) {
103105
out.writeOptionalWriteable(attributes);
104106
}
105107
}

x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/action/SamlInitiateSingleSignOnRequestTests.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ public void testSerializationCurrentVersion() throws Exception {
6363
}
6464
}
6565

66+
public void testSerializationOldButCompatibleTransportVersion() throws Exception {
67+
final SamlInitiateSingleSignOnRequest request = new SamlInitiateSingleSignOnRequest();
68+
request.setSpEntityId("https://kibana_url");
69+
request.setAssertionConsumerService("https://kibana_url/acs");
70+
if (randomBoolean()) {
71+
request.setAttributes(
72+
new SamlInitiateSingleSignOnAttributes(
73+
Map.ofEntries(
74+
Map.entry("http://idp.elastic.co/attribute/custom1", List.of("foo")),
75+
Map.entry("http://idp.elastic.co/attribute/custom2", List.of("bar", "baz"))
76+
)
77+
)
78+
);
79+
}
80+
assertThat("An invalid request is not guaranteed to serialize correctly", request.validate(), nullValue());
81+
final BytesStreamOutput out = new BytesStreamOutput();
82+
out.setTransportVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19);
83+
request.writeTo(out);
84+
85+
try (StreamInput in = out.bytes().streamInput()) {
86+
in.setTransportVersion(out.getTransportVersion());
87+
final SamlInitiateSingleSignOnRequest request1 = new SamlInitiateSingleSignOnRequest(in);
88+
assertThat(request1.getSpEntityId(), equalTo(request.getSpEntityId()));
89+
assertThat(request1.getAssertionConsumerService(), equalTo(request.getAssertionConsumerService()));
90+
assertThat(request1.getAttributes(), equalTo(request.getAttributes()));
91+
final ActionRequestValidationException validationException = request1.validate();
92+
assertNull(validationException);
93+
}
94+
}
95+
6696
public void testSerializationOldTransportVersion() throws Exception {
6797
final SamlInitiateSingleSignOnRequest request = new SamlInitiateSingleSignOnRequest();
6898
request.setSpEntityId("https://kibana_url");
@@ -83,7 +113,7 @@ public void testSerializationOldTransportVersion() throws Exception {
83113
TransportVersionUtils.randomVersionBetween(
84114
random(),
85115
TransportVersions.MINIMUM_COMPATIBLE,
86-
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES)
116+
TransportVersionUtils.getPreviousVersion(TransportVersions.IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19)
87117
)
88118
);
89119
request.writeTo(out);

0 commit comments

Comments
 (0)