1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Move InetAddressMatcher to spring-security-core

Closes gh-18979
This commit is contained in:
Robert Winch
2026-03-25 15:25:40 -05:00
parent c6e60c84f9
commit 51ce11cbd2
11 changed files with 56 additions and 16 deletions
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -66,6 +66,18 @@ public final class InetAddressMatchers {
return builder().matchAll(InternalInetAddressMatcher.getInstance());
}
/**
* Creates an {@link InetAddressMatcher} that matches a specific IP address or subnet
* using CIDR notation (e.g., {@code 192.168.1.0/24}).
* <p>
* Both IPv4 and IPv6 addresses are supported.
* @param ipAddress the IP address or CIDR range to match against
* @return an {@link InetAddressMatcher} for the given IP address pattern
*/
public static InetAddressMatcher fromIpAddress(String ipAddress) {
return new IpInetAddressMatcher(ipAddress);
}
/**
* A builder for constructing {@link InetAddressMatcher} instances with various
* matching rules.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -34,18 +34,18 @@ import org.springframework.util.StringUtils;
* Both IPv4 and IPv6 addresses are supported. The matcher can be configured with either a
* specific IP address or a subnet using CIDR notation.
* <p>
* The logic from this class was migrated from {@link IpAddressMatcher} to provide a more
* general API that did not depend on the servlet APIs (e.g. HttpServletRequest).
* The logic from this class was migrated from
* {@code org.springframework.security.web.util.matcher.IpAddressMatcher} to provide a
* more general API that did not depend on the servlet APIs (e.g. HttpServletRequest).
*
* @author Luke Taylor
* @author Steve Riesenberg
* @author Andrey Litvitski
* @since 7.1
* @see IpAddressMatcher
*/
final class IpInetAddressMatcher implements InetAddressMatcher {
private static final Log logger = LogFactory.getLog(IpAddressMatcher.class);
private static final Log logger = LogFactory.getLog(IpInetAddressMatcher.class);
private final InetAddress requiredAddress;
@@ -0,0 +1,23 @@
/*
* Copyright 2004-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* General utility classes for matching IP addresses.
*/
@NullMarked
package org.springframework.security.util.matcher;
import org.jspecify.annotations.NullMarked;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import org.junit.jupiter.api.Test;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
import java.util.List;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.security.web.util.matcher;
package org.springframework.security.util.matcher;
import java.net.InetAddress;
+4 -2
View File
@@ -1,9 +1,11 @@
[[new]]
= What's New in Spring Security 7.1
== Web
== Core
* https://github.com/spring-projects/spring-security/pull/18634[gh-18634] - Added javadoc:org.springframework.security.web.util.matcher.InetAddressMatcher[]
* https://github.com/spring-projects/spring-security/pull/18634[gh-18634] - Added javadoc:org.springframework.security.util.matcher.InetAddressMatcher[]
== Web
* https://github.com/spring-projects/spring-security/issues/18755[gh-18755] - Include `charset` in `WWW-Authenticate` header
* Added xref:servlet/authorization/architecture.adoc#authz-conditional-authorization-manager[ConditionalAuthorizationManager]
* Added `when` and `withWhen` conditions to `AuthorizationManagerFactories.multiFactor()` for xref:servlet/authentication/mfa.adoc#programmatic-mfa[Programmatic MFA]
@@ -20,8 +20,8 @@ import java.util.List;
import reactor.core.publisher.Mono;
import org.springframework.security.web.util.matcher.InetAddressMatcher;
import org.springframework.security.web.util.matcher.InetAddressMatchers;
import org.springframework.security.util.matcher.InetAddressMatcher;
import org.springframework.security.util.matcher.InetAddressMatchers;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
@@ -19,6 +19,9 @@ package org.springframework.security.web.util.matcher;
import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.security.util.matcher.InetAddressMatcher;
import org.springframework.security.util.matcher.InetAddressMatchers;
/**
* Matches a request based on IP Address or subnet mask matching against the remote
* address.
@@ -42,7 +45,7 @@ public final class IpAddressMatcher implements RequestMatcher {
* come.
*/
public IpAddressMatcher(String ipAddress) {
this.matcher = new IpInetAddressMatcher(ipAddress);
this.matcher = InetAddressMatchers.fromIpAddress(ipAddress);
}
@Override