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/08 22:07:15 UTC

[shiro] branch jetty-meecrowave-replacement created (now ec282e1d)

This is an automated email from the ASF dual-hosted git repository.

bmarwell pushed a change to branch jetty-meecrowave-replacement
in repository https://gitbox.apache.org/repos/asf/shiro.git


      at ec282e1d [WIP] Use Meecrowave

This branch includes the following new commits:

     new ec282e1d [WIP] Use Meecrowave

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: [WIP] Use Meecrowave

Posted by bm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bmarwell pushed a commit to branch jetty-meecrowave-replacement
in repository https://gitbox.apache.org/repos/asf/shiro.git

commit ec282e1d6974ea795858c5feefe74f19623c1ee9
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Tue Nov 8 23:08:28 2022 +0100

    [WIP] Use Meecrowave
---
 integration-tests/support/pom.xml                  | 170 +++++++-----------
 .../shiro/testing/web/AbstractContainerIT.java     | 198 +++------------------
 samples/web/pom.xml                                |  73 +-------
 .../shiro/test/WebAppContainerIntegrationIT.java   |   6 +-
 4 files changed, 90 insertions(+), 357 deletions(-)

diff --git a/integration-tests/support/pom.xml b/integration-tests/support/pom.xml
index a711480a..46bbf43e 100644
--- a/integration-tests/support/pom.xml
+++ b/integration-tests/support/pom.xml
@@ -17,117 +17,75 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
-<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>
+<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.apache.shiro.integrationtests</groupId>
-		<artifactId>shiro-integration-tests</artifactId>
-		<version>1.10.1-SNAPSHOT</version>
-	</parent>
+  <parent>
+    <groupId>org.apache.shiro.integrationtests</groupId>
+    <artifactId>shiro-integration-tests</artifactId>
+    <version>1.10.1-SNAPSHOT</version>
+  </parent>
 
-	<artifactId>shiro-its-support</artifactId>
-	<name>Apache Shiro :: ITs :: Support</name>
+  <artifactId>shiro-its-support</artifactId>
+  <name>Apache Shiro :: ITs :: Support</name>
 
-	<dependencies>
-	    <dependency>
-            <groupId>org.apache.taglibs</groupId>
-            <artifactId>taglibs-standard-spec</artifactId>
-            <scope>compile</scope>
-	    </dependency>
-	    <dependency>
-            <groupId>org.apache.taglibs</groupId>
-            <artifactId>taglibs-standard-impl</artifactId>
-            <scope>compile</scope>
-	    </dependency>
-	    <dependency>
-	        <groupId>javax.servlet</groupId>
-	        <artifactId>javax.servlet-api</artifactId>
-	        <scope>provided</scope>
-	    </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-slf4j-impl</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-core</artifactId>
-            <scope>runtime</scope>
-        </dependency>
+  <properties>
+    <meecrowave.version>1.2.14</meecrowave.version>
+    <tomcat.version>9.0.68</tomcat.version>
+  </properties>
 
-	    <dependency>
-	        <groupId>org.slf4j</groupId>
-	        <artifactId>jcl-over-slf4j</artifactId>
-	        <scope>runtime</scope>
-	    </dependency>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.shiro</groupId>
+      <artifactId>shiro-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.shiro</groupId>
+      <artifactId>shiro-web</artifactId>
+    </dependency>
 
-        <dependency>
-            <groupId>net.sourceforge.htmlunit</groupId>
-            <artifactId>htmlunit</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-            <version>${jetty.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-webapp</artifactId>
-            <version>${jetty.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>apache-jsp</artifactId>
-            <version>${jetty.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>apache-jstl</artifactId>
-            <version>${jetty.version}</version>
-            <type>pom</type>
-        </dependency>
-        <dependency>
-            <groupId>com.github.mjeanroy</groupId>
-            <artifactId>junit-servers-jetty</artifactId>
-            <!-- Exclude Jetty 9.2 artifacts -->
-            <exclusions>
-                <exclusion>
-                    <groupId>org.eclipse.jetty</groupId>
-                    <artifactId>jetty-server</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.eclipse.jetty</groupId>
-                    <artifactId>jetty-jndi</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.eclipse.jetty</groupId>
-                    <artifactId>jetty-continuation</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.eclipse.jetty</groupId>
-                    <artifactId>jetty-webapp</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.eclipse.jetty.websocket</groupId>
-                    <artifactId>websocket-server</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-			<scope>compile</scope>
-		</dependency>
+    <dependency>
+      <groupId>javax.servlet.jsp.jstl</groupId>
+      <artifactId>jstl-api</artifactId>
+      <version>1.2</version>
+    </dependency>
 
-		<!-- dependency on the Base64 class
-		     in 2.0 this is split out, so this dep will be removed
-		     in the future
-		 -->
-		<dependency>
-			<groupId>org.apache.shiro</groupId>
-			<artifactId>shiro-core</artifactId>
-		</dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-jasper</artifactId>
+      <version>${tomcat.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-jasper-el</artifactId>
+      <version>${tomcat.version}</version>
+      <scope>test</scope>
+    </dependency>
 
-	</dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.meecrowave</groupId>
+      <artifactId>meecrowave-specs-api</artifactId>
+      <version>${meecrowave.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.meecrowave</groupId>
+      <artifactId>meecrowave-core</artifactId>
+      <version>${meecrowave.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
 </project>
diff --git a/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java b/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java
index 4814664b..cfb72819 100644
--- a/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java
+++ b/integration-tests/support/src/main/java/org/apache/shiro/testing/web/AbstractContainerIT.java
@@ -18,205 +18,49 @@
  */
 package org.apache.shiro.testing.web;
 
-import org.apache.shiro.codec.Base64;
+import static org.junit.Assert.assertEquals;
 
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty;
-import com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration;
-import org.eclipse.jetty.annotations.AnnotationConfiguration;
-import org.eclipse.jetty.http.HttpVersion;
-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.FileResource;
-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 java.io.File;
+import javax.servlet.ServletRegistration;
+import org.apache.catalina.servlets.DefaultServlet;
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.tomcat.TomcatAutoInitializer;
 import org.junit.AfterClass;
-import org.junit.Before;
 import org.junit.BeforeClass;
 
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.ServerSocket;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-
-import static com.github.mjeanroy.junit.servers.commons.Strings.isNotBlank;
-import static org.eclipse.jetty.util.resource.Resource.newResource;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 public abstract class AbstractContainerIT {
 
-    protected static EmbeddedJetty jetty;
-
-    protected static int tlsPort;
-
-    protected final WebClient webClient = new WebClient();
-
-    protected static final File TEST_KEYSTORE_PATH = setupKeyStore();
-    protected static final String TEST_KEYSTORE_PASSWORD = "password";
+    protected static Meecrowave meecrowave;
 
     @BeforeClass
-    public static void startContainer() throws Exception {
-
-        EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder()
-                .withWebapp(getWarDir())
-                .build();
-
-        jetty = new EmbeddedJetty(config) {
-
-            /**
-             * Overriding with contents of this pull request, to make fragment scanning work.
-             * https://github.com/mjeanroy/junit-servers/pull/3
-             */
-            protected WebAppContext createdWebAppContext() throws Exception {
-                final String path = configuration.getPath();
-                final String webapp = configuration.getWebapp();
-                final String classpath = configuration.getClasspath();
-
-                WebAppContext ctx = new WebAppContext();
-                ctx.setClassLoader(Thread.currentThread().getContextClassLoader());
-                ctx.setContextPath(path);
-
-                // Useful for WebXmlConfiguration
-                ctx.setBaseResource(newResource(webapp));
-
-                ctx.setConfigurations(new Configuration[]{
-                        new WebInfConfiguration(),
-                        new WebXmlConfiguration(),
-                        new AnnotationConfiguration(),
-                        new JettyWebXmlConfiguration(),
-                        new MetaInfConfiguration(),
-                        new FragmentConfiguration(),
-                });
-
-                if (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);
-                    FileResource containerResources = new FileResource(classes.toURI());
-                    ctx.getMetaData().addContainerResource(containerResources);
-                }
-
-                Server server = getDelegate();
-
-                // web app
-                ctx.setParentLoaderPriority(true);
-                ctx.setWar(webapp);
-                ctx.setServer(server);
-
-                // Add server context
-                server.setHandler(ctx);
-
-                return ctx;
-            }
-        };
-
-        Server server = jetty.getDelegate();
-
-        // 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(
-                server,
-                new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
-                new HttpConnectionFactory(https));
-        httpsConnector.setPort(tlsPort);
-        server.addConnector(httpsConnector);
-
-        jetty.start();
-
-        assertTrue(jetty.isStarted());
+    public static void startContainer() {
+        final File root = new File(getWarDir());
+        try {
+            meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort().tomcatJspDevelopment(true));
+            meecrowave.getConfiguration().addGlobalContextCustomizer(ctx -> ctx.setJarScanner(new org.apache.tomcat.util.scan.StandardJarScanner()));
+            meecrowave.start();
+            meecrowave.deployWebapp("/", root);
+        } catch (final Exception e) {
+            e.printStackTrace();
+        }
     }
 
     protected static String getBaseUri() {
-        return "http://localhost:" + jetty.getPort() + "/";
-    }
-
-    protected static String getTlsBaseUri() {
-        return "https://localhost:" + tlsPort + "/";
+        return "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/";
     }
 
     protected static String getWarDir() {
-        File[] warFiles = new File("target").listFiles(new FilenameFilter() {
-            @Override
-            public boolean accept(File dir, String name) {
-                return name.endsWith(".war");
-            }
-        });
+        File[] warFiles = new File("target").listFiles((dir, name) -> name.endsWith(".war"));
 
         assertEquals("Expected only one war file in target directory, run 'mvn clean' and try again", 1, warFiles.length);
 
         return warFiles[0].getAbsolutePath().replaceFirst("\\.war$", "");
     }
 
-    protected static String getBasicAuthorizationHeaderValue(String username, String password) throws UnsupportedEncodingException {
-        String authorizationHeader = username + ":" + password;
-        byte[] valueBytes;
-        valueBytes = authorizationHeader.getBytes("UTF-8");
-        authorizationHeader = new String(Base64.encode(valueBytes));
-        return "Basic " + authorizationHeader;
-    }
-
-    @Before
-    public void beforeTest() {
-        webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
-    }
-
     @AfterClass
     public static void stopContainer() {
-        if (jetty != null) {
-            jetty.stop();
-        }
-    }
-
-    private static int getFreePort() {
-        try (ServerSocket socket = new ServerSocket(0)) {
-            return socket.getLocalPort();
-        } catch (IOException e) {
-            throw new IllegalStateException("Failed to allocate free port", e);
-        }
-    }
-
-    // Dealing with a keystore is NOT fun, it's easier to script one with the keytool
-    // see src/main/resources/createKeyStore.sh for more info
-    private static File setupKeyStore() {
-        try {
-            Path outKeyStoreFile = File.createTempFile("test-keystore", "jks").toPath();
-            URL keyStoreResource = Thread.currentThread().getContextClassLoader().getResource("test-keystore.jks");
-            Files.copy(keyStoreResource.openStream(), outKeyStoreFile, StandardCopyOption.REPLACE_EXISTING);
-            File keyStoreFile = outKeyStoreFile.toFile();
-
-            // clients will pick up the ssl keystore this way, so just set SSL properties
-            System.setProperty("javax.net.ssl.trustStore", keyStoreFile.getAbsolutePath());
-            System.setProperty("javax.net.ssl.trustStorePassword", TEST_KEYSTORE_PASSWORD);
-            return keyStoreFile;
-        } catch (IOException e) {
-            throw new IllegalStateException("Failed to create test keystore", e);
+        if (meecrowave != null) {
+            meecrowave.close();
         }
     }
 }
diff --git a/samples/web/pom.xml b/samples/web/pom.xml
index 405935df..aacbc331 100644
--- a/samples/web/pom.xml
+++ b/samples/web/pom.xml
@@ -31,56 +31,7 @@
     <name>Apache Shiro :: Samples :: Web</name>
     <packaging>war</packaging>
 
-    <properties>
-        <jetty.port>9080</jetty.port>
-        <jetty.postIT.sleep>1</jetty.postIT.sleep>
-    </properties>
-
-    <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>
-
     <dependencies>
-        <dependency>
-            <groupId>org.apache.taglibs</groupId>
-            <artifactId>taglibs-standard-spec</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.taglibs</groupId>
-            <artifactId>taglibs-standard-impl</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-core</artifactId>
-            <scope>runtime</scope>
-        </dependency>
         <dependency>
             <groupId>net.sourceforge.htmlunit</groupId>
             <artifactId>htmlunit</artifactId>
@@ -103,29 +54,7 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-            <version>${slf4j.version}</version>
-	    <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>apache-jsp</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>apache-jstl</artifactId>
-            <version>${jetty.version}</version>
-            <type>pom</type>
-            <scope>test</scope>
-        </dependency>
+
         <dependency>
             <groupId>org.apache.shiro.integrationtests</groupId>
             <artifactId>shiro-its-support</artifactId>
diff --git a/samples/web/src/test/java/org/apache/shiro/test/WebAppContainerIntegrationIT.java b/samples/web/src/test/java/org/apache/shiro/test/WebAppContainerIntegrationIT.java
index 3f724f30..59817644 100644
--- a/samples/web/src/test/java/org/apache/shiro/test/WebAppContainerIntegrationIT.java
+++ b/samples/web/src/test/java/org/apache/shiro/test/WebAppContainerIntegrationIT.java
@@ -20,6 +20,8 @@ package org.apache.shiro.test;
 
 import com.gargoylesoftware.htmlunit.ElementNotFoundException;
 import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.TextPage;
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.html.HtmlForm;
 import com.gargoylesoftware.htmlunit.html.HtmlInput;
@@ -38,7 +40,7 @@ public class WebAppContainerIntegrationIT extends AbstractContainerIT {
     @Before
     public void logOut() throws IOException {
         // Make sure we are logged out
-        final HtmlPage homePage = webClient.getPage(getTlsBaseUri());
+        final HtmlPage homePage = webClient.getPage(getBaseUri());
         try {
             homePage.getAnchorByHref("/logout").click();
         }
@@ -50,7 +52,7 @@ public class WebAppContainerIntegrationIT extends AbstractContainerIT {
     @Test
     public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
 
-        HtmlPage page = webClient.getPage(getTlsBaseUri() + "login.jsp");
+        HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
         HtmlForm form = page.getFormByName("loginform");
         form.<HtmlInput>getInputByName("username").setValueAttribute("root");
         form.<HtmlInput>getInputByName("password").setValueAttribute("secret");