From 627a821d5f0bb6d38c9f0b893611606ff1f05087 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 30 Oct 2023 14:29:56 +0100 Subject: [PATCH 1/9] Polish ReactiveTokenValidator --- .../cloudfoundry/reactive/ReactiveTokenValidator.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidator.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidator.java index e31fc3797ae..e9f6dd5a62a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidator.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidator.java @@ -24,9 +24,8 @@ import java.security.Signature; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; import java.util.Base64; +import java.util.Collections; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import reactor.core.publisher.Mono; @@ -44,7 +43,7 @@ class ReactiveTokenValidator { private final ReactiveCloudFoundrySecurityService securityService; - private volatile ConcurrentMap cachedTokenKeys = new ConcurrentHashMap<>(); + private volatile Map cachedTokenKeys = Collections.emptyMap(); ReactiveTokenValidator(ReactiveCloudFoundrySecurityService securityService) { this.securityService = securityService; @@ -92,7 +91,7 @@ class ReactiveTokenValidator { } private void cacheTokenKeys(Map tokenKeys) { - this.cachedTokenKeys = new ConcurrentHashMap<>(tokenKeys); + this.cachedTokenKeys = Map.copyOf(tokenKeys); } private boolean hasValidSignature(Token token, String key) { From 9152217c96043a7f2719ebbf4b50561b48f88efd Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 30 Oct 2023 14:52:57 +0100 Subject: [PATCH 2/9] Fix JUnit's @Nested usage --- .../tracing/CompositePropagationFactoryTests.java | 2 +- .../autoconfigure/DevToolsR2dbcAutoConfigurationTests.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java index a232104de4c..5c756514684 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/CompositePropagationFactoryTests.java @@ -65,7 +65,7 @@ class CompositePropagationFactoryTests { } @Nested - static class CompostePropagationTests { + class CompositePropagationTests { @Test void keys() { diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfigurationTests.java index 8da0ed983e5..0e9d28f7c88 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -152,12 +152,12 @@ class DevToolsR2dbcAutoConfigurationTests { @Nested @ClassPathExclusions("r2dbc-pool*.jar") - static class Embedded extends Common { + class Embedded extends Common { } @Nested - static class Pooled extends Common { + class Pooled extends Common { } From d095a5e47da1ed3fbb4a0ee886156c5517c08630 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:21:54 +0100 Subject: [PATCH 3/9] Polish RestartApplicationListenerTests --- .../boot/devtools/restart/RestartApplicationListenerTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartApplicationListenerTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartApplicationListenerTests.java index 9e0d0f82092..23468ef6dd4 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartApplicationListenerTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/RestartApplicationListenerTests.java @@ -36,7 +36,6 @@ import org.springframework.core.Ordered; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.nullValue; import static org.mockito.Mockito.mock; /** @@ -117,7 +116,7 @@ class RestartApplicationListenerTests { SpringApplication application = new SpringApplication(); ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class); listener.onApplicationEvent(new ApplicationStartingEvent(bootstrapContext, application, ARGS)); - assertThat(Restarter.getInstance()).isNotEqualTo(nullValue()); + assertThat(Restarter.getInstance()).isNotNull(); assertThat(Restarter.getInstance().isFinished()).isFalse(); listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context)); if (failed) { From 1f41179a88901067e5e297cb4e78a830c34f9800 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:23:50 +0100 Subject: [PATCH 4/9] Polish SpringBootMockMvcBuilderCustomizer --- .../web/servlet/SpringBootMockMvcBuilderCustomizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java index 269d3615009..d739a2766b4 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java @@ -253,7 +253,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi } void clear() { - this.lines.get().clear(); + this.lines.remove(); } } From f3c10ae97b54387a2f6196e34c4cb0c3feb12848 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:33:52 +0100 Subject: [PATCH 5/9] Polish JsonStream --- .../buildpack/platform/json/JsonStream.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java index 87dd8ecbcb9..e14964604d7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/JsonStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 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. @@ -64,13 +64,14 @@ public class JsonStream { */ public void get(InputStream content, Class type, Consumer consumer) throws IOException { JsonFactory jsonFactory = this.objectMapper.getFactory(); - JsonParser parser = jsonFactory.createParser(content); - while (!parser.isClosed()) { - JsonToken token = parser.nextToken(); - if (token != null && token != JsonToken.END_OBJECT) { - T node = read(parser, type); - if (node != null) { - consumer.accept(node); + try (JsonParser parser = jsonFactory.createParser(content)) { + while (!parser.isClosed()) { + JsonToken token = parser.nextToken(); + if (token != null && token != JsonToken.END_OBJECT) { + T node = read(parser, type); + if (node != null) { + consumer.accept(node); + } } } } From e7c26b94101558b1fe9a4c57d84da2c43e353c83 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:37:06 +0100 Subject: [PATCH 6/9] Polish BeanDefinitionLoader --- .../java/org/springframework/boot/BeanDefinitionLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java index ceecb07bc1f..32a59063509 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java @@ -265,7 +265,7 @@ class BeanDefinitionLoader { .getResources(ClassUtils.convertClassNameToResourcePath(source.toString()) + "/*.class"); for (Resource resource : resources) { String className = StringUtils.stripFilenameExtension(resource.getFilename()); - load(Class.forName(source.toString() + "." + className)); + load(Class.forName(source + "." + className)); break; } } From 3d4a9dd059b72deac1868d3e08a13480cc66936a Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:39:05 +0100 Subject: [PATCH 7/9] Polish StandardConfigDataResource --- .../boot/context/config/StandardConfigDataResource.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataResource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataResource.java index ccf175f555a..aac0897413e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataResource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataResource.java @@ -106,7 +106,7 @@ public class StandardConfigDataResource extends ConfigDataResource { } private boolean isSameFile(File ours, File other) { - return (ours != null) && (other != null) && ours.equals(other); + return (ours != null) && ours.equals(other); } @Override @@ -119,9 +119,10 @@ public class StandardConfigDataResource extends ConfigDataResource { public String toString() { if (this.resource instanceof FileSystemResource || this.resource instanceof FileUrlResource) { try { - return "file [" + this.resource.getFile().toString() + "]"; + return "file [" + this.resource.getFile() + "]"; } catch (IOException ex) { + // Ignore } } return this.resource.toString(); @@ -131,11 +132,11 @@ public class StandardConfigDataResource extends ConfigDataResource { try { if (resource instanceof ClassPathResource || resource instanceof FileSystemResource || resource instanceof FileUrlResource) { - File file = resource.getFile(); - return (file != null) ? file.getAbsoluteFile() : null; + return resource.getFile().getAbsoluteFile(); } } catch (IOException ex) { + // Ignore } return null; } From e0985331c039a4474d9e9f371de270fb5f9efd91 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:56:35 +0100 Subject: [PATCH 8/9] Polish ReactiveCloudFoundrySecurityService --- .../reactive/ReactiveCloudFoundrySecurityService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java index 4add4c09431..d75725e68d6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java @@ -53,8 +53,6 @@ class ReactiveCloudFoundrySecurityService { private final String cloudControllerUrl; - private Mono uaaUrl; - ReactiveCloudFoundrySecurityService(WebClient.Builder webClientBuilder, String cloudControllerUrl, boolean skipSslValidation) { Assert.notNull(webClientBuilder, "WebClient must not be null"); @@ -149,7 +147,7 @@ class ReactiveCloudFoundrySecurityService { * @return the UAA url Mono */ Mono getUaaUrl() { - this.uaaUrl = this.webClient.get() + return this.webClient.get() .uri(this.cloudControllerUrl + "/info") .retrieve() .bodyToMono(Map.class) @@ -157,7 +155,6 @@ class ReactiveCloudFoundrySecurityService { .cache() .onErrorMap((ex) -> new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Unable to fetch token keys from UAA.")); - return this.uaaUrl; } } From dccf378d493928d062af23435005100598b8f56f Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 31 Oct 2023 09:57:41 +0100 Subject: [PATCH 9/9] Polish CloudFoundryActuatorAutoConfiguration --- .../servlet/CloudFoundryActuatorAutoConfiguration.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java index 35ba2cab29e..08a688c53be 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java @@ -67,7 +67,6 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.OrRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; -import org.springframework.util.CollectionUtils; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.servlet.DispatcherServlet; @@ -125,8 +124,8 @@ public class CloudFoundryActuatorAutoConfiguration { allEndpoints.addAll(webEndpoints); allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); - return new CloudFoundryWebEndpointServletHandlerMapping(new EndpointMapping("/cloudfoundryapplication"), - webEndpoints, endpointMediaTypes, getCorsConfiguration(), securityInterceptor, allEndpoints); + return new CloudFoundryWebEndpointServletHandlerMapping(new EndpointMapping(BASE_PATH), webEndpoints, + endpointMediaTypes, getCorsConfiguration(), securityInterceptor, allEndpoints); } private CloudFoundrySecurityInterceptor getSecurityInterceptor(RestTemplateBuilder restTemplateBuilder, @@ -189,9 +188,7 @@ public class CloudFoundryActuatorAutoConfiguration { .forEach((path) -> requestMatchers.add(new AntPathRequestMatcher(path + "/**"))); requestMatchers.add(new AntPathRequestMatcher(BASE_PATH)); requestMatchers.add(new AntPathRequestMatcher(BASE_PATH + "/")); - if (!CollectionUtils.isEmpty(requestMatchers)) { - web.ignoring().requestMatchers(new OrRequestMatcher(requestMatchers)); - } + web.ignoring().requestMatchers(new OrRequestMatcher(requestMatchers)); } }