From c4d715206e09200002ccece85c5c0a68d52363d2 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Fri, 23 Oct 2026 09:54:10 +0200 Subject: [PATCH] Access h2 database which is used during local testing When testing locally an h2 database is used. In order to access this database, e.g. for troubleshooting, the changes provided by this commit are required. --- samples/bookshop/srv/pom.xml | 1 - .../customer/bookshop/SecurityConfig.java | 31 +++++++++++++++++++ .../srv/src/main/resources/application.yaml | 10 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 samples/bookshop/srv/src/main/java/customer/bookshop/SecurityConfig.java diff --git a/samples/bookshop/srv/pom.xml b/samples/bookshop/srv/pom.xml index bb3004b3e..5167d650c 100644 --- a/samples/bookshop/srv/pom.xml +++ b/samples/bookshop/srv/pom.xml @@ -47,7 +47,6 @@ com.h2database h2 - runtime diff --git a/samples/bookshop/srv/src/main/java/customer/bookshop/SecurityConfig.java b/samples/bookshop/srv/src/main/java/customer/bookshop/SecurityConfig.java new file mode 100644 index 000000000..7d88ba303 --- /dev/null +++ b/samples/bookshop/srv/src/main/java/customer/bookshop/SecurityConfig.java @@ -0,0 +1,31 @@ +/* + * © 2024 SAP SE or an SAP affiliate company and cds-feature-attachments contributors. + */ +package customer.bookshop; + +import org.h2.server.web.JakartaWebServlet; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.web.firewall.HttpFirewall; +import org.springframework.security.web.firewall.StrictHttpFirewall; + +@Configuration +public class SecurityConfig { + + @Bean + public HttpFirewall allowSemicolonHttpFirewall() { + StrictHttpFirewall firewall = new StrictHttpFirewall(); + firewall.setAllowSemicolon(true); + return firewall; + } + + @Bean + public ServletRegistrationBean h2ServletRegistration() { + ServletRegistrationBean registration = + new ServletRegistrationBean<>(new JakartaWebServlet(), "/h2-console/*"); + registration.addInitParameter("-webAllowOthers", ""); + return registration; + } + +} diff --git a/samples/bookshop/srv/src/main/resources/application.yaml b/samples/bookshop/srv/src/main/resources/application.yaml index f655cc3d8..919cd2f2a 100644 --- a/samples/bookshop/srv/src/main/resources/application.yaml +++ b/samples/bookshop/srv/src/main/resources/application.yaml @@ -7,6 +7,14 @@ spring: sql: init: platform: h2 + h2: + console: + enabled: true + path: /h2-console + settings: + web-allow-others: true + security: + ignored: /h2-console/** cds: security: mock: @@ -17,6 +25,8 @@ cds: - admin user: password: user + open-paths: + - /h2-console/** data-source: auto-config: enabled: false