reenable ee10 distribution tests

Signed-off-by:  Jan Bartel <janb@webtide.com>
This commit is contained in:
Greg Wilkins 2022-07-08 09:52:20 +10:00
parent 33487b5fd8
commit 8322899650
68 changed files with 2352 additions and 79 deletions

View File

@ -6,6 +6,10 @@ Enables use of the apache implementation of JSP.
[environment]
ee10
[depend]
ee10-servlet
ee10-annotations
[lib]
lib/ee10-apache-jsp/*.jar
lib/jetty-ee10-apache-jsp-${jetty.version}.jar

View File

@ -7,6 +7,6 @@
#org.eclipse.jetty.io.LEVEL=DEBUG
#org.eclipse.jetty.io.ssl.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.ee9.servlets.LEVEL=DEBUG
#org.eclipse.jetty.ee10.servlets.LEVEL=DEBUG
#org.eclipse.jetty.alpn.LEVEL=DEBUG
#org.eclipse.jetty.jmx.LEVEL=DEBUG

View File

@ -6,6 +6,6 @@ org.eclipse.jetty.demos.JettyHome.LEVEL=DEBUG
#org.eclipse.jetty.io.LEVEL=DEBUG
#org.eclipse.jetty.io.ssl.LEVEL=DEBUG
#org.eclipse.jetty.server.LEVEL=DEBUG
#org.eclipse.jetty.ee9.servlets.LEVEL=DEBUG
#org.eclipse.jetty.ee10.servlets.LEVEL=DEBUG
#org.eclipse.jetty.alpn.LEVEL=DEBUG
#org.eclipse.jetty.jmx.LEVEL=DEBUG

View File

@ -11,8 +11,8 @@ ee10-security
client
[lib]
lib/jetty-util-ajax-${jetty.version}.jar
lib/jetty-ee10-openid-${jetty.version}.jar
lib/jetty-ee10-util-ajax-${jetty.version}.jar
[files]
basehome:modules/openid/jetty-ee10-openid-baseloginservice.xml|etc/jetty-ee10-openid-baseloginservice.xml

View File

@ -0,0 +1 @@
org.eclipse.jetty.ee10.security.openid.OpenIdAuthenticatorFactory

View File

@ -1 +0,0 @@
org.eclipse.jetty.security.openid.OpenIdAuthenticatorFactory

View File

@ -1 +0,0 @@
org.eclipse.jetty.ee9.security.openid.OpenIdAuthenticatorFactory

View File

@ -7,25 +7,12 @@
<Arg><Property name="jetty.quickstart.mode"/></Arg>
</Call>
<Ref refid="webappprovider">
<Get name="configurationManager">
<Ref refid="WebAppProvider">
<Get name="properties">
<Put name="jetty.quickstart.mode"><Property name="jetty.quickstart.mode"/></Put>
<Put name="jetty.quickstart.origin"><Property name="jetty.quickstart.origin"/></Put>
<Put name="jetty.quickstart.xml"><Property name="jetty.quickstart.xml"/></Put>
<Put name="jetty.deploy.attribute.org.eclipse.jetty.quickstart.mode"><Property name="jetty.quickstart.mode"/></Put>
<Put name="jetty.deploy.attribute.org.eclipse.jetty.quickstart.origin"><Property name="jetty.quickstart.origin"/></Put>
<Put name="jetty.deploy.attribute.org.eclipse.jetty.quickstart.xml"><Property name="jetty.quickstart.xml"/></Put>
</Get>
</Get>
</Ref>
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding">
<Set name="jettyXml">
<Property name="jetty.base"/>/etc/jetty-ee10-quickstart-webapp.xml
</Set>
</New>
</Arg>
</Call>
</Ref>
</Configure>

View File

@ -16,10 +16,6 @@ lib/jetty-ee10-quickstart-${jetty.version}.jar
[xml]
etc/jetty-ee10-quickstart.xml
[files]
basehome:modules/jetty-quickstart.d/jetty-ee10-quickstart-webapp.xml|etc/jetty-ee10-quickstart-webapp.xml
[ini-template]
# Modes are AUTO, GENERATE, QUICKSTART

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.ee10.webapp.WebAppContext">
<Call name="setAttribute">
<Arg>org.eclipse.jetty.quickstart.origin</Arg>
<Arg><Property name="jetty.quickstart.origin" default="origin"/></Arg>
</Call>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.quickstart.xml</Arg>
<Arg><Property name="jetty.quickstart.xml"/></Arg>
</Call>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.quickstart.mode</Arg>
<Arg>
<Call class="org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration$Mode" name="valueOf">
<Arg><Property name="jetty.quickstart.mode" default="AUTO"/></Arg>
</Call>
</Arg>
</Call>
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
<Set name="copyWebInf">false</Set>
</Configure>

View File

@ -106,7 +106,7 @@ public class PreconfigureQuickStartWar
webapp.setAttribute(QuickStartConfiguration.MODE, QuickStartConfiguration.Mode.GENERATE);
webapp.setAttribute(QuickStartConfiguration.ORIGIN_ATTRIBUTE, "");
webapp.setAttribute(MetaInfConfiguration.CONTAINER_JAR_PATTERN,
".*/jetty-jakarta-servlet-api-[^/]*\\.jar$|.*/jakarta.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs-standard-.*\\.jar$");
".*/jakarta.servlet-api-[^/]*\\.jar$|.*jakarta.servlet.jsp.jstl-.*\\.jar$");
if (xml != null)
{
if (xml.isDirectory() || !xml.toString().toLowerCase(Locale.ENGLISH).endsWith(".xml"))

View File

@ -99,12 +99,18 @@ public class QuickStartConfiguration extends AbstractConfiguration
LOG.debug("quickStartWebXml={} exists={}", quickStartWebXml, quickStartWebXml.exists());
//Get the mode
Mode mode = (Mode)context.getAttribute(MODE);
Object o = context.getAttribute(MODE);
Mode mode;
if (o instanceof Mode)
mode = (Mode)o;
else
mode = Mode.valueOf((String)o);
if (mode != null)
_mode = mode;
_quickStart = false;
switch (_mode)
{
case GENERATE:

View File

@ -0,0 +1,24 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<artifactId>jetty-ee10-test-badinit-webapp</artifactId>
<packaging>war</packaging>
<name>Test :: Jetty EE10 Test Bad Init Webapp</name>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,39 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.ee10.test;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class BadServletInit extends HttpServlet
{
@Override
public void init() throws ServletException
{
ServletException cause = new ServletException("This servlet is intentionally failing init()");
cause.printStackTrace(System.err);
throw cause;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
resp.getWriter().println("Should not work");
}
}

View File

@ -0,0 +1,20 @@
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Intentionally Bad Init</display-name>
<servlet>
<servlet-name>BadInit</servlet-name>
<servlet-class>org.eclipse.jetty.ee10.test.BadServletInit</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>BadInit</servlet-name>
<url-pattern>/bad/*</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,54 @@
<?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">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-test-cdi-common-webapp</artifactId>
<name>Test :: Jetty EE10 CDI :: Common Demo Webapp</name>
<packaging>war</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.cdi.common</bundle-symbolic-name>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-- provided by container -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,28 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.inject.Named;
public class FriendlyGreetings
{
@Produces
@Named("friendly")
public Greetings getGreetings(InjectionPoint ip)
{
return () -> "Hello " + ip.getMember().getDeclaringClass().getSimpleName();
}
}

View File

@ -0,0 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
public interface Greetings
{
String getGreeting();
}

View File

@ -0,0 +1,40 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import java.io.IOException;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/greetings")
public class GreetingsServlet extends HttpServlet
{
@Inject
@Named("friendly")
public Greetings greetings;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setContentType("text/plain");
resp.getWriter().print(greetings.getGreeting());
resp.getWriter().print(" from ");
resp.getWriter().println(getServletContext().getAttribute("ServerID"));
}
}

View File

@ -0,0 +1,55 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.InjectionPoint;
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Inject;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/info")
public class InfoServlet extends HttpServlet
{
@Inject
BeanManager beanManager;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
out.println("Bean Manager: " + beanManager);
Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<Any>() {});
for (Bean<?> bean : beans)
{
out.printf("%16s => %s%n", bean.getName(), bean);
for (InjectionPoint ij : bean.getInjectionPoints())
{
out.printf("%16s -> %s%n", "", ij);
}
}
}
}

View File

@ -0,0 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import jakarta.enterprise.inject.Produces;
public class ManifestServerID
{
@Produces
public ServerID getServerID()
{
return () ->
{
String implVersion = this.getClass().getPackage().getImplementationVersion();
if (implVersion == null)
implVersion = this.getClass().getPackage().getName();
if (implVersion == null)
implVersion = "unknown";
return "CDI-Demo-" + implVersion;
};
}
}

View File

@ -0,0 +1,39 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import jakarta.inject.Inject;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;
@WebListener
public class MyContextListener implements ServletContextListener
{
@Inject
public ServerID serverId;
@Override
public void contextInitialized(ServletContextEvent sce)
{
if (serverId == null)
throw new IllegalStateException("CDI did not inject!");
sce.getServletContext().setAttribute("ServerID", serverId.get());
}
@Override
public void contextDestroyed(ServletContextEvent sce)
{
}
}

View File

@ -0,0 +1,27 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
public class OldGreetings
{
@Produces
@Named("old")
public Greetings getGreeting()
{
return () -> "Salutations!";
}
}

View File

@ -0,0 +1,19 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
public interface ServerID
{
String get();
}

View File

@ -0,0 +1,53 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test;
import java.io.IOException;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletResponse;
/**
* A Web Filter that doesn't use CDI.
*/
@WebFilter("/*")
public class ServerIDFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig)
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
if (response instanceof HttpServletResponse)
{
String serverID = (String)request.getServletContext().getAttribute("ServerID");
((HttpServletResponse)response).setHeader("Server", serverID);
}
chain.doFilter(request, response);
}
@Override
public void destroy()
{
}
}

View File

@ -0,0 +1,8 @@
<beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>

View File

@ -0,0 +1,7 @@
<H1>CDI Test Webapp</H1>
<H2>CDI Info</H2>
<iframe src="info" width="100%" height="60%"></iframe>
<H2>Greetings test</H2>
<iframe src="greetings" width="100%"></iframe>

View File

@ -63,17 +63,17 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jakarta-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jetty-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jetty-client</artifactId>
<scope>test</scope>
</dependency>

View File

@ -1,4 +1,4 @@
# Jetty Logging using jetty-slf4j-impl
org.eclipse.jetty.LEVEL=INFO
org.eclipse.jetty.ee9.cdi.LEVEL=DEBUG
org.eclipse.jetty.ee10.cdi.LEVEL=DEBUG
org.jboss.LEVEL=DEBUG

View File

@ -0,0 +1,50 @@
<?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">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-test-felix-webapp</artifactId>
<name>Test :: Jetty EE10 Felix Webapp</name>
<packaging>war</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.felix</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>7.0.5</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,77 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.demo;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.annotation.WebListener;
import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
@WebListener
public class AppListener implements ServletContextListener
{
public void contextInitialized(ServletContextEvent sce)
{
Framework framework = initFelix();
sce.getServletContext().setAttribute(Framework.class.getName(), framework);
}
private Framework initFelix()
{
Map<String, String> properties = new HashMap<>();
try
{
Path cacheDir = Files.createTempDirectory("felix-cache");
properties.put(Constants.FRAMEWORK_STORAGE, cacheDir.toAbsolutePath().toString());
properties.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
properties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
properties.put(Constants.FRAMEWORK_BOOTDELEGATION, "*");
}
catch (IOException e)
{
throw new RuntimeException("Unable to configure Felix", e);
}
Framework framework = ServiceLoader.load(FrameworkFactory.class).iterator().next().newFramework(properties);
try
{
System.err.println("Initializing felix");
framework.init();
System.err.println("Starting felix");
framework.start();
}
catch (Exception e)
{
e.printStackTrace(System.err);
throw new RuntimeException("Unable to start Felix", e);
}
return framework;
}
public void contextDestroyed(ServletContextEvent sce)
{
}
}

View File

@ -0,0 +1,49 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.demo;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.launch.Framework;
@WebServlet("/info")
public class InfoServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
Framework framework = (Framework)getServletContext().getAttribute(Framework.class.getName());
out.printf("Framework: %s\n", framework);
BundleContext bundleContext = framework.getBundleContext();
out.printf("BundleContext: %s\n", bundleContext);
Bundle bundleSelf = bundleContext.getBundle();
out.printf("BundleContext.bundle: %s\n", bundleSelf);
for (Bundle bundle : bundleContext.getBundles())
{
out.printf("bundle[]: %s\n", bundle);
}
}
}

View File

@ -0,0 +1,31 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-test-openid-webapp</artifactId>
<packaging>war</packaging>
<name>Test :: Jetty EE10 OpenId Webapp</name>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,32 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.openid;
import java.io.IOException;
import java.util.Map;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class AdminPage extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
@SuppressWarnings("unchecked")
Map<String, Object> userInfo = (Map<String, Object>)request.getSession().getAttribute("org.eclipse.jetty.security.openid.claims");
response.getWriter().println(userInfo.get("sub") + ": success");
}
}

View File

@ -0,0 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.openid;
import java.io.IOException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class ErrorPage extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
response.getWriter().println("not authorized");
response.getWriter().println("<br><a href=\"" + request.getContextPath() + "\">Home</a>");
}
}

View File

@ -0,0 +1,46 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.openid;
import java.io.IOException;
import java.security.Principal;
import java.util.Map;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class HomePage extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
Principal userPrincipal = request.getUserPrincipal();
if (userPrincipal != null)
{
@SuppressWarnings("unchecked")
Map<String, Object> userInfo = (Map<String, Object>)request.getSession().getAttribute("org.eclipse.jetty.security.openid.claims");
response.getWriter().println("userId: " + userInfo.get("sub") + "<br>");
response.getWriter().println("name: " + userInfo.get("name") + "<br>");
response.getWriter().println("email: " + userInfo.get("email") + "<br>");
response.getWriter().println("<br><a href=\"" + request.getContextPath() + "/logout\">Logout</a>");
}
else
{
response.getWriter().println("not authenticated");
response.getWriter().println("<br><a href=\"" + request.getContextPath() + "/login\">Login</a>");
}
}
}

View File

@ -0,0 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.openid;
import java.io.IOException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class LoginPage extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setContentType("text/html");
response.getWriter().println("success");
response.getWriter().println("<br><a href=\"" + request.getContextPath() + "\">Home</a>");
}
}

View File

@ -0,0 +1,30 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.openid;
import java.io.IOException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class LogoutPage extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
request.getSession().invalidate();
response.sendRedirect(request.getContextPath());
}
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false"
version="3.1">
<login-config>
<auth-method>OPENID</auth-method>
</login-config>
<servlet>
<servlet-name>AdminPage</servlet-name>
<servlet-class>org.eclipse.jetty.test.openid.AdminPage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminPage</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ErrorPage</servlet-name>
<servlet-class>org.eclipse.jetty.test.openid.ErrorPage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ErrorPage</servlet-name>
<url-pattern>/error</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HomePage</servlet-name>
<servlet-class>org.eclipse.jetty.test.openid.HomePage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomePage</servlet-name>
<url-pattern/>
</servlet-mapping>
<servlet>
<servlet-name>LoginPage</servlet-name>
<servlet-class>org.eclipse.jetty.test.openid.LoginPage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginPage</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>LogoutPage</servlet-name>
<servlet-class>org.eclipse.jetty.test.openid.LogoutPage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogoutPage</servlet-name>
<url-pattern>/logout</url-pattern>
</servlet-mapping>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>**</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>User Pages</web-resource-name>
<url-pattern>/profile</url-pattern>
<url-pattern>/login</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>**</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin Page</web-resource-name>
<url-pattern>/admin</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
</web-app>

View File

@ -0,0 +1,67 @@
<?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">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-test-owb-cdi-webapp</artifactId>
<name>Test :: Jetty EE10 CDI OWB Demo Webapp</name>
<packaging>war</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.cdi.owb</bundle-symbolic-name>
<openwebbeans.version>2.0.27</openwebbeans.version>
</properties>
<build>
<finalName>jetty-ee10-test-owb-cdi-demo</finalName>
</build>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-test-cdi-common-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<!-- included in webapp -->
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>${openwebbeans.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jetty9</artifactId>
<version>${openwebbeans.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1 @@
org.eclipse.jetty.ee10.cdi.owb.OwbServletContainerInitializer

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.ee10.webapp.WebAppContext">
<!-- Enable OWB ServletContainerInitializer
See: https://issues.apache.org/jira/browse/OWB-1296 -->
<Call name="setInitParameter">
<Arg>openwebbeans.web.sci.active</Arg>
<Arg>true</Arg>
</Call>
<New id="BeanManager" class="org.eclipse.jetty.ee10.plus.jndi.Resource">
<Arg>
<Ref refid="webAppCtx" />
</Arg>
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>jakarta.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.apache.webbeans.container.ManagerObjectFactory</Arg>
<Arg/>
</New>
</Arg>
</New>
</Configure>

View File

@ -0,0 +1,16 @@
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="wac" class="org.eclipse.jetty.ee10.webapp.WebAppContext">
<!-- Rename this file to jetty-web.xml if the cdi-spi module is not used-->
<Get id="wal" name="classLoader"/>
<Get id="objf" name="objectFactory">
<Call name="addDecorator">
<Arg>
<!-- TODO this doesn't exist yet -->
<New class="org.apache.webbeans.web.jetty10.JettyDecorator">
<Arg><Ref refid="wal"/></Arg>
</New>
</Arg>
</Call>
</Get>
</Configure>

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>OWB CDI Integration Test WebApp</display-name>
<!-- Required by org.apache.webbeans.servlet.WebBeansConfigurationListener$Auto -->
<context-param>
<param-name>openwebbeans.web.sci.active</param-name>
<param-value>true</param-value>
</context-param>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>jakarta.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>

View File

@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-mock-resources</artifactId>
<artifactId>jetty-ee10-demo-mock-resources</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -55,29 +55,29 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-jndi-webapp</artifactId>
<artifactId>jetty-ee10-demo-jndi-webapp</artifactId>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-spec-webapp</artifactId>
<artifactId>jetty-ee10-demo-spec-webapp</artifactId>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-jetty-webapp</artifactId>
<artifactId>jetty-ee10-demo-jetty-webapp</artifactId>
<type>war</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jakarta-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jetty-server</artifactId>
<scope>test</scope>
</dependency>
@ -149,7 +149,7 @@
<artifactItems>
<artifactItem>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-jndi-webapp</artifactId>
<artifactId>jetty-ee10-demo-jndi-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
@ -159,7 +159,7 @@
</artifactItem>
<artifactItem>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-spec-webapp</artifactId>
<artifactId>jetty-ee10-demo-spec-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
@ -169,7 +169,7 @@
</artifactItem>
<artifactItem>
<groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>demo-jetty-webapp</artifactId>
<artifactId>jetty-ee10-demo-jetty-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>

View File

@ -33,6 +33,7 @@ import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.eclipse.jetty.xml.XmlParser.Node;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@ -147,6 +148,7 @@ public class QuickStartTest
server.stop();
}
@Disabled //TODO needs DefaultServlet
@Test
public void testJNDIWar() throws Exception
{
@ -191,8 +193,8 @@ public class QuickStartTest
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream)connection.getContent());
assertEquals(200, connection.getResponseCode());
assertThat(content, Matchers.containsString("JNDI Demo WebApp"));
server.stop();

View File

@ -8,7 +8,7 @@
<New id="tx" class="org.eclipse.jetty.ee10.plus.jndi.Transaction">
<Arg>
<New class="com.acme.MockUserTransaction"/>
<New class="org.example.MockUserTransaction"/>
</Arg>
</New>
@ -33,7 +33,7 @@
<Arg><Ref refid='wac'/></Arg>
<Arg>jdbc/mydatasource</Arg>
<Arg>
<New class="com.acme.MockDataSource"/>
<New class="org.example.MockDataSource"/>
</Arg>
</New>

View File

@ -5,7 +5,7 @@
<New id="tx" class="org.eclipse.jetty.ee10.plus.jndi.Transaction">
<Arg>
<New class="com.acme.MockUserTransaction"/>
<New class="org.example.MockUserTransaction"/>
</Arg>
</New>
@ -31,7 +31,7 @@
<Arg><Ref refid='wac'/></Arg>
<Arg>jdbc/mydatasource</Arg>
<Arg>
<New class="com.acme.MockDataSource">
<New class="org.example.MockDataSource">
</New>
</Arg>
</New>

View File

@ -0,0 +1,24 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<artifactId>jetty-ee10-test-simple-session-webapp</artifactId>
<packaging>war</packaging>
<name>Test :: Jetty EE10 Test Simple Session Webapp</name>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,30 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.session;
import java.io.Serializable;
public class Chocolate implements Serializable
{
private static final long serialVersionUID = 1L;
private static final String THE_BEST_EVER = "FRENCH";
private String theBest = THE_BEST_EVER;
public String getTheBest()
{
return this.theBest;
}
}

View File

@ -0,0 +1,45 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.test.session;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
public class SessionTest extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String action = req.getParameter("action");
if ("CREATE".equals(action))
{
HttpSession session = req.getSession(true);
session.setAttribute("CHOCOLATE", new Chocolate());
resp.getOutputStream().println("SESSION CREATED");
}
else
{
HttpSession session = req.getSession(false);
Chocolate yummi = (Chocolate)session.getAttribute("CHOCOLATE");
resp.getOutputStream().println("SESSION READ CHOCOLATE THE BEST:" + yummi.getTheBest());
}
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false"
version="3.1">
<display-name>Very Simple Web Application</display-name>
<servlet>
<servlet-name>SessionTest</servlet-name>
<servlet-class>org.eclipse.jetty.test.session.SessionTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SessionTest</servlet-name>
<url-pattern>/session</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,51 @@
<?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.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<artifactId>jetty-ee10-test-webapp-rfc2616</artifactId>
<name>Tests :: Jetty EE10 RFC2616 WebApp</name>
<packaging>war</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.rfc2616</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<!-- DO NOT DEPLOY (or Release) -->
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<stopPort>8087</stopPort>
<stopKey>foo</stopKey>
<scan>1</scan>
<systemProperties>
<fooprop>222</fooprop>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlets</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,97 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.tests.webapp;
import java.io.IOException;
import java.util.Enumeration;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet declaring the various do* methods.
*
* The Jetty internals for OPTIONS should detect the declared do* methods and
* return an appropriate listing of available OPTIONS on an OPTIONS request.
*/
public class HttpMethodsServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HttpMethodsServlet()
{
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/* do nothing */
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/* do nothing */
}
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/* do nothing */
}
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/* do nothing */
}
@Override
protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
/* do nothing */
}
@Override
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.addHeader("Content-Type", "message/http");
StringBuffer msg = new StringBuffer();
msg.append(request.getMethod()).append(' ');
msg.append(request.getRequestURI()).append(' ');
msg.append(request.getProtocol()).append("\n");
// Now the headers
Enumeration enNames = request.getHeaderNames();
while (enNames.hasMoreElements())
{
String name = (String)enNames.nextElement();
Enumeration enValues = request.getHeaders(name);
while (enValues.hasMoreElements())
{
String value = (String)enValues.nextElement();
msg.append(name).append(": ").append(value).append("\n");
}
}
msg.append("\n");
response.getWriter().print(msg.toString());
}
}

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>rfc2616-webapp</display-name>
<context-param>
<param-name>org.eclipse.jetty.handler.GzipHandler.minGzipSize</param-name>
<param-value>1024</param-value>
</context-param>
<context-param>
<param-name>org.eclipse.jetty.handler.GzipHandler.includePaths</param-name>
<param-value>/*</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HttpMethodsServlet</servlet-name>
<servlet-class>org.eclipse.jetty.tests.webapp.HttpMethodsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HttpMethodsServlet</servlet-name>
<url-pattern>/httpmethods</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@ -0,0 +1,153 @@
<html>
<head>
<title>Quotable "Solutions"</title>
<style type="text/css">
body {
font-family: sans-serif;
}
h1 {
background-color: black;
color: white;
padding: 5px;
}
ul li {
list-style: none;
margin-top: 10px;
}
li .author {
color: #777;
margin-left: 20px;
font-style: italic;
}
</style>
</head>
<body bgcolor="white">
<h1>Quotable "Solutions"</h1>
<ul>
<li>
An undefined problem has an infinite number of solutions.
<div class="author">Robert A. Humphrey</div>
</li>
<li>
There is always a well-known solution to every human problem--neat, plausible, and wrong.
<div class="author">H. L. Mencken (1880 - 1956), The Divine Afflatus / Prejudices: Second Series, 1920</div>
</li>
<li>
If you're not part of the solution, you're part of the precipitate.
<div class="author">Henry J. Tillman</div>
</li>
<li>
Two paradoxes are better than one; they may even suggest a solution.
<div class="author">Edward Teller (1908 - 2003)</div>
</li>
<li>
The direct use of force is such a poor solution to any problem, it is generally employed only by small children and large nations.
<div class="author">David Friedman</div>
</li>
<li>
When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong.
<div class="author">R. Buckminster Fuller (1895 - 1983)</div>
</li>
<li>
We are at the very beginning of time for the human race. It is not unreasonable that we grapple with problems. But there are tens of thousands of years in the future. Our responsibility is to do what we can, learn what we can, improve the solutions, and pass them on.
<div class="author">Richard Feynman (1918 - 1988)</div>
</li>
<li>
It's so much easier to suggest solutions when you don't know too much about the problem.
<div class="author">Malcolm Forbes (1919 - 1990)</div>
</li>
<li>
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
<div class="author">Bertrand Russell (1872 - 1970)</div>
</li>
<li>
All progress is precarious, and the solution of one problem brings us face to face with another problem.
<div class="author">Martin Luther King Jr. (1929 - 1968), 'Strength to Love,' 1963</div>
</li>
<li>
It isn't that they can't see the solution. It is that they can't see the problem.
<div class="author">G. K. Chesterton (1874 - 1936), Scandal of Father Brown (1935)</div>
</li>
<li>
Focus 90% of your time on solutions and only 10% of your time on problems.
<div class="author">Anthony J. D'Angelo, The College Blue Book</div>
</li>
<li>
Within the problem lies the solution
<div class="author">Milton Katselas</div>
</li>
<li>
Good management is the art of making problems so interesting and their solutions so constructive that everyone wants to get to work and deal with them.
<div class="author">Paul Hawken, Growing a Business</div>
</li>
<li>
An old puzzle asks how a barometer can be used to measure the height of a building. Answers range from dropping the instrument from the top and measuring the time of its fall to giving it to the building's superintendent in return for a look at the plans. A modern version of the puzzle asks how a personal computer can balance a checkbook. An elegant solution is to sell the machine and deposit the money.
<div class="author">Jon Bentley, More Programming Pearls</div>
</li>
<li>
Believe it can be done. When you believe something can be done, really believe, your mind will find the ways to do it. Believing a solution paves the way to solution.
<div class="author">Dr. David Schwartz</div>
</li>
<li>
To doubt everything or to believe everything are two equally convenient solutions; both dispense with the necessity of reflection.
<div class="author">Henri Poincare</div>
</li>
<li>
I have not failed. I've just found 10,000 ways that don't work.
<div class="author">Thomas Alva Edison</div>
</li>
<li>
Any solution to a problem changes the problem.
<div class="author">R.W. (Richard William) Johnson (b. 1916), U.S. journalist. Washingtonian (November 1979).</div>
</li>
<li>
Whatever creativity is, it is in part a solution to a problem.
<div class="author">Brian Aldiss (b. 1925), British science fiction writer.</div>
</li>
<li>
Only he is an artist who can make a riddle out of a solution.
<div class="author">Karl Kraus (1874 - 1936), Austrian writer.</div>
</li>
<li>
There is nothing more productive of problems than a really good solution.
<div class="author">Dr Nathan S Kline</div>
</li>
<li>
The problem is that we attempt to solve the simplest questions cleverly, thereby rendering them unusually complex. One should seek the simple solution.
<div class="author">Anton Pavlovich Chekhov (1860 - 1904), Russian author, playwright.</div>
</li>
<li>
Mankind always sets itself only such tasks as it can solve; since, looking at the matter more closely, we will always find that the task itself arises only when the material conditions necessary for its solution already exist or are at least in the process of formation.
<div class="author">Karl Marx (1818 - 1883), German political theorist, social philosopher.</div>
</li>
</ul>
</body>
</html>

View File

@ -0,0 +1,50 @@
<?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">
<parent>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-tests</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-ee10-test-weld-cdi-webapp</artifactId>
<name>Test :: Jetty EE10 CDI Weld Demo Webapp</name>
<packaging>war</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.cdi.weld</bundle-symbolic-name>
</properties>
<build>
<finalName>jetty-ee10-test-weld-cdi-demo</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-test-cdi-common-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<!-- included in webapp -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>${weld.version}</version>
<exclusions>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss.logging.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.ee10.webapp.WebAppContext">
<New id="BeanManager" class="org.eclipse.jetty.ee10.plus.jndi.Resource">
<Arg>
<Ref refid="webAppCtx"/>
</Arg>
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>jakarta.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg/>
</New>
</Arg>
</New>
</Configure>

View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>Weld CDI Integration Test WebApp</display-name>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>jakarta.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>

View File

@ -18,17 +18,25 @@
<modules>
<module>jetty-ee10-test-bad-websocket-webapp</module>
<!-- TODO <module>jetty-ee10-test-cdi</module>-->
<module>jetty-ee10-test-cdi</module>
<!-- TODO <module>jetty-ee10-test-http2-webapp</module>-->
<!-- TODO <module>jetty-ee10-test-http-client-transport</module>-->
<!-- TODO <module>jetty-ee10-test-integration</module>-->
<module>jetty-ee10-test-jmx</module>
<module>jetty-ee10-test-jndi</module>
<!-- TODO <module>jetty-ee10-test-loginservice</module>-->
<!-- TODO <module>jetty-ee10-test-quickstart</module>-->
<module>jetty-ee10-test-loginservice</module>
<module>jetty-ee10-test-quickstart</module>
<module>jetty-ee10-test-websocket-client-provided-webapp</module>
<module>jetty-ee10-test-websocket-client-webapp</module>
<module>jetty-ee10-test-websocket-webapp</module>
<module>jetty-ee10-test-cdi-common-webapp</module>
<module>jetty-ee10-test-felix-webapp</module>
<module>jetty-ee10-test-openid-webapp</module>
<module>jetty-ee10-test-owb-cdi-webapp</module>
<module>jetty-ee10-test-simple-session-webapp</module>
<module>jetty-ee10-test-webapp-rfc2616</module>
<module>jetty-ee10-test-weld-cdi-webapp</module>
<module>jetty-ee10-test-badinit-webapp</module>
</modules>
<build>

View File

@ -0,0 +1,17 @@
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>stats-demo</display-name>
<servlet>
<servlet-name>Stats</servlet-name>
<servlet-class>org.eclipse.jetty.ee10.servlet.StatisticsServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Stats</servlet-name>
<url-pattern>/stats</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,8 @@
<html>
<head>
<title>stats-demo</title>
</head>
<body>
<h1>Stats Demo</h1>
</body>
</html>

View File

@ -0,0 +1,170 @@
<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/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-distribution</artifactId>
<version>12.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>test-ee10-distribution</artifactId>
<packaging>jar</packaging>
<properties>
<bundle-symbolic-name>${project.groupId}.ee10.distribution</bundle-symbolic-name>
<distribution.debug.port>-1</distribution.debug.port>
<home.start.timeout>10</home.start.timeout>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-distribution-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.tests</groupId>
<artifactId>test-distribution-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util-ajax</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-spi</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${maven.resolver.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-http-client-transport</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http3</groupId>
<artifactId>http3-http-client-transport</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jetty-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10.websocket</groupId>
<artifactId>jetty-ee10-websocket-jetty-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-openid</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<mavenRepoPath>${settings.localRepository}</mavenRepoPath>
<jettyVersion>${project.version}</jettyVersion>
<distribution.debug.port>$(distribution.debug.port}</distribution.debug.port>
<home.start.timeout>${home.start.timeout}</home.start.timeout>
</systemPropertyVariables>
</configuration>
</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>
<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

@ -0,0 +1,119 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.ee10.tests.distribution;
import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.ee10.tests.distribution.openid.OpenIdProvider;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.tests.distribution.AbstractJettyHomeTest;
import org.eclipse.jetty.tests.distribution.JettyHomeTester;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class OpenIdTests extends AbstractJettyHomeTest
{
@Test
public void testOpenID() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();
String[] args1 = {
"--create-startd",
"--approve-all-licenses",
"--add-to-start=http,ee10-webapp,ee10-deploy,ee10-openid"
};
String clientId = "clientId123";
String clientSecret = "clientSecret456";
OpenIdProvider openIdProvider = new OpenIdProvider(clientId, clientSecret);
try (JettyHomeTester.Run run1 = distribution.start(args1))
{
assertTrue(run1.awaitFor(10, TimeUnit.SECONDS));
assertEquals(0, run1.getExitValue());
File webApp = distribution.resolveArtifact("org.eclipse.jetty.ee10:jetty-ee10-test-openid-webapp:war:" + jettyVersion);
distribution.installWarFile(webApp, "test");
int port = distribution.freePort();
openIdProvider.addRedirectUri("http://localhost:" + port + "/test/j_security_check");
openIdProvider.start();
String[] args2 = {
"jetty.http.port=" + port,
"jetty.ssl.port=" + port,
"jetty.openid.provider=" + openIdProvider.getProvider(),
"jetty.openid.clientId=" + clientId,
"jetty.openid.clientSecret=" + clientSecret,
//"jetty.server.dumpAfterStart=true",
};
try (JettyHomeTester.Run run2 = distribution.start(args2))
{
assertTrue(run2.awaitConsoleLogsFor("Started oejs.Server@", 10, TimeUnit.SECONDS));
startHttpClient(false);
String uri = "http://localhost:" + port + "/test";
openIdProvider.setUser(new OpenIdProvider.User("123456789", "Alice"));
// Initially not authenticated
ContentResponse response = client.GET(uri + "/");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
String content = response.getContentAsString();
assertThat(content, containsString("not authenticated"));
// Request to login is success
response = client.GET(uri + "/login");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
content = response.getContentAsString();
assertThat(content, containsString("success"));
// Now authenticated we can get info
response = client.GET(uri + "/");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
content = response.getContentAsString();
assertThat(content, containsString("userId: 123456789"));
assertThat(content, containsString("name: Alice"));
assertThat(content, containsString("email: Alice@example.com"));
// Request to admin page gives 403 as we do not have admin role
response = client.GET(uri + "/admin");
assertThat(response.getStatus(), is(HttpStatus.FORBIDDEN_403));
// We are no longer authenticated after logging out
response = client.GET(uri + "/logout");
assertThat(response.getStatus(), is(HttpStatus.OK_200));
content = response.getContentAsString();
assertThat(content, containsString("not authenticated"));
}
}
finally
{
openIdProvider.stop();
}
}
}

View File

@ -0,0 +1,53 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.ee10.tests.distribution.openid;
import java.util.Base64;
/**
* A basic JWT encoder for testing purposes.
*/
public class JwtEncoder
{
private static final Base64.Encoder ENCODER = Base64.getUrlEncoder();
private static final String DEFAULT_HEADER = "{\"INFO\": \"this is not used or checked in our implementation\"}";
private static final String DEFAULT_SIGNATURE = "we do not validate signature as we use the authorization code flow";
public static String encode(String idToken)
{
return stripPadding(ENCODER.encodeToString(DEFAULT_HEADER.getBytes())) + "." +
stripPadding(ENCODER.encodeToString(idToken.getBytes())) + "." +
stripPadding(ENCODER.encodeToString(DEFAULT_SIGNATURE.getBytes()));
}
private static String stripPadding(String paddedBase64)
{
return paddedBase64.split("=")[0];
}
/**
* Create a basic JWT for testing using argument supplied attributes.
*/
public static String createIdToken(String provider, String clientId, String subject, String name, long expiry)
{
return "{" +
"\"iss\": \"" + provider + "\"," +
"\"sub\": \"" + subject + "\"," +
"\"aud\": \"" + clientId + "\"," +
"\"exp\": " + expiry + "," +
"\"name\": \"" + name + "\"," +
"\"email\": \"" + name + "@example.com" + "\"" +
"}";
}
}

View File

@ -0,0 +1,341 @@
//
// ========================================================================
// Copyright (c) 1995-2022 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
// ========================================================================
//
package org.eclipse.jetty.ee10.tests.distribution.openid;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.ee10.security.openid.OpenIdConfiguration;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletContextResponse;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OpenIdProvider extends ContainerLifeCycle
{
private static final Logger LOG = LoggerFactory.getLogger(OpenIdProvider.class);
private static final String CONFIG_PATH = "/.well-known/openid-configuration";
private static final String AUTH_PATH = "/auth";
private static final String TOKEN_PATH = "/token";
private final Map<String, User> issuedAuthCodes = new HashMap<>();
protected final String clientId;
protected final String clientSecret;
protected final List<String> redirectUris = new ArrayList<>();
private final ServerConnector connector;
private final Server server;
private int port = 0;
private String provider;
private User preAuthedUser;
public static void main(String[] args) throws Exception
{
String clientId = "CLIENT_ID123";
String clientSecret = "PASSWORD123";
int port = 5771;
String redirectUri = "http://localhost:8080/openid/auth";
OpenIdProvider openIdProvider = new OpenIdProvider(clientId, clientSecret);
openIdProvider.addRedirectUri(redirectUri);
openIdProvider.setPort(port);
openIdProvider.start();
try
{
openIdProvider.join();
}
finally
{
openIdProvider.stop();
}
}
public OpenIdProvider(String clientId, String clientSecret)
{
this.clientId = clientId;
this.clientSecret = clientSecret;
server = new Server();
connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
contextHandler.addServlet(new ServletHolder(new OpenIdConfigServlet()), CONFIG_PATH);
contextHandler.addServlet(new ServletHolder(new OpenIdAuthEndpoint()), AUTH_PATH);
contextHandler.addServlet(new ServletHolder(new OpenIdTokenEndpoint()), TOKEN_PATH);
server.setHandler(contextHandler);
addBean(server);
}
public void join() throws InterruptedException
{
server.join();
}
public OpenIdConfiguration getOpenIdConfiguration()
{
String provider = getProvider();
String authEndpoint = provider + AUTH_PATH;
String tokenEndpoint = provider + TOKEN_PATH;
return new OpenIdConfiguration(provider, authEndpoint, tokenEndpoint, clientId, clientSecret, null);
}
@Override
protected void doStart() throws Exception
{
connector.setPort(port);
super.doStart();
provider = "http://localhost:" + connector.getLocalPort();
}
public void setPort(int port)
{
if (isStarted())
throw new IllegalStateException();
this.port = port;
}
public void setUser(User user)
{
this.preAuthedUser = user;
}
public String getProvider()
{
if (!isStarted() && port == 0)
throw new IllegalStateException("Port of OpenIdProvider not configured");
return provider;
}
public void addRedirectUri(String uri)
{
redirectUris.add(uri);
}
public class OpenIdAuthEndpoint extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
if (!clientId.equals(req.getParameter("client_id")))
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "invalid client_id");
return;
}
String redirectUri = req.getParameter("redirect_uri");
if (!redirectUris.contains(redirectUri))
{
LOG.warn("invalid redirectUri {}", redirectUri);
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "invalid redirect_uri");
return;
}
String scopeString = req.getParameter("scope");
List<String> scopes = (scopeString == null) ? Collections.emptyList() : Arrays.asList(StringUtil.csvSplit(scopeString));
if (!scopes.contains("openid"))
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "no openid scope");
return;
}
if (!"code".equals(req.getParameter("response_type")))
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "response_type must be code");
return;
}
String state = req.getParameter("state");
if (state == null)
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "no state param");
return;
}
if (preAuthedUser == null)
{
PrintWriter writer = resp.getWriter();
resp.setContentType("text/html");
writer.println("<h2>Login to OpenID Connect Provider</h2>");
writer.println("<form action=\"" + AUTH_PATH + "\" method=\"post\">");
writer.println("<input type=\"text\" autocomplete=\"off\" placeholder=\"Username\" name=\"username\" required>");
writer.println("<input type=\"hidden\" name=\"redirectUri\" value=\"" + redirectUri + "\">");
writer.println("<input type=\"hidden\" name=\"state\" value=\"" + state + "\">");
writer.println("<input type=\"submit\">");
writer.println("</form>");
}
else
{
redirectUser(req, resp, preAuthedUser, redirectUri, state);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
String redirectUri = req.getParameter("redirectUri");
if (!redirectUris.contains(redirectUri))
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "invalid redirect_uri");
return;
}
String state = req.getParameter("state");
if (state == null)
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "no state param");
return;
}
String username = req.getParameter("username");
if (username == null)
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "no username");
return;
}
User user = new User(username);
redirectUser(req, resp, user, redirectUri, state);
}
public void redirectUser(HttpServletRequest request, HttpServletResponse response, User user, String redirectUri, String state) throws IOException
{
String authCode = UUID.randomUUID().toString().replace("-", "");
issuedAuthCodes.put(authCode, user);
try
{
redirectUri += "?code=" + authCode + "&state=" + state;
int redirectCode = (HttpVersion.fromString(request.getProtocol()).getVersion() < HttpVersion.HTTP_1_1.getVersion()
? HttpServletResponse.SC_MOVED_TEMPORARILY : HttpServletResponse.SC_SEE_OTHER);
ServletContextResponse.getBaseResponse(response).getServletApiResponse().sendRedirect(redirectCode, response.encodeRedirectURL(redirectUri));
}
catch (Throwable t)
{
issuedAuthCodes.remove(authCode);
throw t;
}
}
}
public class OpenIdTokenEndpoint extends HttpServlet
{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
String code = req.getParameter("code");
if (!clientId.equals(req.getParameter("client_id")) ||
!clientSecret.equals(req.getParameter("client_secret")) ||
!redirectUris.contains(req.getParameter("redirect_uri")) ||
!"authorization_code".equals(req.getParameter("grant_type")) ||
code == null)
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "bad auth request");
return;
}
User user = issuedAuthCodes.remove(code);
if (user == null)
{
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "invalid auth code");
return;
}
String accessToken = "ABCDEFG";
long expiry = System.currentTimeMillis() + Duration.ofMinutes(10).toMillis();
String response = "{" +
"\"access_token\": \"" + accessToken + "\"," +
"\"id_token\": \"" + JwtEncoder.encode(user.getIdToken(provider, clientId)) + "\"," +
"\"expires_in\": " + expiry + "," +
"\"token_type\": \"Bearer\"" +
"}";
resp.setContentType("text/plain");
resp.getWriter().print(response);
}
}
public class OpenIdConfigServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
String discoveryDocument = "{" +
"\"issuer\": \"" + provider + "\"," +
"\"authorization_endpoint\": \"" + provider + AUTH_PATH + "\"," +
"\"token_endpoint\": \"" + provider + TOKEN_PATH + "\"," +
"}";
resp.getWriter().write(discoveryDocument);
}
}
public static class User
{
private final String subject;
private final String name;
public User(String name)
{
this(UUID.nameUUIDFromBytes(name.getBytes()).toString(), name);
}
public User(String subject, String name)
{
this.subject = subject;
this.name = name;
}
public String getName()
{
return name;
}
public String getSubject()
{
return subject;
}
public String getIdToken(String provider, String clientId)
{
long expiry = System.currentTimeMillis() + Duration.ofMinutes(1).toMillis();
return JwtEncoder.createIdToken(provider, clientId, subject, name, expiry);
}
}
}