Skip to content

Commit feda73b

Browse files
author
su
committed
Add getRequiredAddress() and getMaskBits() to IpAddressMatcher.java
Closes gh-16693 Signed-off-by: su <[email protected]>
1 parent 861a9a9 commit feda73b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java

+8
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,12 @@ private InetAddress parseAddress(String address) {
130130
}
131131
}
132132

133+
public InetAddress getRequiredAddress() {
134+
return this.requiredAddress;
135+
}
136+
137+
public int getMaskBits() {
138+
return this.nMaskBits;
139+
}
140+
133141
}

web/src/test/java/org/springframework/security/web/util/matcher/IpAddressMatcherTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,18 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
152152
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(""))
153153
.withMessage("ipAddress cannot be empty");
154154
}
155+
// gh-16693
156+
@Test
157+
public void getRequiredAddressWhenCidrIsValidThenReturnsHostAddress() {
158+
IpAddressMatcher ipAddressMatcher = new IpAddressMatcher("192.168.1.0/24");
159+
assertThat(ipAddressMatcher.getRequiredAddress().getHostAddress()).isEqualTo("192.168.1.0");
160+
}
161+
162+
// gh-16693
163+
@Test
164+
public void getRequiredAddressWhenCidrIsValidThenReturnsMaskBits() {
165+
IpAddressMatcher ipAddressMatcher = new IpAddressMatcher("192.168.1.0/24");
166+
assertThat(ipAddressMatcher.getMaskBits()).isEqualTo(24);
167+
}
155168

156169
}

0 commit comments

Comments
 (0)