fix(sso): join the Entra ID authority and tenant with a single separator - #3259
Open
marevol wants to merge 1 commit into
Open
fix(sso): join the Entra ID authority and tenant with a single separator#3259marevol wants to merge 1 commit into
marevol wants to merge 1 commit into
Conversation
getAuthority() returns the configured entraid.authority / aad.authority verbatim, and its only guard maps a blank value onto DEFAULT_AUTHORITY, which already carries a trailing slash. A non-blank value without one was concatenated straight onto the tenant, so entraid.authority=https://login.microsoftonline.com entraid.tenant=contoso.onmicrosoft.com produced https://login.microsoftonline.comcontoso.onmicrosoft.com/oauth2/v2.0/authorize The host and the tenant fuse into one hostname, the browser gets NXDOMAIN, and the authorization URL is only logged at debug level, so nothing points at the setting. https://login.microsoftonline.com is how the endpoint is written wherever it is documented, so omitting the trailing slash is the expected mistake rather than an exotic one. Add getTenantAuthority(), which joins the two with exactly one slash, and route getAuthUrl, getClientApplication, buildClientApplicationKey and the two debug-log authorities through it. A tenant that already starts with a slash joins correctly against a slashless authority today, so a separator is inserted only when neither side supplies one and a doubled separator is collapsed; a blank tenant gets no separator, because every caller appends its own slash afterwards. getAuthority() itself is unchanged, and so is the shape of the authority handed to msal4j. Tests cover all four authority/tenant slash combinations, a blank tenant and the casing, and pin the full authorization URL for the fixed case.
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.
Problem
getAuthority()returns the configuredentraid.authority/aad.authorityverbatim. Its only guard maps a blank value ontoDEFAULT_AUTHORITY, which already carries a trailing slash — a non-blank value without one was passed through untouched and concatenated straight onto the tenant:getAuthUrl—getAuthority() + getTenant() + "/oauth2/v2.0/authorize?..."getClientApplication/buildClientApplicationKey—getAuthority() + getTenant() + "/"So with
the authorization URL became
The host and the tenant fuse into a single bogus hostname. The browser gets NXDOMAIN, and because the URL is only logged at debug level nothing points back at the setting.
https://login.microsoftonline.comis how the endpoint is written wherever it is documented, so omitting the trailing slash is the expected mistake rather than an exotic one.This is pre-existing and reproduces on 15.7.x as well; it is not a 15.8 regression.
Fix
Add
getTenantAuthority(), which joins the authority and the tenant with exactly one/, and routegetAuthUrl,getClientApplication,buildClientApplicationKey()and the two debug-log authorities ingetAccessTokenthrough it.getAuthority()itself is deliberately unchanged: it is a documented getter whose value also feedsbuildClientApplicationKey.Normalisation rules:
///inserted — the bug/A tenant that already starts with a slash joins correctly against a slashless authority today, so a naive "always append a slash to the authority" fix would break a working configuration. A blank tenant gets no separator at all, because every caller appends its own
/afterwards and inserting one here would turn today's output into a doubled slash.Nothing is lowercased or trimmed, and the shape of the authority handed to msal4j is unchanged — it still receives at least one path segment, which
Authority.detectAuthorityTyperequires.The msal4j side was already loud about this (it throws
IllegalArgumentException, which becomes anSsoLoginException); it is the browser redirect that failed silently. That path is untouched.Tests
The authenticator test class gains seven cases: all four authority/tenant slash combinations, a blank tenant against both authority shapes, a casing guard, and one that pins the full authorization URL for the fixed case so the regression is caught end to end.
Every new test was mutation-checked against two reverts:
getAuthority() + getTenant()) — 4 fail, including the full-URL test, which reports the fusedlogin.microsoftonline.comcontoso.onmicrosoft.com./to the authority) — the other 3 fail, confirming the "already correct today" cases are live guards and not tautologies.mvn clean test -Dtest='org.codelibs.fess.sso.**'→ Tests run: 250, Failures: 0, Errors: 0, Skipped: 0.mvn clean javadoc:jar→ BUILD SUCCESS.