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 284769d75f..4f2135a346 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 @@ -87,7 +87,7 @@ public abstract class AbstractRequestMatcherRegistry { * @return the object that is chained after creating the {@link RequestMatcher} */ public C antMatchers(HttpMethod method) { - return antMatchers(method, new String[] { "/**" }); + return antMatchers(method, "/**"); } /** diff --git a/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java index 9e2968a03f..8e66cceba7 100644 --- a/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java @@ -141,7 +141,7 @@ public final class AntPathRequestMatcher implements RequestMatcher, RequestVaria @Override public boolean matches(HttpServletRequest request) { if (this.httpMethod != null && StringUtils.hasText(request.getMethod()) - && this.httpMethod != valueOf(request.getMethod())) { + && this.httpMethod != HttpMethod.resolve(request.getMethod())) { return false; } if (this.pattern.equals(MATCH_ALL)) { @@ -211,21 +211,6 @@ public final class AntPathRequestMatcher implements RequestMatcher, RequestVaria return sb.toString(); } - /** - * Provides a save way of obtaining the HttpMethod from a String. If the method is - * invalid, returns null. - * @param method the HTTP method to use. - * @return the HttpMethod or null if method is invalid. - */ - private static HttpMethod valueOf(String method) { - try { - return HttpMethod.valueOf(method); - } - catch (IllegalArgumentException ex) { - return null; - } - } - private interface Matcher { boolean matches(String path); diff --git a/web/src/main/java/org/springframework/security/web/util/matcher/RegexRequestMatcher.java b/web/src/main/java/org/springframework/security/web/util/matcher/RegexRequestMatcher.java index 6d0bc19a1a..9264b56f21 100644 --- a/web/src/main/java/org/springframework/security/web/util/matcher/RegexRequestMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matcher/RegexRequestMatcher.java @@ -81,7 +81,8 @@ public final class RegexRequestMatcher implements RequestMatcher { */ @Override public boolean matches(HttpServletRequest request) { - if (this.httpMethod != null && request.getMethod() != null && this.httpMethod != valueOf(request.getMethod())) { + if (this.httpMethod != null && request.getMethod() != null + && this.httpMethod != HttpMethod.resolve(request.getMethod())) { return false; } String url = request.getServletPath(); @@ -101,21 +102,6 @@ public final class RegexRequestMatcher implements RequestMatcher { return this.pattern.matcher(url).matches(); } - /** - * Provides a save way of obtaining the HttpMethod from a String. If the method is - * invalid, returns null. - * @param method the HTTP method to use. - * @return the HttpMethod or null if method is invalid. - */ - private static HttpMethod valueOf(String method) { - try { - return HttpMethod.valueOf(method); - } - catch (IllegalArgumentException ex) { - return null; - } - } - @Override public String toString() { StringBuilder sb = new StringBuilder();