Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-11.0.x

This commit is contained in:
Jan Bartel 2021-06-01 10:22:19 +10:00
commit dabb0a0624
11 changed files with 173 additions and 31 deletions

6
Jenkinsfile vendored
View File

@ -37,13 +37,13 @@ pipeline {
}
}
stage("Build / Test - JDK15") {
stage("Build / Test - JDK16") {
agent { node { label 'linux' } }
steps {
container( 'jetty-build' ) {
timeout( time: 120, unit: 'MINUTES' ) {
mavenBuild( "jdk15", "clean install", "maven3")
recordIssues id: "jdk15", name: "Static Analysis jdk15", aggregatingResults: true, enabledForFailure: true, tools: [mavenConsole(), java(), checkStyle(), spotBugs(), pmdParser()]
mavenBuild( "jdk16", "clean install", "maven3")
recordIssues id: "jdk16", name: "Static Analysis jdk16", aggregatingResults: true, enabledForFailure: true, tools: [mavenConsole(), java(), checkStyle(), spotBugs(), pmdParser()]
}
}
}

View File

@ -68,4 +68,25 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>

View File

@ -22,3 +22,4 @@ lib/logging/jetty-slf4j-impl-${jetty.version}.jar
[ini]
jetty.webapp.addServerClasses+=,org.eclipse.jetty.logging.
jetty.webapp.addServerClasses+=,${jetty.home.uri}/lib/logging/

View File

@ -88,4 +88,25 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/jdk.internal.misc=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>

View File

@ -131,4 +131,27 @@
</dependency>
</dependencies>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/sun.security.x509=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>

View File

@ -73,6 +73,7 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.AttributesMap;
import org.eclipse.jetty.util.Index;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.StringUtil;
@ -179,6 +180,16 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
DESTROYED
}
/**
* The type of protected target match
* @see #_protectedTargets
*/
private enum ProtectedTargetType
{
EXACT,
PREFIX
}
protected ContextStatus _contextStatus = ContextStatus.NOTSET;
protected Context _scontext;
private final AttributesMap _attributes;
@ -214,7 +225,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
private final List<ServletRequestAttributeListener> _servletRequestAttributeListeners = new CopyOnWriteArrayList<>();
private final List<ContextScopeListener> _contextListeners = new CopyOnWriteArrayList<>();
private final Set<EventListener> _durableListeners = new HashSet<>();
private String[] _protectedTargets;
private Index<ProtectedTargetType> _protectedTargets = Index.empty(false);
private final CopyOnWriteArrayList<AliasCheck> _aliasChecks = new CopyOnWriteArrayList<>();
public enum Availability
@ -1471,30 +1482,17 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
*/
public boolean isProtectedTarget(String target)
{
if (target == null || _protectedTargets == null)
if (target == null || _protectedTargets.isEmpty())
return false;
while (target.startsWith("//"))
{
if (target.startsWith("//"))
// ignore empty segments which may be discard by file system
target = URIUtil.compactPath(target);
}
for (int i = 0; i < _protectedTargets.length; i++)
{
String t = _protectedTargets[i];
if (StringUtil.startsWithIgnoreCase(target, t))
{
if (target.length() == t.length())
return true;
ProtectedTargetType type = _protectedTargets.getBest(target);
// Check that the target prefix really is a path segment, thus
// it can end with /, a query, a target or a parameter
char c = target.charAt(t.length());
if (c == '/' || c == '?' || c == '#' || c == ';')
return true;
}
}
return false;
return type == ProtectedTargetType.PREFIX ||
type == ProtectedTargetType.EXACT && _protectedTargets.get(target) == ProtectedTargetType.EXACT;
}
/**
@ -1502,13 +1500,22 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
*/
public void setProtectedTargets(String[] targets)
{
if (targets == null)
Index.Builder<ProtectedTargetType> builder = new Index.Builder<>();
if (targets != null)
{
_protectedTargets = null;
return;
}
for (String t : targets)
{
if (!t.startsWith("/"))
throw new IllegalArgumentException("Bad protected target: " + t);
_protectedTargets = Arrays.copyOf(targets, targets.length);
builder.with(t, ProtectedTargetType.EXACT);
builder.with(t + "/", ProtectedTargetType.PREFIX);
builder.with(t + "?", ProtectedTargetType.PREFIX);
builder.with(t + "#", ProtectedTargetType.PREFIX);
builder.with(t + ";", ProtectedTargetType.PREFIX);
}
}
_protectedTargets = builder.caseSensitive(false).build();
}
public String[] getProtectedTargets()
@ -1516,7 +1523,9 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
if (_protectedTargets == null)
return null;
return Arrays.copyOf(_protectedTargets, _protectedTargets.length);
return _protectedTargets.keySet().stream()
.filter(s -> _protectedTargets.get(s) == ProtectedTargetType.EXACT)
.toArray(String[]::new);
}
@Override

View File

@ -646,9 +646,20 @@ public class ContextHandlerTest
String[] protectedTargets = {"/foo-inf", "/bar-inf"};
handler.setProtectedTargets(protectedTargets);
assertTrue(handler.isProtectedTarget("/foo-inf"));
assertTrue(handler.isProtectedTarget("/Foo-Inf"));
assertTrue(handler.isProtectedTarget("/FOO-INF"));
assertTrue(handler.isProtectedTarget("/foo-inf/"));
assertTrue(handler.isProtectedTarget("/FOO-inf?"));
assertTrue(handler.isProtectedTarget("/FOO-INF;"));
assertTrue(handler.isProtectedTarget("/foo-INF#"));
assertTrue(handler.isProtectedTarget("//foo-inf"));
assertTrue(handler.isProtectedTarget("//foo-inf//some//path"));
assertTrue(handler.isProtectedTarget("///foo-inf"));
assertTrue(handler.isProtectedTarget("/foo-inf/x/y/z"));
assertFalse(handler.isProtectedTarget("/foo/x/y/z"));
assertTrue(handler.isProtectedTarget("/foo-inf?x=y&z=1"));
assertFalse(handler.isProtectedTarget("/foo/x/y/z"));
assertFalse(handler.isProtectedTarget("/foo-inf-bar"));
protectedTargets = new String[4];

View File

@ -73,7 +73,8 @@ public interface Index<V>
V getBest(String s, int offset, int len);
/**
* Get the best match from key in a String.
* Get the best match from key in a String, which may be
* a prefix match or an exact match.
*
* @param s The string
* @return The value or null if not found
@ -267,6 +268,11 @@ public interface Index<V>
return new ArrayTrie<>(true, maxCapacity);
}
static <V> Index<V> empty(boolean caseSensitive)
{
return EmptyTrie.instance(caseSensitive);
}
/**
* Builder of {@link Index} instances.
* @param <V> the entry type

View File

@ -184,4 +184,28 @@
</plugins>
</build>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<cdi.tests.jvmArgs>--add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED</cdi.tests.jvmArgs>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>

View File

@ -17,6 +17,8 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Stream;
@ -78,8 +80,10 @@ public class CDITests extends AbstractJettyHomeTest
public void testCDIIncludedInWebapp(String implementation, String integration, Consumer<JettyHomeTester> configure) throws Exception
{
String jettyVersion = System.getProperty("jettyVersion");
String jvmArgs = System.getProperty("cdi.tests.jvmArgs");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jvmArgs(jvmArgs == null ? Collections.emptyList() : Arrays.asList(jvmArgs.split("\\s+")))
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();

View File

@ -32,6 +32,7 @@
<includes>
<include>**/*.java</include>
</includes>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED</argLine>
<systemPropertyVariables>
<infinispan.docker.image.version>${infinispan.docker.image.version}</infinispan.docker.image.version>
<infinispan.docker.image.name>${infinispan.docker.image.name}</infinispan.docker.image.name>
@ -177,4 +178,25 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>