From 7cab573f3d862a998cb64fec33718ff2817983cb Mon Sep 17 00:00:00 2001 From: Garth <244253+xgp@users.noreply.github.com> Date: Mon, 11 Dec 2023 20:53:00 +0100 Subject: [PATCH] added fix for jax-rs regex paths no longer working (#118) --- .../portal/PortalResourceProvider.java | 42 +++++++++++++++++++ pom.xml | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ext/main/java/io/phasetwo/portal/PortalResourceProvider.java b/ext/main/java/io/phasetwo/portal/PortalResourceProvider.java index f31d2d5..a5c5607 100644 --- a/ext/main/java/io/phasetwo/portal/PortalResourceProvider.java +++ b/ext/main/java/io/phasetwo/portal/PortalResourceProvider.java @@ -20,6 +20,7 @@ import java.util.Optional; import java.util.Properties; import java.util.function.Function; +import java.util.regex.Pattern; import java.util.stream.Collectors; import lombok.extern.jbosslog.JBossLog; import org.keycloak.forms.login.LoginFormsProvider; @@ -100,6 +101,47 @@ public Response preflight() { return Cors.add(request, Response.ok()).auth().allowedMethods(METHODS).preflight().build(); } + /** + * something is seriously wrong since resteasy reactive upgrade. catch-all and regex paths no + * longer work from annotations. This is a hack to get v23 working in the meantime. + */ + @GET + @Path("{path:.+}") + public Response router(@PathParam("path") String path) throws Exception { + UriInfo uriInfo = session.getContext().getUri(); + log.debugf("param path %s", path); + log.debugf("absolutePath %s", uriInfo.getAbsolutePath()); + log.debugf("path %s", uriInfo.getPath()); + log.debugf("baseUri %s", uriInfo.getBaseUri()); + log.debugf("segments %s", uriInfo.getPathSegments()); + log.debugf("requestUri %s", uriInfo.getRequestUri()); + + if (path == null || "".equals(path) || "/".equals(path)) return portal(); + if (path.startsWith("/")) { + path = path.substring(1); + } + + // staticResources + if (Pattern.matches("^(asset-manifest|logo|manifest|static|locales|favicon).*", path)) { + Response response = staticResources(path); + if (response != null) { + log.debugf("returning response %d for path %s", response.getStatus(), path); + return response; + } + } + + // forward + if (Pattern.matches("^(profile|organizations).*", path)) { + Response response = forward(); + if (response != null) { + log.debugf("forwarding response %d for path %s", response.getStatus(), path); + return response; + } + } + + return portal(); + } + @GET @Path("{path: ^(profile|organizations).*}") @Produces(MediaType.TEXT_HTML) diff --git a/pom.xml b/pom.xml index e3591c7..e70d66a 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ com.github.eirslett frontend-maven-plugin - 1.14.2 + 1.15.0 setup-node-and-yarn