Skip to content

Commit 14092b5

Browse files
Change type shouldInflate
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent f73b031 commit 14092b5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

saml2/saml2-service-provider/src/main/java/org/springframework/security/saml2/provider/service/web/Saml2AuthenticationTokenConverter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import jakarta.servlet.http.HttpServletRequest;
2020

21-
import org.springframework.http.HttpMethod;
2221
import org.springframework.security.saml2.core.Saml2Error;
2322
import org.springframework.security.saml2.core.Saml2ErrorCodes;
2423
import org.springframework.security.saml2.core.Saml2ParameterNames;
@@ -43,7 +42,7 @@ public final class Saml2AuthenticationTokenConverter implements AuthenticationCo
4342

4443
private Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository;
4544

46-
private Boolean shouldInflate;
45+
private boolean shouldInflate = true;
4746

4847
/**
4948
* Constructs a {@link Saml2AuthenticationTokenConverter} given a strategy for
@@ -89,7 +88,7 @@ public void setAuthenticationRequestRepository(
8988
}
9089

9190
/**
92-
* Use the given {@code shouldInflate} to inflate request.
91+
* Use the given {@code shouldInflate} to inflate request. Default is {@code true}.
9392
* @param shouldInflate the {@code shouldInflate} to use
9493
* @since 7.0
9594
*/
@@ -98,10 +97,6 @@ public void setShouldInflateResponse(boolean shouldInflate) {
9897
}
9998

10099
private String decode(HttpServletRequest request) {
101-
// prevent to break passivity in Saml2LoginBeanDefinitionParserTests
102-
if (this.shouldInflate == null) {
103-
this.shouldInflate = HttpMethod.GET.matches(request.getMethod());
104-
}
105100
String encoded = request.getParameter(Saml2ParameterNames.SAML_RESPONSE);
106101
if (encoded == null) {
107102
return null;

saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/web/Saml2AuthenticationTokenConverterTests.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public class Saml2AuthenticationTokenConverterTests {
6161
public void convertWhenSamlResponseThenToken() {
6262
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(
6363
this.relyingPartyRegistrationResolver);
64-
converter.setShouldInflateResponse(false);
6564
given(this.relyingPartyRegistrationResolver.resolve(any(HttpServletRequest.class), any()))
6665
.willReturn(this.relyingPartyRegistration);
6766
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -77,7 +76,6 @@ public void convertWhenSamlResponseThenToken() {
7776
public void convertWhenSamlResponseWithRelyingPartyRegistrationResolver(
7877
@Mock RelyingPartyRegistrationResolver resolver) {
7978
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(resolver);
80-
converter.setShouldInflateResponse(false);
8179
given(resolver.resolve(any(HttpServletRequest.class), any())).willReturn(this.relyingPartyRegistration);
8280
MockHttpServletRequest request = new MockHttpServletRequest();
8381
request.setParameter(Saml2ParameterNames.SAML_RESPONSE,
@@ -163,7 +161,6 @@ public void convertWhenGetRequestInvalidDeflatedThenSaml2AuthenticationException
163161
public void convertWhenUsingSamlUtilsBase64ThenXmlIsValid() throws Exception {
164162
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(
165163
this.relyingPartyRegistrationResolver);
166-
converter.setShouldInflateResponse(false);
167164
given(this.relyingPartyRegistrationResolver.resolve(any(HttpServletRequest.class), any()))
168165
.willReturn(this.relyingPartyRegistration);
169166
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -181,7 +178,6 @@ public void convertWhenSavedAuthenticationRequestThenToken() {
181178
.willReturn(this.relyingPartyRegistration.getRegistrationId());
182179
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(
183180
this.relyingPartyRegistrationResolver);
184-
converter.setShouldInflateResponse(false);
185181
converter.setAuthenticationRequestRepository(authenticationRequestRepository);
186182
given(this.relyingPartyRegistrationResolver.resolve(any(HttpServletRequest.class), any()))
187183
.willReturn(this.relyingPartyRegistration);
@@ -207,7 +203,6 @@ public void convertWhenSavedAuthenticationRequestThenTokenWithRelyingPartyRegist
207203
.willReturn(this.relyingPartyRegistration.getRegistrationId());
208204
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(resolver);
209205
converter.setAuthenticationRequestRepository(authenticationRequestRepository);
210-
converter.setShouldInflateResponse(false);
211206
given(resolver.resolve(any(HttpServletRequest.class), any())).willReturn(this.relyingPartyRegistration);
212207
given(authenticationRequestRepository.loadAuthenticationRequest(any(HttpServletRequest.class)))
213208
.willReturn(authenticationRequest);
@@ -235,6 +230,22 @@ public void setAuthenticationRequestRepositoryWhenNullThenIllegalArgument() {
235230
.isThrownBy(() -> converter.setAuthenticationRequestRepository(null));
236231
}
237232

233+
@Test
234+
public void convertWhenGetRequestWithoutInflate() {
235+
Saml2AuthenticationTokenConverter converter = new Saml2AuthenticationTokenConverter(
236+
this.relyingPartyRegistrationResolver);
237+
converter.setShouldInflateResponse(false);
238+
given(this.relyingPartyRegistrationResolver.resolve(any(HttpServletRequest.class), any()))
239+
.willReturn(this.relyingPartyRegistration);
240+
MockHttpServletRequest request = new MockHttpServletRequest();
241+
request.setMethod("GET");
242+
request.setParameter(Saml2ParameterNames.SAML_RESPONSE, Saml2Utils.samlEncode("response".getBytes(StandardCharsets.UTF_8)));
243+
Saml2AuthenticationToken token = converter.convert(request);
244+
assertThat(token.getSaml2Response()).isEqualTo("response");
245+
assertThat(token.getRelyingPartyRegistration().getRegistrationId())
246+
.isEqualTo(this.relyingPartyRegistration.getRegistrationId());
247+
}
248+
238249
private void validateSsoCircleXml(String xml) {
239250
assertThat(xml).contains("InResponseTo=\"ARQ9a73ead-7dcf-45a8-89eb-26f3c9900c36\"")
240251
.contains(" ID=\"s246d157446618e90e43fb79bdd4d9e9e19cf2c7c4\"")

0 commit comments

Comments
 (0)