From e76de931ced8d02920e6a79d5418a33f146906e9 Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Fri, 25 Oct 2024 19:29:24 +0700 Subject: [PATCH] Polish Optional usage --- ...rvletOAuth2AuthorizedClientExchangeFilterFunction.java | 8 ++++---- .../web/server/authentication/SwitchUserWebFilter.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.java index d03f648d04..eb501c9b46 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServletOAuth2AuthorizedClientExchangeFilterFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -395,9 +395,9 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement } private Mono mergeRequestAttributesIfNecessary(ClientRequest request) { - if (!request.attribute(HTTP_SERVLET_REQUEST_ATTR_NAME).isPresent() - || !request.attribute(HTTP_SERVLET_RESPONSE_ATTR_NAME).isPresent() - || !request.attribute(AUTHENTICATION_ATTR_NAME).isPresent()) { + if (request.attribute(HTTP_SERVLET_REQUEST_ATTR_NAME).isEmpty() + || request.attribute(HTTP_SERVLET_RESPONSE_ATTR_NAME).isEmpty() + || request.attribute(AUTHENTICATION_ATTR_NAME).isEmpty()) { return mergeRequestAttributesFromContext(request); } return Mono.just(request); diff --git a/web/src/main/java/org/springframework/security/web/server/authentication/SwitchUserWebFilter.java b/web/src/main/java/org/springframework/security/web/server/authentication/SwitchUserWebFilter.java index cfc93a301a..8eab25cf1f 100644 --- a/web/src/main/java/org/springframework/security/web/server/authentication/SwitchUserWebFilter.java +++ b/web/src/main/java/org/springframework/security/web/server/authentication/SwitchUserWebFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -228,7 +228,7 @@ public class SwitchUserWebFilter implements WebFilter { @NonNull private Authentication attemptExitUser(Authentication currentAuthentication) { Optional sourceAuthentication = extractSourceAuthentication(currentAuthentication); - if (!sourceAuthentication.isPresent()) { + if (sourceAuthentication.isEmpty()) { this.logger.debug("Failed to find original user"); throw noOriginalAuthenticationException(); }