Skip to content

Commit 99c049e

Browse files
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x
2 parents c3cf256 + 38cea26 commit 99c049e

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

jetty-server/src/main/config/modules/inetaccess.mod

+5-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[description]
44
Enables the InetAccessHandler.
5-
Applies a include/exclude control of the remote IP of requests.
5+
Applies an include/exclude control of the remote IP of requests.
66

77
[tags]
88
connector
@@ -18,15 +18,9 @@ etc/jetty-inetaccess.xml
1818

1919
[ini-template]
2020

21-
## List of InetAddress patterns to include
22-
#jetty.inetaccess.include=127.0.0.1,127.0.0.2
21+
## List of InetAddress patterns to include (connectorName@addressPattern|pathSpec)
22+
#jetty.inetaccess.include=http@127.0.0.1-127.0.0.2|/pathSpec,tls@,|/pathSpec2,127.0.0.20
2323

24-
## List of InetAddress patterns to exclude
25-
#jetty.inetaccess.exclude=127.0.0.1,127.0.0.2
26-
27-
## List of Connector names to include
28-
#jetty.inetaccess.includeConnectors=http
29-
30-
## List of Connector names to exclude
31-
#jetty.inetaccess.excludeConnectors=tls
24+
## List of InetAddress patterns to exclude (connectorName@addressPattern|pathSpec)
25+
#jetty.inetaccess.exclude=http@127.0.0.1-127.0.0.2|/pathSpec,tls@,|/pathSpec2,127.0.0.20
3226

jetty-server/src/main/config/modules/inetaccess/inetaccess.xml

-13
This file was deleted.

jetty-server/src/main/config/modules/inetaccess/jetty-inetaccess.xml

-14
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919
</Call>
2020
</Arg>
2121
</Call>
22-
<Call name="includeConnectors">
23-
<Arg>
24-
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit">
25-
<Arg><Property name="jetty.inetaccess.includeConnectors" default="" /></Arg>
26-
</Call>
27-
</Arg>
28-
</Call>
29-
<Call name="excludeConnectors">
30-
<Arg>
31-
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit">
32-
<Arg><Property name="jetty.inetaccess.excludeConnectors" default="" /></Arg>
33-
</Call>
34-
</Arg>
35-
</Call>
3622
</New>
3723
</Arg>
3824
</Call>

jetty-server/src/main/java/org/eclipse/jetty/server/handler/InetAccessSet.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public class InetAccessSet extends AbstractSet<InetAccessSet.PatternTuple> implements Set<InetAccessSet.PatternTuple>, Predicate<InetAccessSet.AccessTuple>
2929
{
30-
private ArrayList<PatternTuple> tuples = new ArrayList<>();
30+
private final ArrayList<PatternTuple> tuples = new ArrayList<>();
3131

3232
@Override
3333
public boolean add(PatternTuple storageTuple)
@@ -67,7 +67,7 @@ public boolean test(AccessTuple entry)
6767
return false;
6868
}
6969

70-
static class PatternTuple implements Predicate<AccessTuple>
70+
public static class PatternTuple implements Predicate<AccessTuple>
7171
{
7272
private final String connector;
7373
private final InetAddressPattern address;
@@ -110,19 +110,22 @@ public boolean test(AccessTuple entry)
110110
if ((connector != null) && !connector.equals(entry.getConnector()))
111111
return false;
112112

113-
// If we have a path we must must be at this path to match for an address.
113+
// If we have a path we must be at this path to match for an address.
114114
if ((pathSpec != null) && !pathSpec.matches(entry.getPath()))
115115
return false;
116116

117117
// Match for InetAddress.
118-
if ((address != null) && !address.test(entry.getAddress()))
119-
return false;
118+
return (address == null) || address.test(entry.getAddress());
119+
}
120120

121-
return true;
121+
@Override
122+
public String toString()
123+
{
124+
return String.format("%s@%x{connector=%s, addressPattern=%s, pathSpec=%s}", getClass().getSimpleName(), hashCode(), connector, address, pathSpec);
122125
}
123126
}
124127

125-
static class AccessTuple
128+
public static class AccessTuple
126129
{
127130
private final String connector;
128131
private final InetAddress address;

tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java

+38
Original file line numberDiff line numberDiff line change
@@ -1376,4 +1376,42 @@ public void testVirtualThreadPool() throws Exception
13761376
}
13771377
}
13781378
}
1379+
1380+
@Test
1381+
public void testInetAccessHandler() throws Exception
1382+
{
1383+
String jettyVersion = System.getProperty("jettyVersion");
1384+
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
1385+
.jettyVersion(jettyVersion)
1386+
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
1387+
.build();
1388+
1389+
try (JettyHomeTester.Run run1 = distribution.start("--add-modules=inetaccess,http"))
1390+
{
1391+
assertTrue(run1.awaitFor(10, TimeUnit.SECONDS));
1392+
assertEquals(0, run1.getExitValue());
1393+
1394+
int httpPort = distribution.freePort();
1395+
List<String> args = List.of(
1396+
"jetty.inetaccess.exclude=|/excludedPath/*",
1397+
"jetty.http.port=" + httpPort);
1398+
try (JettyHomeTester.Run run2 = distribution.start(args))
1399+
{
1400+
assertTrue(run2.awaitConsoleLogsFor("Started Server@", 10, TimeUnit.SECONDS));
1401+
startHttpClient();
1402+
1403+
// Excluded path returns 403 response.
1404+
ContentResponse response = client.newRequest("http://localhost:" + httpPort + "/excludedPath")
1405+
.timeout(15, TimeUnit.SECONDS)
1406+
.send();
1407+
assertEquals(HttpStatus.FORBIDDEN_403, response.getStatus());
1408+
1409+
// Other paths return 404 response.
1410+
response = client.newRequest("http://localhost:" + httpPort + "/path")
1411+
.timeout(15, TimeUnit.SECONDS)
1412+
.send();
1413+
assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus());
1414+
}
1415+
}
1416+
}
13791417
}

0 commit comments

Comments
 (0)