diff --git a/annot/src/main/java/com/predic8/membrane/annot/generator/HelpReference.java b/annot/src/main/java/com/predic8/membrane/annot/generator/HelpReference.java index b2b629e30..8e31de034 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/generator/HelpReference.java +++ b/annot/src/main/java/com/predic8/membrane/annot/generator/HelpReference.java @@ -1,4 +1,4 @@ -/* Copyright 2013 predic8 GmbH, www.predic8.com +/* Copyright 2023 predic8 GmbH, www.predic8.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/core/src/main/java/com/predic8/membrane/core/Constants.java b/core/src/main/java/com/predic8/membrane/core/Constants.java index c69527ceb..831238208 100644 --- a/core/src/main/java/com/predic8/membrane/core/Constants.java +++ b/core/src/main/java/com/predic8/membrane/core/Constants.java @@ -33,7 +33,7 @@ public class Constants { public static final String VERSION; static { - String version = "5"; // fallback + String version = "5.1"; // fallback try { Properties p = new Properties(); // Production p.load(Constants.class.getResourceAsStream("/META-INF/maven/org.membrane-soa/service-proxy-core/pom.properties")); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java index a267b7c39..2a3fe81b4 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java @@ -14,23 +14,27 @@ package com.predic8.membrane.core.interceptor.authentication; -import com.google.common.collect.*; -import com.predic8.membrane.annot.*; -import com.predic8.membrane.core.*; -import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.http.*; -import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.interceptor.authentication.session.*; -import com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.*; -import com.predic8.membrane.core.util.*; - -import java.util.*; - -import static com.predic8.membrane.core.Constants.*; -import static com.predic8.membrane.core.http.Header.*; -import static java.nio.charset.StandardCharsets.*; -import static org.apache.commons.codec.binary.Base64.*; -import static org.apache.commons.text.StringEscapeUtils.*; +import com.google.common.collect.ImmutableMap; +import com.predic8.membrane.annot.MCChildElement; +import com.predic8.membrane.annot.MCElement; +import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.exchange.Exchange; +import com.predic8.membrane.core.http.Response; +import com.predic8.membrane.core.interceptor.AbstractInterceptor; +import com.predic8.membrane.core.interceptor.Outcome; +import com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider; +import com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User; +import com.predic8.membrane.core.interceptor.authentication.session.UserDataProvider; +import com.predic8.membrane.core.util.HttpUtil; + +import java.util.List; +import java.util.NoSuchElementException; + +import static com.predic8.membrane.core.Constants.PRODUCT_NAME; +import static com.predic8.membrane.core.http.Header.AUTHORIZATION; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.commons.codec.binary.Base64.decodeBase64; +import static org.apache.commons.text.StringEscapeUtils.escapeHtml4; /** * @description Blocks requests which do not have the correct RFC 1945 basic authentication credentials (HTTP header "Authentication: Basic ...."). @@ -95,7 +99,10 @@ private String getAuthorizationHeaderDecoded(Exchange exc) { } public List getUsers() { - return ((StaticUserDataProvider)userDataProvider).getUsers(); + if (userDataProvider instanceof StaticUserDataProvider sud) { + return sud.getUsers(); + } + throw new UnsupportedOperationException("getUsers not implemented for this userDataProvider."); } /** diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java index cae4d4287..2bb8e49b0 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java @@ -46,6 +46,8 @@ public void setHtpasswdPath(String path) { this.htpasswdPath = path; } + public String getHtpasswdPath() { return this.htpasswdPath; } + @Override public Map verify(Map postData) { String username = postData.get("username"); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionException.java b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionException.java index f0586fbfa..feabddbd8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionException.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionException.java @@ -1,3 +1,17 @@ +/* Copyright 2023 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core.interceptor.json; public class JsonProtectionException extends Exception{ diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java index 7a595bc4e..b48690b9e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java @@ -240,7 +240,7 @@ public void setReportError(boolean reportError) { this.reportError = reportError; } - public boolean getReportError() { + public Boolean getReportError() { return reportError; } diff --git a/core/src/test/java/com/predic8/membrane/core/config/CustomSpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/CustomSpringConfigurationTest.java index 1fa4e403a..1569ceb60 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/CustomSpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/CustomSpringConfigurationTest.java @@ -31,6 +31,7 @@ import com.predic8.membrane.core.interceptor.server.WebServerInterceptor; import com.predic8.membrane.core.interceptor.statistics.*; import com.predic8.membrane.core.interceptor.xslt.XSLTInterceptor; +import jdk.jshell.spi.ExecutionControl; import org.junit.jupiter.api.*; @SuppressWarnings("unused") diff --git a/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java b/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java index 242a0f04f..0a97f16f5 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java @@ -57,6 +57,7 @@ public class ConfigSerializationTest { "stax-interceptor", // has external classpath dependencies "soap", // has external classpath dependencies "basic-xml-interceptor", // has external classpath dependencies + "database", // contains a reference to a DataSource bean (not serializable) "template"); public static List getPorts() { diff --git a/distribution/src/test/java/com/predic8/membrane/examples/env/ConsistentVersionNumbers.java b/distribution/src/test/java/com/predic8/membrane/examples/env/ConsistentVersionNumbers.java index 2925fed67..3c0911dde 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/env/ConsistentVersionNumbers.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/env/ConsistentVersionNumbers.java @@ -66,6 +66,10 @@ public class ConsistentVersionNumbers { public static final Option SNAPSHOT = Option.builder("snapshot").desc("Increase patch version and append SNAPSHOT tag").build(); public static final Option RELEASE = Option.builder("release").desc("Release version").hasArg().argName("x.y.z").build(); + private static final Pattern CONSTANTS_VERSION_PATTERN = Pattern.compile("(\\s*String version = \")(\\d+.\\d+)(\";.*)"); + private static final Pattern RPM_SPEC_VERSION_PATTERN = Pattern.compile("(Version:\\s+)(\\S+)(.*)"); + private static final Pattern HELP_REFERENCE_VERSION_PATTERN = Pattern.compile("(path.replace\\(\"%VERSION%\", \")([^\"]*)(\"\\))"); + @Test public void doit() throws Exception { AtomicReference version = new AtomicReference<>(null); @@ -138,21 +142,18 @@ private static void transformRecursively(File baseDirectory, VersionTransformer } private static void handleConstants(File file, VersionTransformer versionTransformer) throws Exception { - // String version = "5"; // fallback - Pattern versionPattern = Pattern.compile("(\\s*String version = \")(\\d+)(\";.*)"); - handleByRegex(file, versionTransformer, versionPattern, v -> v.getMajor().toString()); + // String version = "5.1"; // fallback + handleByRegex(file, versionTransformer, CONSTANTS_VERSION_PATTERN, v -> "%d.%d".formatted(v.getMajor(), v.getMinor())); } private static void handleRpmSpec(File file, VersionTransformer versionTransformer) throws Exception { // Version: 5.1.0 - Pattern versionPattern = Pattern.compile("(Version:\\s+)(\\S+)(.*)"); - handleByRegex(file, versionTransformer, versionPattern, Semver::getValue); + handleByRegex(file, versionTransformer, RPM_SPEC_VERSION_PATTERN, Semver::getValue); } private static void handleHelpReference(File file, VersionTransformer versionTransformer) throws Exception { // path.replace("%VERSION%", "5.0") - Pattern versionPattern = Pattern.compile("(path.replace\\(\"%VERSION%\", \")([^\"]*)(\"\\))"); - handleByRegex(file, versionTransformer, versionPattern, v -> "%d.%d".formatted(v.getMajor(), v.getMinor())); + handleByRegex(file, versionTransformer, HELP_REFERENCE_VERSION_PATTERN, v -> "%d.%d".formatted(v.getMajor(), v.getMinor())); } private static void handleByRegex(File file, VersionTransformer versionTransformer, Pattern pattern, Function versionFormatter) throws Exception { diff --git a/distribution/src/test/java/com/predic8/membrane/examples/tests/JsonProtectionTest.java b/distribution/src/test/java/com/predic8/membrane/examples/tests/JsonProtectionTest.java index 281a4a6c1..6ca10b60d 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/tests/JsonProtectionTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/tests/JsonProtectionTest.java @@ -39,7 +39,7 @@ public class JsonProtectionTest extends AbstractSampleMembraneStartStopTestcase @Override protected String getExampleDirName() { - return "json-protection"; + return "security/json-protection"; } private final HashMap statusCodeFileMap = new HashMap<>() {{ diff --git a/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2APITest.java b/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2APITest.java index a51bc38b8..c4f43d44c 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2APITest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2APITest.java @@ -52,7 +52,7 @@ void stopMembrane() throws IOException, InterruptedException { void testIt() throws Exception { BufferLogger logger = new BufferLogger(); - try(Process2 ignored = new Process2.Builder().in(getExampleDir("oauth2/api")).withWatcher(logger).script("client").parameters("john password").waitAfterStartFor("200 O").start()) { + try(Process2 ignored = new Process2.Builder().in(getExampleDir("oauth2/api")).withWatcher(logger).script("client").parameters("john password").waitAfterStartFor("success").start()) { assertTrue(logger.contains(""" {"success":"true"} """)); diff --git a/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2CredentialsTest.java b/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2CredentialsTest.java index fd7387e6f..69a690c26 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2CredentialsTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/tests/oauth2/OAuth2CredentialsTest.java @@ -52,7 +52,7 @@ void stopMembrane() throws IOException, InterruptedException { void testIt() throws Exception { BufferLogger logger = new BufferLogger(); - try(Process2 ignored = new Process2.Builder().in(getExampleDir("oauth2/api")).withWatcher(logger).script("client").parameters("john password").waitAfterStartFor("200 O").start()) { + try(Process2 ignored = new Process2.Builder().in(getExampleDir("oauth2/api")).withWatcher(logger).script("client").parameters("john password").waitAfterStartFor("success").start()) { assertTrue(logger.contains(""" {"success":"true"} """)); diff --git a/membrane.spec b/membrane.spec index 3604d8757..f5f254873 100644 --- a/membrane.spec +++ b/membrane.spec @@ -4,7 +4,7 @@ %global logdir %{_var}/log/%{name} Name: membrane -Version: 5.1.19 +Version: 5.1.20-SNAPSHOT Release: 1%{?dist} URL: https://github.com/membrane/service-proxy Summary: Membrane - Open Source API Gateway written in Java for REST APIs, WebSockets, STOMP and legacy Web Services