You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2023/03/16 18:13:56 UTC

[causeway] branch master updated: updates docs for h2 console

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

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/master by this push:
     new 6100167b5f updates docs for h2 console
6100167b5f is described below

commit 6100167b5fd42eff32b0e7f0888065f5984e2f50
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Mar 16 18:13:48 2023 +0000

    updates docs for h2 console
---
 .../adoc/modules/h2console/pages/about.adoc        | 37 +++++++++++-----------
 .../h2console/ui/services/H2ManagerMenu.java       | 15 +++++----
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/testing/h2console/adoc/modules/h2console/pages/about.adoc b/testing/h2console/adoc/modules/h2console/pages/about.adoc
index c600db020c..f83707b9f1 100644
--- a/testing/h2console/adoc/modules/h2console/pages/about.adoc
+++ b/testing/h2console/adoc/modules/h2console/pages/about.adoc
@@ -81,7 +81,7 @@ Note that this launches the manager on the same host that the webapp runs, and s
 
 == Additional Configuration
 
-The following additional configuration is also required (all of this is present in the helloworld and simpleapp starter apps):
+The following additional configuration is also required (eg as in the xref:docs:starters:helloworld.adoc[] and xref:docs:starters:simpleapp.adoc[] starter apps):
 
 * the h2 jdbc driver is required on the classpath of the webapp:
 +
@@ -103,26 +103,25 @@ spring.sql.init.platform=h2
 spring.datasource.url=jdbc:h2:mem
 ----
 
-* finally, and most importantly, the h2 console servlet must be configured in `web.xml`, and must be mapped to `/db`:
+* because this is a potential security risk, a further configuration property must also be explicitly enabled:
 +
-[source,xml]
-.web.xml
-----
-<servlet>
-    <servlet-name>H2Console</servlet-name>
-    <servlet-class>org.h2.server.web.WebServlet</servlet-class>
-    <init-param>
-        <param-name>webAllowOthers</param-name>
-        <param-value>true</param-value>
-    </init-param>
-    <load-on-startup>1</load-on-startup>
-</servlet>
-<servlet-mapping>
-    <servlet-name>H2Console</servlet-name>
-    <url-pattern>/db/*</url-pattern>
-</servlet-mapping>
+[source,ini]
+.application.properties
+----
+causeway.prototyping.h2-console.web-allow-remote-access=true
 ----
 
+* and if so, then the password should be randomly generated (it will be printed to the log); this is enabled by default:
++
+[source,ini]
+.application.properties
+----
+causeway.prototyping.h2-console.generate-random-web-admin-password=true
+----
+
+
+
+
 == Disabling/hiding the menu
 
 The menu can be hidden or disabled by subscribing to its domain event, eg:
@@ -145,5 +144,5 @@ public class HideH2ManagerMenu {
 
 == Using with Secman
 
-WARNING: TODO - describe the necessary role to grant if using secman.
+If xref:security:secman:about.adoc[] is in use, then you will also need to grant the appropriate role (xref:refguide:extensions:index/secman/applib/role/seed/CausewayExtH2ConsoleRoleAndPermissions.adoc[]) to the user.
 
diff --git a/testing/h2console/ui/src/main/java/org/apache/causeway/testing/h2console/ui/services/H2ManagerMenu.java b/testing/h2console/ui/src/main/java/org/apache/causeway/testing/h2console/ui/services/H2ManagerMenu.java
index b80b6aa592..d52328f2f2 100644
--- a/testing/h2console/ui/src/main/java/org/apache/causeway/testing/h2console/ui/services/H2ManagerMenu.java
+++ b/testing/h2console/ui/src/main/java/org/apache/causeway/testing/h2console/ui/services/H2ManagerMenu.java
@@ -18,8 +18,11 @@
  */
 package org.apache.causeway.testing.h2console.ui.services;
 
+import lombok.RequiredArgsConstructor;
+
 import java.util.Optional;
 
+import javax.annotation.Priority;
 import javax.inject.Inject;
 import javax.inject.Named;
 
@@ -34,6 +37,7 @@ import org.apache.causeway.applib.annotation.PriorityPrecedence;
 import org.apache.causeway.applib.annotation.RestrictTo;
 import org.apache.causeway.applib.annotation.SemanticsOf;
 import org.apache.causeway.applib.value.LocalResourcePath;
+import org.apache.causeway.core.config.CausewayConfiguration;
 import org.apache.causeway.testing.h2console.ui.CausewayModuleTestingH2ConsoleUi;
 import org.apache.causeway.testing.h2console.ui.webmodule.WebModuleH2Console;
 
@@ -48,15 +52,12 @@ import org.apache.causeway.testing.h2console.ui.webmodule.WebModuleH2Console;
         named = "Prototyping",
         menuBar = DomainServiceLayout.MenuBar.SECONDARY
 )
-@javax.annotation.Priority(PriorityPrecedence.EARLY)
+@Priority(PriorityPrecedence.EARLY)
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
 public class H2ManagerMenu {
 
     private final WebModuleH2Console webModule;
-
-    @Inject
-    public H2ManagerMenu(final WebModuleH2Console webModule) {
-        this.webModule = webModule;
-    }
+    private final CausewayConfiguration causewayConfiguration;
 
     public static class ActionDomainEvent extends CausewayModuleApplib.ActionDomainEvent<H2ManagerMenu>{}
 
@@ -73,7 +74,7 @@ public class H2ManagerMenu {
         return getPathToH2Console().orElse(null);
     }
     @MemberSupport public boolean hideOpenH2Console() {
-        return getPathToH2Console().isEmpty();
+        return getPathToH2Console().isEmpty() || ! causewayConfiguration.getPrototyping().getH2Console().isWebAllowRemoteAccess();
     }
 
     // -- HELPER