openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans-meecrowave] branch master updated: MEECROWAVE-204 ensure we use Random and not SecureRandom by default to speed up the startup
Date Wed, 24 Jul 2019 12:16:29 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git


The following commit(s) were added to refs/heads/master by this push:
     new a6fe2e4  MEECROWAVE-204 ensure we use Random and not SecureRandom by default to speed
up the startup
a6fe2e4 is described below

commit a6fe2e4264efa5776d3a3da70807d4c88c37e880
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
AuthorDate: Wed Jul 24 14:16:21 2019 +0200

    MEECROWAVE-204 ensure we use Random and not SecureRandom by default to speed up the startup
---
 .../java/org/apache/meecrowave/Meecrowave.java     | 51 ++++++++--------------
 .../java/org/apache/meecrowave/MeecrowaveTest.java | 13 ++++++
 2 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
index 748cd6f..36767a8 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
@@ -60,6 +60,7 @@ import java.util.Properties;
 import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.BiPredicate;
 import java.util.function.Consumer;
@@ -86,19 +87,17 @@ import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
-import org.apache.catalina.Manager;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Realm;
 import org.apache.catalina.Server;
-import org.apache.catalina.Service;
 import org.apache.catalina.Valve;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.core.StandardHost;
-import org.apache.catalina.session.ManagerBase;
 import org.apache.catalina.session.StandardManager;
 import org.apache.catalina.startup.Catalina;
 import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.util.StandardSessionIdGenerator;
 import org.apache.coyote.http2.Http2Protocol;
 import org.apache.meecrowave.api.StartListening;
 import org.apache.meecrowave.api.StopListening;
@@ -398,6 +397,21 @@ public class Meecrowave implements AutoCloseable {
         }
 
         ofNullable(meta.consumer).ifPresent(c -> c.accept(ctx));
+        if (configuration.isQuickSession() && ctx.getManager() == null) {
+            final StandardManager manager = new StandardManager();
+            manager.setSessionIdGenerator(new StandardSessionIdGenerator() {
+                @Override
+                protected void getRandomBytes(final byte bytes[]) {
+                    ThreadLocalRandom.current().nextBytes(bytes);
+                }
+
+                @Override
+                public String toString() {
+                    return "MeecrowaveSessionIdGenerator@" + System.identityHashCode(this);
+                }
+            });
+            ctx.setManager(manager);
+        }
         if (configuration.antiResourceLocking && StandardContext.class.isInstance(ctx))
{
             StandardContext.class.cast(ctx).setAntiResourceLocking(true);
         }
@@ -466,11 +480,7 @@ public class Meecrowave implements AutoCloseable {
 
         clearCatalinaSystemProperties = System.getProperty("catalina.base") == null &&
System.getProperty("catalina.home") == null;
 
-        if (configuration.quickSession) {
-            tomcat = new TomcatWithFastSessionIDs();
-        } else {
-            tomcat = new InternalTomcat();
-        }
+        tomcat = new InternalTomcat();
 
         { // setup
             base = new File(newBaseDir());
@@ -2581,31 +2591,6 @@ public class Meecrowave implements AutoCloseable {
         }
     }
 
-    private static class TomcatWithFastSessionIDs extends InternalTomcat {
-        @Override
-        public void start() throws LifecycleException {
-            // Use fast, insecure session ID generation for all tests
-            final Server server = getServer();
-            for (final Service service : server.findServices()) {
-                final org.apache.catalina.Container e = service.getContainer();
-                for (final org.apache.catalina.Container h : e.findChildren()) {
-                    for (final org.apache.catalina.Container c : h.findChildren()) {
-                        Manager m = ((org.apache.catalina.Context) c).getManager();
-                        if (m == null) {
-                            m = new StandardManager();
-                            org.apache.catalina.Context.class.cast(c).setManager(m);
-                        }
-                        if (m instanceof ManagerBase) {
-                            ManagerBase.class.cast(m).setSecureRandomClass(
-                                    "org.apache.catalina.startup.FastNonSecureRandom");
-                        }
-                    }
-                }
-            }
-            super.start();
-        }
-    }
-
     private static class QuickServerXmlParser extends DefaultHandler {
         private static final SAXParserFactory FACTORY = SAXParserFactory.newInstance();
 
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
index 94916dc..3355519 100644
--- a/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/MeecrowaveTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.meecrowave;
 
+import org.apache.catalina.Context;
 import org.apache.cxf.helpers.FileUtils;
 import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.runner.cli.CliOption;
@@ -54,6 +55,18 @@ import static org.junit.Assert.fail;
 
 public class MeecrowaveTest {
     @Test
+    public void fastStartupSessionId() {
+        try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort())
+                .start().deployClasspath()) {
+            assertTrue(Context.class.cast(meecrowave.getTomcat()
+                    .getEngine()
+                    .findChildren()[0]
+                    .findChildren()[0])
+                    .getManager().getSessionIdGenerator().toString().startsWith("MeecrowaveSessionIdGenerator@"));
+        }
+    }
+
+    @Test
     public void conflictingConfig() throws MalformedURLException {
         withConfigClassLoader(() -> {
             try {


Mime
View raw message