Skip to content

Commit 834370d

Browse files
committed
Update Deprecated Spring Web Usage
1 parent 216680b commit 834370d

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OidcBackChannelLogoutHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void eachLogout(HttpServletRequest request, OidcBackChannelLogoutAuthent
127127
String computeLogoutEndpoint(HttpServletRequest request, OidcBackChannelLogoutAuthentication token) {
128128
// @formatter:off
129129
UriComponents uriComponents = UriComponentsBuilder
130-
.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
130+
.fromUriString(UrlUtils.buildFullRequestUrl(request))
131131
.replacePath(request.getContextPath())
132132
.replaceQuery(null)
133133
.fragment(null)

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/web/logout/OidcClientInitiatedLogoutSuccessHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private String postLogoutRedirectUri(HttpServletRequest request, ClientRegistrat
9595
}
9696
// @formatter:off
9797
UriComponents uriComponents = UriComponentsBuilder
98-
.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
98+
.fromUriString(UrlUtils.buildFullRequestUrl(request))
9999
.replacePath(request.getContextPath())
100100
.replaceQuery(null)
101101
.fragment(null)

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/DefaultOAuth2AuthorizationRequestResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static String expandRedirectUri(HttpServletRequest request, ClientRegist
226226
Map<String, String> uriVariables = new HashMap<>();
227227
uriVariables.put("registrationId", clientRegistration.getRegistrationId());
228228
// @formatter:off
229-
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
229+
UriComponents uriComponents = UriComponentsBuilder.fromUriString(UrlUtils.buildFullRequestUrl(request))
230230
.replacePath(request.getContextPath())
231231
.replaceQuery(null)
232232
.fragment(null)

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2LoginAuthenticationFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
184184
throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
185185
}
186186
// @formatter:off
187-
String redirectUri = UriComponentsBuilder.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
187+
String redirectUri = UriComponentsBuilder.fromUriString(UrlUtils.buildFullRequestUrl(request))
188188
.replaceQuery(null)
189189
.build()
190190
.toUriString();

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.http.HttpHeaders;
3131
import org.springframework.http.HttpStatus;
32+
import org.springframework.http.HttpStatusCode;
3233
import org.springframework.security.authentication.AnonymousAuthenticationToken;
3334
import org.springframework.security.core.Authentication;
3435
import org.springframework.security.core.authority.AuthorityUtils;
@@ -469,7 +470,7 @@ private final class AuthorizationFailureForwarder implements ClientResponseHandl
469470
* A map of HTTP Status Code to OAuth 2.0 Error codes for HTTP status codes that
470471
* should be interpreted as authentication or authorization failures.
471472
*/
472-
private final Map<Integer, String> httpStatusToOAuth2ErrorCodeMap;
473+
private final Map<HttpStatusCode, String> httpStatusToOAuth2ErrorCodeMap;
473474

474475
/**
475476
* The {@link ReactiveOAuth2AuthorizationFailureHandler} to notify when an
@@ -480,9 +481,9 @@ private final class AuthorizationFailureForwarder implements ClientResponseHandl
480481
private AuthorizationFailureForwarder(ReactiveOAuth2AuthorizationFailureHandler authorizationFailureHandler) {
481482
Assert.notNull(authorizationFailureHandler, "authorizationFailureHandler cannot be null");
482483
this.authorizationFailureHandler = authorizationFailureHandler;
483-
Map<Integer, String> httpStatusToOAuth2Error = new HashMap<>();
484-
httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED.value(), OAuth2ErrorCodes.INVALID_TOKEN);
485-
httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN.value(), OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
484+
Map<HttpStatusCode, String> httpStatusToOAuth2Error = new HashMap<>();
485+
httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED, OAuth2ErrorCodes.INVALID_TOKEN);
486+
httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN, OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
486487
this.httpStatusToOAuth2ErrorCodeMap = Collections.unmodifiableMap(httpStatusToOAuth2Error);
487488
}
488489

@@ -525,10 +526,10 @@ private OAuth2Error resolveErrorIfPossible(ClientResponse response) {
525526
authParameters.get(OAuth2ParameterNames.ERROR_URI));
526527
}
527528
}
528-
return resolveErrorIfPossible(response.statusCode().value());
529+
return resolveErrorIfPossible(response.statusCode());
529530
}
530531

531-
private OAuth2Error resolveErrorIfPossible(int statusCode) {
532+
private OAuth2Error resolveErrorIfPossible(HttpStatusCode statusCode) {
532533
if (this.httpStatusToOAuth2ErrorCodeMap.containsKey(statusCode)) {
533534
return new OAuth2Error(this.httpStatusToOAuth2ErrorCodeMap.get(statusCode), null,
534535
"https://tools.ietf.org/html/rfc6750#section-3.1");
@@ -563,7 +564,7 @@ private Map<String, String> parseAuthParameters(String wwwAuthenticateHeader) {
563564
*/
564565
private Mono<Void> handleWebClientResponseException(ClientRequest request,
565566
WebClientResponseException exception) {
566-
return Mono.justOrEmpty(resolveErrorIfPossible(exception.getRawStatusCode())).flatMap((oauth2Error) -> {
567+
return Mono.justOrEmpty(resolveErrorIfPossible(exception.getStatusCode())).flatMap((oauth2Error) -> {
567568
Mono<Optional<ServerWebExchange>> serverWebExchange = effectiveServerWebExchange(request);
568569
Mono<String> clientRegistrationId = effectiveClientRegistrationId(request);
569570
return Mono

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.springframework.http.HttpHeaders;
3434
import org.springframework.http.HttpStatus;
35+
import org.springframework.http.HttpStatusCode;
3536
import org.springframework.security.authentication.AbstractAuthenticationToken;
3637
import org.springframework.security.authentication.AnonymousAuthenticationToken;
3738
import org.springframework.security.core.Authentication;
@@ -585,7 +586,7 @@ private static final class AuthorizationFailureForwarder implements ClientRespon
585586
* A map of HTTP status code to OAuth 2.0 error code for HTTP status codes that
586587
* should be interpreted as authentication or authorization failures.
587588
*/
588-
private final Map<Integer, String> httpStatusToOAuth2ErrorCodeMap;
589+
private final Map<HttpStatusCode, String> httpStatusToOAuth2ErrorCodeMap;
589590

590591
/**
591592
* The {@link OAuth2AuthorizationFailureHandler} to notify when an
@@ -596,9 +597,9 @@ private static final class AuthorizationFailureForwarder implements ClientRespon
596597
private AuthorizationFailureForwarder(OAuth2AuthorizationFailureHandler authorizationFailureHandler) {
597598
Assert.notNull(authorizationFailureHandler, "authorizationFailureHandler cannot be null");
598599
this.authorizationFailureHandler = authorizationFailureHandler;
599-
Map<Integer, String> httpStatusToOAuth2Error = new HashMap<>();
600-
httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED.value(), OAuth2ErrorCodes.INVALID_TOKEN);
601-
httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN.value(), OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
600+
Map<HttpStatusCode, String> httpStatusToOAuth2Error = new HashMap<>();
601+
httpStatusToOAuth2Error.put(HttpStatus.UNAUTHORIZED, OAuth2ErrorCodes.INVALID_TOKEN);
602+
httpStatusToOAuth2Error.put(HttpStatus.FORBIDDEN, OAuth2ErrorCodes.INSUFFICIENT_SCOPE);
602603
this.httpStatusToOAuth2ErrorCodeMap = Collections.unmodifiableMap(httpStatusToOAuth2Error);
603604
}
604605

@@ -641,10 +642,10 @@ private OAuth2Error resolveErrorIfPossible(ClientResponse response) {
641642
authParameters.get(OAuth2ParameterNames.ERROR_URI));
642643
}
643644
}
644-
return resolveErrorIfPossible(response.statusCode().value());
645+
return resolveErrorIfPossible(response.statusCode());
645646
}
646647

647-
private OAuth2Error resolveErrorIfPossible(int statusCode) {
648+
private OAuth2Error resolveErrorIfPossible(HttpStatusCode statusCode) {
648649
if (this.httpStatusToOAuth2ErrorCodeMap.containsKey(statusCode)) {
649650
return new OAuth2Error(this.httpStatusToOAuth2ErrorCodeMap.get(statusCode), null,
650651
"https://tools.ietf.org/html/rfc6750#section-3.1");
@@ -678,7 +679,7 @@ private Map<String, String> parseAuthParameters(String wwwAuthenticateHeader) {
678679
*/
679680
private Mono<Void> handleWebClientResponseException(ClientRequest request,
680681
WebClientResponseException exception) {
681-
return Mono.justOrEmpty(resolveErrorIfPossible(exception.getRawStatusCode())).flatMap((oauth2Error) -> {
682+
return Mono.justOrEmpty(resolveErrorIfPossible(exception.getStatusCode())).flatMap((oauth2Error) -> {
682683
Map<String, Object> attrs = request.attributes();
683684
OAuth2AuthorizedClient authorizedClient = getOAuth2AuthorizedClient(attrs);
684685
if (authorizedClient == null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static UriResolver uriResolver(HttpServletRequest request, RelyingPartyRe
8282
private static Map<String, String> uriVariables(HttpServletRequest request) {
8383
String baseUrl = getApplicationUri(request);
8484
Map<String, String> uriVariables = new HashMap<>();
85-
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(baseUrl)
85+
UriComponents uriComponents = UriComponentsBuilder.fromUriString(baseUrl)
8686
.replaceQuery(null)
8787
.fragment(null)
8888
.build();
@@ -103,7 +103,7 @@ private static Map<String, String> uriVariables(HttpServletRequest request) {
103103
}
104104

105105
private static String getApplicationUri(HttpServletRequest request) {
106-
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(UrlUtils.buildFullRequestUrl(request))
106+
UriComponents uriComponents = UriComponentsBuilder.fromUriString(UrlUtils.buildFullRequestUrl(request))
107107
.replacePath(request.getContextPath())
108108
.replaceQuery(null)
109109
.fragment(null)

0 commit comments

Comments
 (0)