diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java b/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java index 2b4c577eb5..bb8a79dc32 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/AbstractRequestMatcherRegistry.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import jakarta.servlet.DispatcherType; @@ -263,11 +264,7 @@ private RequestMatchers() { */ static List antMatchers(HttpMethod httpMethod, String... antPatterns) { String method = (httpMethod != null) ? httpMethod.toString() : null; - List matchers = new ArrayList<>(); - for (String pattern : antPatterns) { - matchers.add(new AntPathRequestMatcher(pattern, method)); - } - return matchers; + return Arrays.stream(antPatterns).map((pattern) -> new AntPathRequestMatcher(pattern, method)).collect(Collectors.toList()); } /** @@ -291,11 +288,7 @@ static List antMatchers(String... antPatterns) { */ static List regexMatchers(HttpMethod httpMethod, String... regexPatterns) { String method = (httpMethod != null) ? httpMethod.toString() : null; - List matchers = new ArrayList<>(); - for (String pattern : regexPatterns) { - matchers.add(new RegexRequestMatcher(pattern, method)); - } - return matchers; + return Arrays.stream(regexPatterns).map(pattern -> new RegexRequestMatcher(pattern, method)).collect(Collectors.toList()); } /**