You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bm...@apache.org on 2022/11/02 21:35:46 UTC
[shiro] branch SHIRO-889_undertow created (now 6816bdbe)
This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a change to branch SHIRO-889_undertow
in repository https://gitbox.apache.org/repos/asf/shiro.git
at 6816bdbe [SHIRO-889] partly set up undertow
This branch includes the following new commits:
new 6816bdbe [SHIRO-889] partly set up undertow
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[shiro] 01/01: [SHIRO-889] partly set up undertow
Posted by bm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a commit to branch SHIRO-889_undertow
in repository https://gitbox.apache.org/repos/asf/shiro.git
commit 6816bdbe973017a9b1c37622a3f252cb98747ffc
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Wed Nov 2 22:36:55 2022 +0100
[SHIRO-889] partly set up undertow
---
samples/web-jakarta/pom.xml | 60 +++--------
.../web/jakarta/JakartaAbstractContainerIT.java | 114 ++++++---------------
.../test/web/jakarta/TestInstanceManager.java | 37 +++++++
.../shiro/test/web/jakarta/WebContainerTest.java | 28 ++---
4 files changed, 97 insertions(+), 142 deletions(-)
diff --git a/samples/web-jakarta/pom.xml b/samples/web-jakarta/pom.xml
index 14f6704f..bba766a9 100644
--- a/samples/web-jakarta/pom.xml
+++ b/samples/web-jakarta/pom.xml
@@ -50,7 +50,7 @@
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
- <version>4.0.4</version>
+ <version>5.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -98,59 +98,27 @@
<artifactId>htmlunit</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
- <version>${jetty.version}</version>
+ <groupId>io.undertow</groupId>
+ <artifactId>undertow-core</artifactId>
+ <version>2.3.0.Final</version>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlet</artifactId>
- <version>${jetty.version}</version>
+ <groupId>io.undertow</groupId>
+ <artifactId>undertow-servlet-jakartaee9</artifactId>
+ <version>2.2.13.Final</version>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-webapp</artifactId>
- <version>${jetty.version}</version>
+ <groupId>io.undertow.jastow</groupId>
+ <artifactId>jastow-jakarta</artifactId>
+ <version>2.0.11.Final</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>apache-jsp</artifactId>
- <version>${jetty.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>apache-jstl</artifactId>
- <version>11.0.0</version>
- <scope>compile</scope>
- </dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-maven-plugin</artifactId>
- <version>${jetty.version}</version>
- <configuration>
- <contextPath>/</contextPath>
- <httpConnector>
- <port>9080</port>
- <idleTimeout>60000</idleTimeout>
- </httpConnector>
- <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
- <filename>./target/yyyy_mm_dd.request.log</filename>
- <retainDays>90</retainDays>
- <append>true</append>
- <extended>false</extended>
- <logTimeZone>GMT</logTimeZone>
- </requestLog>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
\ No newline at end of file
+</project>
diff --git a/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java
index 37e37fd1..05e1c8b8 100644
--- a/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java
+++ b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java
@@ -19,25 +19,16 @@
package org.apache.shiro.test.web.jakarta;
import com.gargoylesoftware.htmlunit.WebClient;
-import org.apache.logging.log4j.util.Strings;
+import io.undertow.Undertow;
+import io.undertow.jsp.JspServletBuilder;
+import io.undertow.server.handlers.PathHandler;
+import io.undertow.servlet.api.DeploymentInfo;
+import io.undertow.servlet.api.DeploymentManager;
+import io.undertow.servlet.api.ServletContainer;
+import java.util.HashMap;
+import org.apache.jasper.deploy.JspPropertyGroup;
+import org.apache.jasper.deploy.TagLibraryInfo;
import org.apache.shiro.lang.codec.Base64;
-//import org.eclipse.jetty.http.HttpVersion;
-//import org.eclipse.jetty.server.Connector;
-//import org.eclipse.jetty.server.HttpConfiguration;
-//import org.eclipse.jetty.server.HttpConnectionFactory;
-//import org.eclipse.jetty.server.SecureRequestCustomizer;
-//import org.eclipse.jetty.server.Server;
-//import org.eclipse.jetty.server.ServerConnector;
-//import org.eclipse.jetty.server.SslConnectionFactory;
-//import org.eclipse.jetty.util.resource.Resource;
-//import org.eclipse.jetty.util.ssl.SslContextFactory;
-//import org.eclipse.jetty.webapp.Configuration;
-//import org.eclipse.jetty.webapp.FragmentConfiguration;
-//import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
-//import org.eclipse.jetty.webapp.MetaInfConfiguration;
-//import org.eclipse.jetty.webapp.WebAppContext;
-//import org.eclipse.jetty.webapp.WebInfConfiguration;
-//import org.eclipse.jetty.webapp.WebXmlConfiguration;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -52,9 +43,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-//import static org.eclipse.jetty.util.resource.Resource.newResource;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public abstract class JakartaAbstractContainerIT {
@@ -71,70 +60,31 @@ public abstract class JakartaAbstractContainerIT {
@BeforeClass
public static void startContainer() throws Exception {
-
-// jetty = new Server();
-// ServerConnector connector = new ServerConnector(jetty);
-// connector.setPort(9080);
-// jetty.setConnectors(new Connector[] {connector});
-//
-// WebAppContext ctx = new WebAppContext();
-// ctx.setClassLoader(Thread.currentThread().getContextClassLoader());
-// ctx.setContextPath("/");
-//
-// // Useful for WebXmlConfiguration
-// ctx.setBaseResource(newResource(getWarDir()));
-//
-// ctx.setConfigurations(new Configuration[]{
-// new WebInfConfiguration(),
-// new WebXmlConfiguration(),
-// new JettyWebXmlConfiguration(),
-// new MetaInfConfiguration(),
-// new FragmentConfiguration(),
-// });
-//
-// if (Strings.isNotBlank(classpath)) {
-// // Fix to scan Spring WebApplicationInitializer
-// // This will add compiled classes to jetty classpath
-// // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
-// // And more precisely: http://stackoverflow.com/a/18449506/1215828
-// File classes = new File(classpath);
-// Resource containerResources = Resource.newResource(new File(classes.toURI()));
-// ctx.getMetaData().addContainerResource(containerResources);
-// }
-//
-// // web app
-// ctx.setParentLoaderPriority(true);
-// ctx.setWar(getWarDir());
-// ctx.setServer(jetty);
-//
-// // Add server context
-// jetty.setHandler(ctx);
-//
-// // TLS
-// tlsPort = getFreePort();
-//
-// final SslContextFactory sslContextFactory = new SslContextFactory.Server();
-// sslContextFactory.setKeyStorePath(TEST_KEYSTORE_PATH.getAbsolutePath());
-// sslContextFactory.setKeyStorePassword(TEST_KEYSTORE_PASSWORD);
-// sslContextFactory.setKeyManagerPassword(TEST_KEYSTORE_PASSWORD);
-//
-// HttpConfiguration https = new HttpConfiguration();
-// https.addCustomizer(new SecureRequestCustomizer());
-//
-// final ServerConnector httpsConnector = new ServerConnector(
-// jetty,
-// new SslConnectionFactory((SslContextFactory.Server) sslContextFactory, HttpVersion.HTTP_1_1.asString()),
-// new HttpConnectionFactory(https));
-// httpsConnector.setPort(tlsPort);
-// jetty.addConnector(httpsConnector);
-//
-// jetty.start();
-//
-// assertTrue(jetty.isStarted());
+ final PathHandler servletPath = new PathHandler();
+ final ServletContainer container = ServletContainer.Factory.newInstance();
+
+ DeploymentInfo builder = new DeploymentInfo()
+ .setClassLoader(JakartaAbstractContainerIT.class.getClassLoader())
+ .setContextPath("/servletContext")
+ //.setClassIntrospecter(TestClassIntrospector.INSTANCE)
+ .setDeploymentName("servletContext.war")
+ //.setResourceManager(new TestResourceLoader(SimpleJspTestCase.class))
+ .addServlet(JspServletBuilder.createServlet("Default Jsp Servlet", "*.jsp"));
+ JspServletBuilder.setupDeployment(builder, new HashMap<String, JspPropertyGroup>(), new HashMap<String, TagLibraryInfo>(), new TestInstanceManager());
+
+ DeploymentManager manager = container.addDeployment(builder);
+ manager.deploy();
+ servletPath.addPrefixPath(builder.getContextPath(), manager.start());
+
+ Undertow server = Undertow.builder()
+ .addHttpListener(8080, "localhost")
+ .setHandler(servletPath)
+ .build();
+ server.start();
}
- protected static String getTlsBaseUri() {
- return "https://localhost:" + tlsPort + "/";
+ protected static String getBaseUri() {
+ return "http://localhost:8080/";
}
protected static String getWarDir() {
diff --git a/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/TestInstanceManager.java b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/TestInstanceManager.java
new file mode 100644
index 00000000..0737dfd9
--- /dev/null
+++ b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/TestInstanceManager.java
@@ -0,0 +1,37 @@
+package org.apache.shiro.test.web.jakarta;
+
+import java.lang.reflect.InvocationTargetException;
+import javax.naming.NamingException;
+import org.apache.tomcat.InstanceManager;
+
+public class TestInstanceManager implements InstanceManager {
+
+ @Override
+ public Object newInstance(Class<?> clazz)
+ throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException {
+ return null;
+ }
+
+ @Override
+ public Object newInstance(String className)
+ throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException {
+ return null;
+ }
+
+ @Override
+ public Object newInstance(String fqcn, ClassLoader classLoader)
+ throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException {
+ return null;
+ }
+
+ @Override
+ public void newInstance(Object o)
+ throws IllegalAccessException, InvocationTargetException, NamingException {
+
+ }
+
+ @Override
+ public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException {
+
+ }
+}
diff --git a/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java
index 033b4bed..02118e8c 100644
--- a/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java
+++ b/samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java
@@ -38,24 +38,24 @@ public class WebContainerTest extends JakartaAbstractContainerIT {
public void startup() throws IOException {
// Make sure we are logged out
-// final HtmlPage homePage = webClient.getPage(getTlsBaseUri());
-// try {
-// homePage.getAnchorByHref("/logout").click();
-// }
-// catch (ElementNotFoundException e) {
-// //Ignore
-// }
+ final HtmlPage homePage = webClient.getPage(getBaseUri());
+ try {
+ homePage.getAnchorByHref("/logout").click();
+ }
+ catch (ElementNotFoundException e) {
+ //Ignore
+ }
}
@Test
public void logIn() throws FailingHttpStatusCodeException, IOException {
-// HtmlPage page = webClient.getPage(getTlsBaseUri() + "login.jsp");
-// HtmlForm form = page.getFormByName("loginform");
-// form.<HtmlInput>getInputByName("username").setValueAttribute("root");
-// form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
-// page = form.<HtmlInput>getInputByName("submit").click();
-// // This'll throw an exception if not logged in
-// page.getAnchorByHref("/logout");
+ HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
+ HtmlForm form = page.getFormByName("loginform");
+ form.<HtmlInput>getInputByName("username").setValueAttribute("root");
+ form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
+ page = form.<HtmlInput>getInputByName("submit").click();
+ // This'll throw an exception if not logged in
+ page.getAnchorByHref("/logout");
}
}