diff --git a/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParser.java index 1672d1faa6..de22300ca4 100644 --- a/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParser.java @@ -94,7 +94,7 @@ final class OAuth2ClientBeanDefinitionParser implements BeanDefinitionParser { .rootBeanDefinition(OAuth2AuthorizationRequestRedirectFilter.class); String authorizationRequestResolverRef = (authorizationCodeGrantElt != null) ? authorizationCodeGrantElt.getAttribute(ATT_AUTHORIZATION_REQUEST_RESOLVER_REF) : null; - if (!StringUtils.isEmpty(authorizationRequestResolverRef)) { + if (StringUtils.hasLength(authorizationRequestResolverRef)) { authorizationRequestRedirectFilterBuilder.addConstructorArgReference(authorizationRequestResolverRef); } else { @@ -122,7 +122,7 @@ final class OAuth2ClientBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getAuthorizationRequestRepository(Element element) { String authorizationRequestRepositoryRef = (element != null) ? element.getAttribute(ATT_AUTHORIZATION_REQUEST_REPOSITORY_REF) : null; - if (!StringUtils.isEmpty(authorizationRequestRepositoryRef)) { + if (StringUtils.hasLength(authorizationRequestRepositoryRef)) { return new RuntimeBeanReference(authorizationRequestRepositoryRef); } return BeanDefinitionBuilder.rootBeanDefinition( @@ -143,7 +143,7 @@ final class OAuth2ClientBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getAccessTokenResponseClient(Element element) { String accessTokenResponseClientRef = (element != null) ? element.getAttribute(ATT_ACCESS_TOKEN_RESPONSE_CLIENT_REF) : null; - if (!StringUtils.isEmpty(accessTokenResponseClientRef)) { + if (StringUtils.hasLength(accessTokenResponseClientRef)) { return new RuntimeBeanReference(accessTokenResponseClientRef); } return BeanDefinitionBuilder.rootBeanDefinition( diff --git a/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParserUtils.java b/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParserUtils.java index 8b8a333c7b..af15479a74 100644 --- a/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParserUtils.java +++ b/config/src/main/java/org/springframework/security/config/http/OAuth2ClientBeanDefinitionParserUtils.java @@ -42,7 +42,7 @@ final class OAuth2ClientBeanDefinitionParserUtils { static BeanMetadataElement getClientRegistrationRepository(Element element) { String clientRegistrationRepositoryRef = element.getAttribute(ATT_CLIENT_REGISTRATION_REPOSITORY_REF); - if (!StringUtils.isEmpty(clientRegistrationRepositoryRef)) { + if (StringUtils.hasLength(clientRegistrationRepositoryRef)) { return new RuntimeBeanReference(clientRegistrationRepositoryRef); } return new RuntimeBeanReference(ClientRegistrationRepository.class); @@ -50,7 +50,7 @@ final class OAuth2ClientBeanDefinitionParserUtils { static BeanMetadataElement getAuthorizedClientRepository(Element element) { String authorizedClientRepositoryRef = element.getAttribute(ATT_AUTHORIZED_CLIENT_REPOSITORY_REF); - if (!StringUtils.isEmpty(authorizedClientRepositoryRef)) { + if (StringUtils.hasLength(authorizedClientRepositoryRef)) { return new RuntimeBeanReference(authorizedClientRepositoryRef); } return null; @@ -58,7 +58,7 @@ final class OAuth2ClientBeanDefinitionParserUtils { static BeanMetadataElement getAuthorizedClientService(Element element) { String authorizedClientServiceRef = element.getAttribute(ATT_AUTHORIZED_CLIENT_SERVICE_REF); - if (!StringUtils.isEmpty(authorizedClientServiceRef)) { + if (StringUtils.hasLength(authorizedClientServiceRef)) { return new RuntimeBeanReference(authorizedClientServiceRef); } return null; diff --git a/config/src/main/java/org/springframework/security/config/http/OAuth2LoginBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/OAuth2LoginBeanDefinitionParser.java index eb6ac43500..61229a8774 100644 --- a/config/src/main/java/org/springframework/security/config/http/OAuth2LoginBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/OAuth2LoginBeanDefinitionParser.java @@ -175,7 +175,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { } Object source = parserContext.extractSource(element); String loginProcessingUrl = element.getAttribute(ATT_LOGIN_PROCESSING_URL); - if (!StringUtils.isEmpty(loginProcessingUrl)) { + if (StringUtils.hasLength(loginProcessingUrl)) { WebConfigUtils.validateHttpRedirect(loginProcessingUrl, parserContext, source); oauth2LoginAuthenticationFilterBuilder.addConstructorArgValue(loginProcessingUrl); } @@ -187,7 +187,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { .rootBeanDefinition(OAuth2LoginAuthenticationProvider.class) .addConstructorArgValue(accessTokenResponseClient).addConstructorArgValue(oauth2UserService); String userAuthoritiesMapperRef = element.getAttribute(ATT_USER_AUTHORITIES_MAPPER_REF); - if (!StringUtils.isEmpty(userAuthoritiesMapperRef)) { + if (StringUtils.hasLength(userAuthoritiesMapperRef)) { oauth2LoginAuthenticationProviderBuilder.addPropertyReference("authoritiesMapper", userAuthoritiesMapperRef); } @@ -197,7 +197,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { BeanDefinitionBuilder oauth2AuthorizationRequestRedirectFilterBuilder = BeanDefinitionBuilder .rootBeanDefinition(OAuth2AuthorizationRequestRedirectFilter.class); String authorizationRequestResolverRef = element.getAttribute(ATT_AUTHORIZATION_REQUEST_RESOLVER_REF); - if (!StringUtils.isEmpty(authorizationRequestResolverRef)) { + if (StringUtils.hasLength(authorizationRequestResolverRef)) { oauth2AuthorizationRequestRedirectFilterBuilder.addConstructorArgReference(authorizationRequestResolverRef); } else { @@ -210,7 +210,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { this.oauth2AuthorizationRequestRedirectFilter = oauth2AuthorizationRequestRedirectFilterBuilder .getBeanDefinition(); String authenticationSuccessHandlerRef = element.getAttribute(ATT_AUTHENTICATION_SUCCESS_HANDLER_REF); - if (!StringUtils.isEmpty(authenticationSuccessHandlerRef)) { + if (StringUtils.hasLength(authenticationSuccessHandlerRef)) { oauth2LoginAuthenticationFilterBuilder.addPropertyReference("authenticationSuccessHandler", authenticationSuccessHandlerRef); } @@ -222,7 +222,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { successHandlerBuilder.getBeanDefinition()); } String loginPage = element.getAttribute(ATT_LOGIN_PAGE); - if (!StringUtils.isEmpty(loginPage)) { + if (StringUtils.hasLength(loginPage)) { WebConfigUtils.validateHttpRedirect(loginPage, parserContext, source); this.oauth2LoginAuthenticationEntryPoint = BeanDefinitionBuilder .rootBeanDefinition(LoginUrlAuthenticationEntryPoint.class).addConstructorArgValue(loginPage) @@ -239,7 +239,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { } } String authenticationFailureHandlerRef = element.getAttribute(ATT_AUTHENTICATION_FAILURE_HANDLER_REF); - if (!StringUtils.isEmpty(authenticationFailureHandlerRef)) { + if (StringUtils.hasLength(authenticationFailureHandlerRef)) { oauth2LoginAuthenticationFilterBuilder.addPropertyReference("authenticationFailureHandler", authenticationFailureHandlerRef); } @@ -262,7 +262,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getAuthorizationRequestRepository(Element element) { String authorizationRequestRepositoryRef = element.getAttribute(ATT_AUTHORIZATION_REQUEST_REPOSITORY_REF); - if (!StringUtils.isEmpty(authorizationRequestRepositoryRef)) { + if (StringUtils.hasLength(authorizationRequestRepositoryRef)) { return new RuntimeBeanReference(authorizationRequestRepositoryRef); } return BeanDefinitionBuilder.rootBeanDefinition( @@ -290,11 +290,11 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { BeanDefinitionBuilder oidcAuthProviderBuilder = BeanDefinitionBuilder.rootBeanDefinition( "org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider") .addConstructorArgValue(accessTokenResponseClient).addConstructorArgValue(oidcUserService); - if (!StringUtils.isEmpty(userAuthoritiesMapperRef)) { + if (StringUtils.hasLength(userAuthoritiesMapperRef)) { oidcAuthProviderBuilder.addPropertyReference("authoritiesMapper", userAuthoritiesMapperRef); } String jwtDecoderFactoryRef = element.getAttribute(ATT_JWT_DECODER_FACTORY_REF); - if (!StringUtils.isEmpty(jwtDecoderFactoryRef)) { + if (StringUtils.hasLength(jwtDecoderFactoryRef)) { oidcAuthProviderBuilder.addPropertyReference("jwtDecoderFactory", jwtDecoderFactoryRef); } return oidcAuthProviderBuilder.getBeanDefinition(); @@ -302,7 +302,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getOidcUserService(Element element) { String oidcUserServiceRef = element.getAttribute(ATT_OIDC_USER_SERVICE_REF); - if (!StringUtils.isEmpty(oidcUserServiceRef)) { + if (StringUtils.hasLength(oidcUserServiceRef)) { return new RuntimeBeanReference(oidcUserServiceRef); } return BeanDefinitionBuilder @@ -312,7 +312,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getOAuth2UserService(Element element) { String oauth2UserServiceRef = element.getAttribute(ATT_USER_SERVICE_REF); - if (!StringUtils.isEmpty(oauth2UserServiceRef)) { + if (StringUtils.hasLength(oauth2UserServiceRef)) { return new RuntimeBeanReference(oauth2UserServiceRef); } return BeanDefinitionBuilder @@ -322,7 +322,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser { private BeanMetadataElement getAccessTokenResponseClient(Element element) { String accessTokenResponseClientRef = element.getAttribute(ATT_ACCESS_TOKEN_RESPONSE_CLIENT_REF); - if (!StringUtils.isEmpty(accessTokenResponseClientRef)) { + if (StringUtils.hasLength(accessTokenResponseClientRef)) { return new RuntimeBeanReference(accessTokenResponseClientRef); } return BeanDefinitionBuilder.rootBeanDefinition( diff --git a/config/src/main/java/org/springframework/security/config/http/OAuth2ResourceServerBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/http/OAuth2ResourceServerBeanDefinitionParser.java index fbd1c8d77a..b1e63a47db 100644 --- a/config/src/main/java/org/springframework/security/config/http/OAuth2ResourceServerBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/http/OAuth2ResourceServerBeanDefinitionParser.java @@ -165,7 +165,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa BeanMetadataElement getAuthenticationManagerResolver(Element element) { String authenticationManagerResolverRef = element.getAttribute(AUTHENTICATION_MANAGER_RESOLVER_REF); - if (!StringUtils.isEmpty(authenticationManagerResolverRef)) { + if (StringUtils.hasLength(authenticationManagerResolverRef)) { return new RuntimeBeanReference(authenticationManagerResolverRef); } BeanDefinitionBuilder authenticationManagerResolver = BeanDefinitionBuilder @@ -176,7 +176,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa BeanMetadataElement getBearerTokenResolver(Element element) { String bearerTokenResolverRef = element.getAttribute(BEARER_TOKEN_RESOLVER_REF); - if (StringUtils.isEmpty(bearerTokenResolverRef)) { + if (!StringUtils.hasLength(bearerTokenResolverRef)) { return new RootBeanDefinition(DefaultBearerTokenResolver.class); } return new RuntimeBeanReference(bearerTokenResolverRef); @@ -184,7 +184,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa BeanMetadataElement getEntryPoint(Element element) { String entryPointRef = element.getAttribute(ENTRY_POINT_REF); - if (StringUtils.isEmpty(entryPointRef)) { + if (!StringUtils.hasLength(entryPointRef)) { return this.authenticationEntryPoint; } return new RuntimeBeanReference(entryPointRef); @@ -223,7 +223,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa Object getDecoder(Element element) { String decoderRef = element.getAttribute(DECODER_REF); - if (!StringUtils.isEmpty(decoderRef)) { + if (StringUtils.hasLength(decoderRef)) { return new RuntimeBeanReference(decoderRef); } BeanDefinitionBuilder builder = BeanDefinitionBuilder @@ -234,7 +234,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa Object getJwtAuthenticationConverter(Element element) { String jwtDecoderRef = element.getAttribute(JWT_AUTHENTICATION_CONVERTER_REF); - return (!StringUtils.isEmpty(jwtDecoderRef)) ? new RuntimeBeanReference(jwtDecoderRef) + return (StringUtils.hasLength(jwtDecoderRef)) ? new RuntimeBeanReference(jwtDecoderRef) : new JwtAuthenticationConverter(); } @@ -291,7 +291,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa BeanMetadataElement getIntrospector(Element element) { String introspectorRef = element.getAttribute(INTROSPECTOR_REF); - if (!StringUtils.isEmpty(introspectorRef)) { + if (StringUtils.hasLength(introspectorRef)) { return new RuntimeBeanReference(introspectorRef); } String introspectionUri = element.getAttribute(INTROSPECTION_URI); diff --git a/config/src/main/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParser.java b/config/src/main/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParser.java index 0cc175d6c7..e5ae34bb33 100644 --- a/config/src/main/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParser.java +++ b/config/src/main/java/org/springframework/security/config/oauth2/client/ClientRegistrationsBeanDefinitionParser.java @@ -170,7 +170,7 @@ public final class ClientRegistrationsBeanDefinitionParser implements BeanDefini if (providers.containsKey(providerId)) { Map provider = providers.get(providerId); String issuer = provider.get(ATT_ISSUER_URI); - if (!StringUtils.isEmpty(issuer)) { + if (StringUtils.hasLength(issuer)) { ClientRegistration.Builder builder = ClientRegistrations.fromIssuerLocation(issuer) .registrationId(registrationId); return getBuilder(parserContext, builder, provider); diff --git a/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java b/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java index c58904745d..2ea4dab29c 100644 --- a/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java +++ b/config/src/test/java/org/springframework/security/config/doc/SpringSecurityXsdParser.java @@ -179,7 +179,7 @@ public class SpringSecurityXsdParser { */ private Element elmt(XmlNode n) { String name = n.attribute("ref"); - if (StringUtils.isEmpty(name)) { + if (!StringUtils.hasLength(name)) { name = n.attribute("name"); } else { @@ -199,7 +199,7 @@ public class SpringSecurityXsdParser { e.getAttrs().forEach((attr) -> attr.setElmt(e)); e.getChildElmts().values().forEach((element) -> element.getParentElmts().put(e.getName(), e)); String subGrpName = n.attribute("substitutionGroup"); - if (!StringUtils.isEmpty(subGrpName)) { + if (StringUtils.hasLength(subGrpName)) { Element subGrp = elmt(findNode(n, subGrpName.split(":")[1])); subGrp.getSubGrps().add(e); } diff --git a/core/src/main/java/org/springframework/security/jackson2/SecurityJackson2Modules.java b/core/src/main/java/org/springframework/security/jackson2/SecurityJackson2Modules.java index abccf9ac50..955355a4f9 100644 --- a/core/src/main/java/org/springframework/security/jackson2/SecurityJackson2Modules.java +++ b/core/src/main/java/org/springframework/security/jackson2/SecurityJackson2Modules.java @@ -127,7 +127,7 @@ public final class SecurityJackson2Modules { Class securityModule = (Class) ClassUtils.forName(className, loader); if (securityModule != null) { logger.debug(LogMessage.format("Loaded module %s, now registering", className)); - return securityModule.newInstance(); + return securityModule.getConstructor().newInstance(); } } catch (Exception ex) { diff --git a/core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java b/core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java index 798bc9c177..b7594081dd 100644 --- a/core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java +++ b/core/src/test/java/org/springframework/security/provisioning/JdbcUserDetailsManagerTests.java @@ -145,7 +145,7 @@ public class JdbcUserDetailsManagerTests { AuthorityUtils.createAuthorityList("A", "B")); this.manager.createUser(user); UserDetails user2 = this.manager.loadUserByUsername(user.getUsername()); - assertThat(user2).isEqualToComparingFieldByField(user); + assertThat(user2).usingRecursiveComparison().isEqualTo(user); } @Test @@ -176,7 +176,7 @@ public class JdbcUserDetailsManagerTests { AuthorityUtils.createAuthorityList("D", "F", "E")); this.manager.updateUser(newJoe); UserDetails joe = this.manager.loadUserByUsername(newJoe.getUsername()); - assertThat(joe).isEqualToComparingFieldByField(newJoe); + assertThat(joe).usingRecursiveComparison().isEqualTo(newJoe); assertThat(this.cache.getUserMap().containsKey(newJoe.getUsername())).isFalse(); } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserRequestUtils.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserRequestUtils.java index e8e6362479..1cd71aa072 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserRequestUtils.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserRequestUtils.java @@ -45,7 +45,7 @@ final class OidcUserRequestUtils { static boolean shouldRetrieveUserInfo(OidcUserRequest userRequest) { // Auto-disabled if UserInfo Endpoint URI is not provided ClientRegistration clientRegistration = userRequest.getClientRegistration(); - if (StringUtils.isEmpty(clientRegistration.getProviderDetails().getUserInfoEndpoint().getUri())) { + if (!StringUtils.hasLength(clientRegistration.getProviderDetails().getUserInfoEndpoint().getUri())) { return false; } // The Claims requested by the profile, email, address, and phone scope values diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.java index 0f543f69a7..eb8dff94a6 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.java @@ -157,7 +157,7 @@ public class OidcUserService implements OAuth2UserService parse(ClientResponse httpResponse) { String wwwAuth = httpResponse.headers().asHttpHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE); - if (!StringUtils.isEmpty(wwwAuth)) { + if (StringUtils.hasLength(wwwAuth)) { // Bearer token error? return Mono.fromCallable(() -> UserInfoErrorResponse.parse(wwwAuth)); } diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java index ffe1cf6677..7d11ef985f 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java @@ -238,10 +238,10 @@ public class OAuth2AuthorizationCodeGrantFilter extends OncePerRequestFilter { OAuth2Error error = ex.getError(); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(authorizationRequest.getRedirectUri()) .queryParam(OAuth2ParameterNames.ERROR, error.getErrorCode()); - if (!StringUtils.isEmpty(error.getDescription())) { + if (StringUtils.hasLength(error.getDescription())) { uriBuilder.queryParam(OAuth2ParameterNames.ERROR_DESCRIPTION, error.getDescription()); } - if (!StringUtils.isEmpty(error.getUri())) { + if (StringUtils.hasLength(error.getUri())) { uriBuilder.queryParam(OAuth2ParameterNames.ERROR_URI, error.getUri()); } this.redirectStrategy.sendRedirect(request, response, uriBuilder.build().encode().toString()); diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolver.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolver.java index a7b9b9687d..0b71a55484 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolver.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolver.java @@ -111,7 +111,7 @@ public final class OAuth2AuthorizedClientArgumentResolver implements HandlerMeth public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) { String clientRegistrationId = this.resolveClientRegistrationId(parameter); - if (StringUtils.isEmpty(clientRegistrationId)) { + if (!StringUtils.hasLength(clientRegistrationId)) { throw new IllegalArgumentException("Unable to resolve the Client Registration Identifier. " + "It must be provided via @RegisteredOAuth2AuthorizedClient(\"client1\") or " + "@RegisteredOAuth2AuthorizedClient(registrationId = \"client1\")."); @@ -137,10 +137,10 @@ public final class OAuth2AuthorizedClientArgumentResolver implements HandlerMeth RegisteredOAuth2AuthorizedClient authorizedClientAnnotation = AnnotatedElementUtils .findMergedAnnotation(parameter.getParameter(), RegisteredOAuth2AuthorizedClient.class); Authentication principal = this.securityContextHolderStrategy.getContext().getAuthentication(); - if (!StringUtils.isEmpty(authorizedClientAnnotation.registrationId())) { + if (StringUtils.hasLength(authorizedClientAnnotation.registrationId())) { return authorizedClientAnnotation.registrationId(); } - if (!StringUtils.isEmpty(authorizedClientAnnotation.value())) { + if (StringUtils.hasLength(authorizedClientAnnotation.value())) { return authorizedClientAnnotation.value(); } if (principal != null && OAuth2AuthenticationToken.class.isAssignableFrom(principal.getClass())) { diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java index cbd3da5935..3a7e4f7ce7 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java @@ -537,7 +537,7 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements private Map parseAuthParameters(String wwwAuthenticateHeader) { // @formatter:off return Stream.of(wwwAuthenticateHeader) - .filter((header) -> !StringUtils.isEmpty(header)) + .filter((header) -> StringUtils.hasLength(header)) .filter((header) -> header.toLowerCase().startsWith("bearer")) .map((header) -> header.substring("bearer".length())) .map((header) -> header.split(",")) 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 d211168b97..75ba1100f1 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 @@ -652,7 +652,7 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement private Map parseAuthParameters(String wwwAuthenticateHeader) { // @formatter:off - return Stream.of(wwwAuthenticateHeader).filter((header) -> !StringUtils.isEmpty(header)) + return Stream.of(wwwAuthenticateHeader).filter((header) -> StringUtils.hasLength(header)) .filter((header) -> header.toLowerCase().startsWith("bearer")) .map((header) -> header.substring("bearer".length())) .map((header) -> header.split(",")) diff --git a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java index 010ec7a6cd..f27ec8f7b5 100644 --- a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java +++ b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClientTests.java @@ -101,7 +101,7 @@ public class WebClientReactiveClientCredentialsTokenResponseClientTests { this.clientRegistration.build()); OAuth2AccessTokenResponse response = this.client.getTokenResponse(request).block(); RecordedRequest actualRequest = this.server.takeRequest(); - String body = actualRequest.getUtf8Body(); + String body = actualRequest.getBody().readUtf8(); assertThat(response.getAccessToken()).isNotNull(); assertThat(response.getAccessToken().getScopes()).containsExactly("create"); assertThat(actualRequest.getHeader(HttpHeaders.AUTHORIZATION)) @@ -155,7 +155,7 @@ public class WebClientReactiveClientCredentialsTokenResponseClientTests { OAuth2ClientCredentialsGrantRequest request = new OAuth2ClientCredentialsGrantRequest(registration); OAuth2AccessTokenResponse response = this.client.getTokenResponse(request).block(); RecordedRequest actualRequest = this.server.takeRequest(); - String body = actualRequest.getUtf8Body(); + String body = actualRequest.getBody().readUtf8(); assertThat(response.getAccessToken()).isNotNull(); assertThat(response.getAccessToken().getScopes()).containsExactly("create"); assertThat(actualRequest.getHeader(HttpHeaders.AUTHORIZATION)).isNull(); diff --git a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/jackson2/OAuth2AuthenticationTokenMixinTests.java b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/jackson2/OAuth2AuthenticationTokenMixinTests.java index aa5ebe83ca..b95f842198 100644 --- a/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/jackson2/OAuth2AuthenticationTokenMixinTests.java +++ b/oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/jackson2/OAuth2AuthenticationTokenMixinTests.java @@ -229,7 +229,7 @@ public class OAuth2AuthenticationTokenMixinTests { String authoritiesJson = (oidcUserAuthority != null) ? asJson(oidcUserAuthority) : (oauth2UserAuthority != null) ? asJson(oauth2UserAuthority) : ""; if (!simpleAuthorities.isEmpty()) { - if (!StringUtils.isEmpty(authoritiesJson)) { + if (StringUtils.hasLength(authoritiesJson)) { authoritiesJson += ","; } authoritiesJson += asJson(simpleAuthorities); diff --git a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusJwtDecoder.java b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusJwtDecoder.java index 604cfec6dc..6c4353bc91 100644 --- a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusJwtDecoder.java +++ b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusJwtDecoder.java @@ -194,7 +194,7 @@ public final class NimbusJwtDecoder implements JwtDecoder { private String getJwtValidationExceptionMessage(Collection errors) { for (OAuth2Error oAuth2Error : errors) { - if (!StringUtils.isEmpty(oAuth2Error.getDescription())) { + if (StringUtils.hasLength(oAuth2Error.getDescription())) { return String.format(DECODING_ERROR_MESSAGE_TEMPLATE, oAuth2Error.getDescription()); } } @@ -473,7 +473,7 @@ public final class NimbusJwtDecoder implements JwtDecoder { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON, APPLICATION_JWK_SET_JSON)); ResponseEntity response = getResponse(url, headers); - if (response.getStatusCodeValue() != 200) { + if (response.getStatusCode().value() != 200) { throw new IOException(response.toString()); } return new Resource(response.getBody(), "UTF-8"); diff --git a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusReactiveJwtDecoder.java b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusReactiveJwtDecoder.java index 0e833ae4de..9416f65fda 100644 --- a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusReactiveJwtDecoder.java +++ b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/NimbusReactiveJwtDecoder.java @@ -203,7 +203,7 @@ public final class NimbusReactiveJwtDecoder implements ReactiveJwtDecoder { private String getJwtValidationExceptionMessage(Collection errors) { for (OAuth2Error oAuth2Error : errors) { - if (!StringUtils.isEmpty(oAuth2Error.getDescription())) { + if (StringUtils.hasLength(oAuth2Error.getDescription())) { return oAuth2Error.getDescription(); } } diff --git a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java index ffb70c483e..c284668604 100644 --- a/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java +++ b/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/introspection/NimbusOpaqueTokenIntrospector.java @@ -177,7 +177,7 @@ public class NimbusOpaqueTokenIntrospector implements OpaqueTokenIntrospector { + contentType + "' is not compatible with JSON"); } - HTTPResponse response = new HTTPResponse(responseEntity.getStatusCodeValue()); + HTTPResponse response = new HTTPResponse(responseEntity.getStatusCode().value()); response.setHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()); response.setContent(responseEntity.getBody()); diff --git a/rsocket/src/test/java/org/springframework/security/rsocket/authentication/AuthenticationPayloadInterceptorTests.java b/rsocket/src/test/java/org/springframework/security/rsocket/authentication/AuthenticationPayloadInterceptorTests.java index 82495f2cb9..b763fa5d20 100644 --- a/rsocket/src/test/java/org/springframework/security/rsocket/authentication/AuthenticationPayloadInterceptorTests.java +++ b/rsocket/src/test/java/org/springframework/security/rsocket/authentication/AuthenticationPayloadInterceptorTests.java @@ -89,8 +89,8 @@ public class AuthenticationPayloadInterceptorTests { interceptor.intercept(exchange, authenticationPayloadChain).block(); Authentication authentication = authenticationPayloadChain.getAuthentication(); verify(this.authenticationManager).authenticate(this.authenticationArg.capture()); - assertThat(this.authenticationArg.getValue()).isEqualToComparingFieldByField( - UsernamePasswordAuthenticationToken.unauthenticated("user", "password")); + assertThat(this.authenticationArg.getValue()).usingRecursiveComparison() + .isEqualTo(UsernamePasswordAuthenticationToken.unauthenticated("user", "password")); assertThat(authentication).isEqualTo(expectedAuthentication); } diff --git a/rsocket/src/test/java/org/springframework/security/rsocket/metadata/BasicAuthenticationDecoderTests.java b/rsocket/src/test/java/org/springframework/security/rsocket/metadata/BasicAuthenticationDecoderTests.java index aea03d174e..28df5e0cf6 100644 --- a/rsocket/src/test/java/org/springframework/security/rsocket/metadata/BasicAuthenticationDecoderTests.java +++ b/rsocket/src/test/java/org/springframework/security/rsocket/metadata/BasicAuthenticationDecoderTests.java @@ -45,7 +45,7 @@ public class BasicAuthenticationDecoderTests { DataBuffer dataBuffer = encoder.encodeValue(expectedCredentials, factory, elementType, mimeType, hints); UsernamePasswordMetadata actualCredentials = decoder .decodeToMono(Mono.just(dataBuffer), elementType, mimeType, hints).block(); - assertThat(actualCredentials).isEqualToComparingFieldByField(expectedCredentials); + assertThat(actualCredentials).usingRecursiveComparison().isEqualTo(expectedCredentials); } } diff --git a/web/src/main/java/org/springframework/security/web/FilterInvocation.java b/web/src/main/java/org/springframework/security/web/FilterInvocation.java index 0e0e050f77..3c596d5f12 100644 --- a/web/src/main/java/org/springframework/security/web/FilterInvocation.java +++ b/web/src/main/java/org/springframework/security/web/FilterInvocation.java @@ -146,7 +146,7 @@ public class FilterInvocation { @Override public String toString() { - if (StringUtils.isEmpty(this.request.getMethod())) { + if (!StringUtils.hasLength(this.request.getMethod())) { return "filter invocation [" + getRequestUrl() + "]"; } else { diff --git a/web/src/main/java/org/springframework/security/web/savedrequest/CookieRequestCache.java b/web/src/main/java/org/springframework/security/web/savedrequest/CookieRequestCache.java index 62f45515d2..e5aa49a904 100644 --- a/web/src/main/java/org/springframework/security/web/savedrequest/CookieRequestCache.java +++ b/web/src/main/java/org/springframework/security/web/savedrequest/CookieRequestCache.java @@ -122,7 +122,7 @@ public class CookieRequestCache implements RequestCache { private static String getCookiePath(HttpServletRequest request) { String contextPath = request.getContextPath(); - return (!StringUtils.isEmpty(contextPath)) ? contextPath : "/"; + return (StringUtils.hasLength(contextPath)) ? contextPath : "/"; } private boolean matchesSavedRequest(HttpServletRequest request, SavedRequest savedRequest) {