|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -43,6 +43,8 @@ public final class Saml2AuthenticationTokenConverter implements AuthenticationCo
|
43 | 43 |
|
44 | 44 | private Saml2AuthenticationRequestRepository<AbstractSaml2AuthenticationRequest> authenticationRequestRepository;
|
45 | 45 |
|
| 46 | + private boolean shouldConvertGetRequests = true; |
| 47 | + |
46 | 48 | /**
|
47 | 49 | * Constructs a {@link Saml2AuthenticationTokenConverter} given a strategy for
|
48 | 50 | * resolving {@link RelyingPartyRegistration}s
|
@@ -86,16 +88,27 @@ public void setAuthenticationRequestRepository(
|
86 | 88 | this.authenticationRequestRepository = authenticationRequestRepository;
|
87 | 89 | }
|
88 | 90 |
|
| 91 | + /** |
| 92 | + * Use the given {@code shouldConvertGetRequests} to convert {@code GET} requests. |
| 93 | + * Default is {@code true}. |
| 94 | + * @param shouldConvertGetRequests the {@code shouldConvertGetRequests} to use |
| 95 | + * @since 7.0 |
| 96 | + */ |
| 97 | + public void setShouldConvertGetRequests(boolean shouldConvertGetRequests) { |
| 98 | + this.shouldConvertGetRequests = shouldConvertGetRequests; |
| 99 | + } |
| 100 | + |
89 | 101 | private String decode(HttpServletRequest request) {
|
90 | 102 | String encoded = request.getParameter(Saml2ParameterNames.SAML_RESPONSE);
|
91 | 103 | if (encoded == null) {
|
92 | 104 | return null;
|
93 | 105 | }
|
| 106 | + boolean isGet = HttpMethod.GET.matches(request.getMethod()); |
| 107 | + if (!this.shouldConvertGetRequests && isGet) { |
| 108 | + return null; |
| 109 | + } |
94 | 110 | try {
|
95 |
| - return Saml2Utils.withEncoded(encoded) |
96 |
| - .requireBase64(true) |
97 |
| - .inflate(HttpMethod.GET.matches(request.getMethod())) |
98 |
| - .decode(); |
| 111 | + return Saml2Utils.withEncoded(encoded).requireBase64(true).inflate(isGet).decode(); |
99 | 112 | }
|
100 | 113 | catch (Exception ex) {
|
101 | 114 | throw new Saml2AuthenticationException(new Saml2Error(Saml2ErrorCodes.INVALID_RESPONSE, ex.getMessage()),
|
|
0 commit comments