Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ClassMatcher to core to have a consistent fix for addServerClasses in all environments #11566

Merged
merged 33 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c8c6dad
Issue #11514 - Cleanup `jetty.webapp.addServerClasses` property behav…
joakime Mar 13, 2024
503225e
Fix test
joakime Mar 13, 2024
87d0c45
Merging patterns (default -> env -> config)
joakime Mar 13, 2024
403f59a
Merge branch 'jetty-12.0.x' into fix/12.0.x/addserverclasses-ee9
gregw Mar 24, 2024
2775c32
Moved ClassMatcher to util
gregw Mar 24, 2024
17b2004
System Server Classes
gregw Mar 24, 2024
eb1c207
System Server Classes
gregw Mar 25, 2024
8b46ea2
System Server Classes
gregw Mar 25, 2024
3866b75
Merge remote-tracking branch 'origin/jetty-12.0.x' into fix/12.0.x/ad…
gregw Mar 25, 2024
01f2903
System Server Classes
gregw Mar 25, 2024
0ddab40
Merge branch 'jetty-12.0.x' into fix/12.0.x/addserverclasses-ee9-gw
gregw Mar 26, 2024
5bfc74f
Updated for loss of dump.war
gregw Mar 26, 2024
7748358
revert name changes in ee8 and ee9
gregw Mar 27, 2024
4214001
revert reverted name changes in ee8 and ee9
gregw Mar 27, 2024
ddc6dc2
Update jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebappC…
gregw Mar 27, 2024
ce08502
renamed as per review
gregw Mar 27, 2024
19aad85
Merge branch 'jetty-12.0.x' into fix/12.0.x/addserverclasses-ee9-gw
gregw Mar 28, 2024
94c0cae
fixed OSGi tests
gregw Mar 29, 2024
724ba19
Ensure default hidden server and system classes.
janbartel Mar 29, 2024
210b068
minimal tests for defaults
gregw Mar 29, 2024
7f43223
WIP
gregw Mar 30, 2024
e9fa012
Fixed ee9 OSGi to load jetty-ee
gregw Mar 30, 2024
9e1b251
fixed test
gregw Apr 3, 2024
627aaa3
Merge branch 'jetty-12.0.x' into fix/12.0.x/addserverclasses-ee9-gw
gregw Apr 3, 2024
10b557f
updated pom version
gregw Apr 3, 2024
1296040
fix demo modules test
gregw Apr 4, 2024
aff96fe
updates from review
gregw Apr 4, 2024
175b191
updates from review
gregw Apr 4, 2024
d60289a
updates from review
gregw Apr 4, 2024
9155a72
updates from review
gregw Apr 4, 2024
9736429
Adding more deprecations
joakime Apr 10, 2024
ac474c0
Changing XML demos/tests to use new getter names
joakime Apr 10, 2024
cc47168
rollback xml changes in ee9/ee8
joakime Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions jetty-core/jetty-ee/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-core</artifactId>
<version>12.0.8-SNAPSHOT</version>
</parent>
<artifactId>jetty-ee</artifactId>
<name>Core :: EE Common</name>

<properties>
<bundle-symbolic-name>${project.groupId}.ee</bundle-symbolic-name>
<spotbugs.onlyAnalyze>org.eclipse.jetty.ee.*</spotbugs.onlyAnalyze>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>jetty-test-multipart</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${jetty.surefire.argLine} --add-reads org.eclipse.jetty.ee=org.eclipse.jetty.logging</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
23 changes: 23 additions & 0 deletions jetty-core/jetty-ee/src/main/config/etc/jetty-ee-webapp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call class="org.eclipse.jetty.ee.WebappProtectedClasses" name="addSystemClasses">
<Arg><Ref refid="Server"/></Arg>
<Arg>
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit">
<Arg><Property name="jetty.server.addSystemClasses"/></Arg>
</Call>
</Arg>
</Call>

<Call class="org.eclipse.jetty.ee.WebappProtectedClasses" name="addServerClasses">
<Arg><Ref refid="Server"/></Arg>
<Arg>
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit">
<Arg><Property name="jetty.server.addServerClasses"/></Arg>
</Call>
</Arg>
</Call>

</Configure>
31 changes: 31 additions & 0 deletions jetty-core/jetty-ee/src/main/config/modules/ee-webapp.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DO NOT EDIT THIS FILE - See: https://eclipse.dev/jetty/documentation/

[description]
# tag::description[]
This module provide common configuration of Java Servlet web applications over all environments.
# end::description[]

[xml]
etc/jetty-ee-webapp.xml

[lib]
lib/jetty-ee-webapp-${jetty.version}.jar

[ini-template]
# tag::ini-template[]
## Add to the server wide default jars and packages protected or hidden from webapps.
## System classes are protected and cannot be overridden by a webapp.
## Server classes are hidden and cannot be seen by a webapp
## Lists of patterns are comma separated and may be either:
## + a qualified classname e.g. 'com.acme.Foo'
## + a package name e.g. 'net.example.'
## + a jar file e.g. '${jetty.base.uri}/lib/dependency.jar'
## + a directory of jars,resource or classes e.g. '${jetty.base.uri}/resources'
## + A pattern preceded with a '-' is an exclusion, all other patterns are inclusions
##
## The +=, operator appends to a CSV list with a comma as needed.
##
#jetty.server.addSystemClasses+=,org.example.
#jetty.server.addServerClasses+=,org.example.
# end::ini-template[]

22 changes: 22 additions & 0 deletions jetty-core/jetty-ee/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

module org.eclipse.jetty.ee
{
requires org.slf4j;

requires transitive org.eclipse.jetty.util;
requires transitive org.eclipse.jetty.server;

exports org.eclipse.jetty.ee;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package org.eclipse.jetty.ee;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.ClassMatcher;
import org.eclipse.jetty.util.component.Environment;

public class WebappProtectedClasses
{
public static final String SYSTEM_CLASSES_ATTRIBUTE = "org.eclipse.jetty.webapp.systemClasses";
public static final String SERVER_CLASSES_ATTRIBUTE = "org.eclipse.jetty.webapp.serverClasses";

// System classes are classes that cannot be replaced by
// the web application, and they are *always* loaded via
// system classloader.
public static final ClassMatcher DEFAULT_SYSTEM_CLASSES = new ClassMatcher(
"java.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
"javax.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
"jakarta.", // Jakarta classes (per servlet spec v5.0 / Section 15.2.1)
"org.xml.", // javax.xml
"org.w3c." // javax.xml
);

// Server classes are classes that are hidden from being
// loaded by the web application using system classloader,
// so if web application needs to load any of such classes,
// it has to include them in its distribution.
public static final ClassMatcher DEFAULT_SERVER_CLASSES = new ClassMatcher(
"org.eclipse.jetty." // hide jetty classes
);

public static ClassMatcher getSystemClasses(Server server)
{
return getClassMatcher(server, SYSTEM_CLASSES_ATTRIBUTE, null);
}

public static ClassMatcher getSystemClasses(Environment environment)
{
return getClassMatcher(environment, SYSTEM_CLASSES_ATTRIBUTE, null);
}

/**
* Add a System Class pattern to use for all WebAppContexts.
* @param patterns the patterns to use
*/
public static void addSystemClasses(String... patterns)
{
DEFAULT_SYSTEM_CLASSES.add(patterns);
}

/**
* Add a System Class pattern to use for all WebAppContexts of a given {@link Server}.
* @param server The {@link Server} instance to add classes to
* @param patterns the patterns to use
*/
public static void addSystemClasses(Server server, String... patterns)
{
addClasses(server, SYSTEM_CLASSES_ATTRIBUTE, DEFAULT_SYSTEM_CLASSES, patterns);
}

/**
* Add a System Class pattern to use for WebAppContexts of a given environment.
* @param environment The {@link Environment} instance to add classes to
* @param patterns the patterns to use
*/
public static void addSystemClasses(Environment environment, String... patterns)
{
addClasses(environment, SYSTEM_CLASSES_ATTRIBUTE, DEFAULT_SYSTEM_CLASSES, patterns);
}

public static ClassMatcher getServerClasses(Server server)
{
return getClassMatcher(server, SERVER_CLASSES_ATTRIBUTE, DEFAULT_SERVER_CLASSES);
}

public static ClassMatcher getServerClasses(Environment environment)
{
return getClassMatcher(environment, SERVER_CLASSES_ATTRIBUTE, DEFAULT_SERVER_CLASSES);
}

/**
* Add a Server Class pattern to use for all WebAppContexts of a given {@link Server}.
* @param patterns the patterns to use
*/
public static void addServerClasses(String... patterns)
{
DEFAULT_SERVER_CLASSES.add(patterns);
}

/**
* Add a Server Class pattern to use for all WebAppContexts of a given {@link Server}.
* @param server The {@link Server} instance to add classes to
* @param patterns the patterns to use
*/
public static void addServerClasses(Server server, String... patterns)
{
addClasses(server, SERVER_CLASSES_ATTRIBUTE, DEFAULT_SERVER_CLASSES, patterns);
}

/**
* Add a Server Class pattern to use for all ee9 WebAppContexts.
* @param environment The {@link Environment} instance to add classes to
* @param patterns the patterns to use
*/
public static void addServerClasses(Environment environment, String... patterns)
{
addClasses(environment, SERVER_CLASSES_ATTRIBUTE, DEFAULT_SERVER_CLASSES, patterns);
}

private static void addClasses(Attributes attributes, String attribute, ClassMatcher defaultPatterns, String... patterns)
{
ClassMatcher classMatcher = getClassMatcher(attributes, attribute, defaultPatterns);
if (patterns != null && patterns.length > 0)
classMatcher.add(patterns);
}

private static ClassMatcher getClassMatcher(Attributes attributes, String attribute, ClassMatcher defaultPatterns)
{
Object existing = attributes.getAttribute(attribute);
if (existing instanceof ClassMatcher cm)
return cm;

ClassMatcher classMatcher = (existing instanceof String[] stringArray)
? new ClassMatcher(stringArray) : new ClassMatcher(defaultPatterns);
attributes.setAttribute(attribute, classMatcher);
return classMatcher;
}

}
Loading
Loading