Make UI REST context path dynamic via server-injected window.__openidm_context_path#154
Merged
vharseko merged 3 commits intocopilot/make-rest-context-path-configurablefrom Apr 9, 2026
Conversation
…ceServlet into index.html Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/855cbe4a-33a7-49bc-88c4-11af25bed6b1 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenIDM/sessions/855cbe4a-33a7-49bc-88c4-11af25bed6b1 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix hardcoded UI context path for REST requests
Make UI REST context path dynamic via server-injected window.__openidm_context_path
Apr 9, 2026
ee9dc32
into
copilot/make-rest-context-path-configurable
14 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constants.jshardcodedcontext = "openidm", breaking the entire UI when the server runs with a custom REST context path (e.g.-Dopenidm.context.path=/myidm). All UI API calls would 404, causing 18 Playwright smoke test failures.Changes
ResourceServlet.java— newhandleIndexHtml()interceptsindex.htmlserving and injects an inline script before</head>with the runtime-configured context path. Escapes<,>,&,",'to prevent XSS. UsesreplaceFirst()to be safe with malformed HTML:Constants.js— reads the injected global with fallback to"openidm"for backward compatibility with older backends:openidm-ui-api/index.html— Swagger UI default URL now useswindow.__openidm_context_pathinstead of hardcoded/openidm/?_api.ConstantsTest.js— adds QUnit tests for thewindow.__openidm_context_pathoverride and fallback behaviour.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
central.sonatype.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenIDM/OpenIDM org.codehaus.plexus.classworlds.launcher.Launcher compile -pl openidm-servlet -am -q(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenIDM/OpenIDM org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip(dns block)maven.alfresco.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenIDM/OpenIDM org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip(dns block)repository.jboss.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenIDM/OpenIDM org.codehaus.plexus.classworlds.launcher.Launcher compile -pl openidm-servlet -am -q(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/OpenIDM/OpenIDM org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip(dns block)www.eclipse.org/opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-dd852eba2a5d9229/dbs/java/working/files-to-index10374774516808572425.list --sourceArchiveDir=/tmp/codeql-scratch-dd852eba2a5d9229/dbs/java/src --outputDir=/tmp/codeql-scratch-dd852eba2a5d9229/dbs/java/trap/java(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Problem
PR #142 made the REST context path configurable via
-Dopenidm.context.path=/myidm, but the UI JavaScript still hardcodescommonConstants.context = "openidm"inConstants.js. When the server runs with a custom context path like/myidm, the UI sends all REST requests to/openidm/*which no longer exists, causing the entire UI to fail to load. This breaks all Playwright smoke tests (18 failures) whenOPENIDM_CONTEXT_PATH=/myidm.Root Cause
Constants.jsatopenidm-ui/openidm-ui-common/src/main/js/org/forgerock/openidm/ui/common/util/Constants.jsline 20:This value is used by all UI delegates to construct REST API URLs like
"/" + Constants.context + "/info/login". When the backend is at/myidm, these requests 404.Additionally, there are a few places in the UI JS that hardcode
"/openidm"directly instead of usingConstants.context.Required Changes
1.
ResourceServlet.java— inject context path intoindex.htmlFile:
openidm-servlet/src/main/java/org/forgerock/openidm/ui/internal/service/ResourceServlet.javaWhen serving
index.html(the entry point for both Admin and Enduser UIs), inject a small inline<script>tag before</head>that setswindow.__openidm_context_pathto the configured context path value (without leading slash). The value comes fromSystem.getProperty(ServerConstants.OPENIDM_CONTEXT_PATH_PROPERTY, ServerConstants.OPENIDM_CONTEXT_PATH_DEFAULT).The injection should look like:
The existing
index.htmlhandling already setsCache-Control: no-cachefor this file (line 133). Replace the normalhandle()call forindex.htmlwith a new method that:/sinceConstants.contextdoesn't use it)</head>with the injection +</head>Import
ServerConstantsfromorg.forgerock.openidm.core.ServerConstants(theopenidm-systemdependency is already available to this module).2.
Constants.js— read injected valueFile:
openidm-ui/openidm-ui-common/src/main/js/org/forgerock/openidm/ui/common/util/Constants.jsChange line 20 from:
to:
This preserves backward compatibility — if the variable is not injected (e.g., running with an older backend), it falls back to
"openidm".3. API Explorer
index.html— fix hardcoded/openidm/?_apiFile:
openidm-ui/openidm-ui-api/src/main/resources/index.htmlChange the default Swagger JSON URL from:
to:
4. Fix remaining hardcoded
"/openidm"in JS delegatesThese files use
"/openidm"directly instead of going throughConstants.context. Fix them:openidm-ui/openidm-ui-common/src/main/js/org/forgerock/openidm/ui/common/delegates/ResourceDelegate.js— in thelinkedViewfunction, change:to:
openidm-ui/openidm-ui-admin/src/main/js/org/forgerock/openidm/ui/admin/mapping/util/MappingUtils.js— indeleteMappingChildren, change:to:
(Make sure
constantsis available in scope — it's already imported as a dependency in this file'sdefine()block.)openidm-ui/openidm-ui-admin/src/main/js/config/validators/AdminValidators.js— find the validation checkv === "/openidm"and change it to useConstants.context:(Make sure
Constantsis in scope — check the define() imports.)5. Update ConstantsTest.js
File:
openidm-ui/openidm-ui-common/src/test/qunit/tests/org/forgerock/openidm/ui/common/util/ConstantsTest.jsAdd a test that verifies the context can be overridden via
window.__openidm_context_path. The test should:window.__openidm_context_path = "myidm"6. No changes needed to
e2e/ui-smoke-test.spec.mjsThe Playwright tests should pass as-is because the UI will now dynamically pick up the correct context path from the injected
window.__openidm_context_path.Important Notes
ServerConstants.OPENIDM_CONTEXT_PATH_PROPERTYandServerConstants.OPENIDM_CONTEXT_PATH_DEFAULTalready exist on the PR bran...This pull request was created from Copilot chat.