fix(sso): serve the SAML SP metadata before the IdP is configured - #3240
Merged
Conversation
`/sso/metadata` publishes the SP metadata that the IdP is registered from, so it
has to be reachable before any `saml.idp.*` property exists. It was not:
final Auth auth = new Auth(getSettings(), request, response);
final Saml2Settings settings = auth.getSettings();
settings.setSPValidationOnly(true);
The `Auth` constructor calls `checkSettings()`, and `spValidationOnly` is still
false at that point, so `checkIdPSettings()` runs and throws. Setting the flag on
the returned settings afterwards is too late -- nothing calls `checkSettings()`
again. With only `sso.type` and `saml.sp.base.url` set, the endpoint fails with:
Invalid settings: idp_entityId_not_found, idp_sso_url_invalid,
idp_cert_or_fingerprint_not_found_and_required
leaving no way to obtain the metadata without first supplying the values the
metadata is meant to help configure.
`Auth` is not needed here at all -- `getSPMetadata()` is a `Saml2Settings`
method. The settings are now built directly, `setSPValidationOnly(true)` is
applied before validation, and `checkSettings()` is called explicitly so invalid
SP settings are still reported rather than silently producing broken metadata.
Also corrects the "Failed to log out." text on the metadata validation error,
which was copied from the logout path.
Tests: 2 added to SamlAuthenticatorTest. The first fails before this change
(SsoMessageException instead of the metadata document); the second pins that SP
settings are still validated.
marevol
force-pushed
the
fix/saml-metadata-without-idp
branch
from
August 10, 2026 23:43
7049f4a to
1f49a81
Compare
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
/sso/metadatapublishes the SP metadata that the IdP is registered from, so it has to be reachable before anysaml.idp.*property exists. It was not:The
Authconstructor callssettings.checkSettings(), andspValidationOnlyis stillfalseat that point, socheckIdPSettings()runs and the constructor throwsSettingsException. Setting the flag on the returned settings afterwards is too late — nothing callscheckSettings()again.With only
sso.type=samlandsaml.sp.base.urlset — which is exactly what the documentation says is needed to fetch the metadata — the endpoint fails:leaving no way to obtain the metadata without first supplying the values the metadata is meant to help configure.
Fix
Authis not needed here at all —getSPMetadata()is aSaml2Settingsmethod, and neither the request nor the response is used. The settings are now built directly,setSPValidationOnly(true)is applied before validation, andcheckSettings()is called explicitly so invalid SP settings are still reported rather than silently producing broken metadata.With the flag set first, the same configuration produces valid metadata:
Also corrects the
"Failed to log out."text on the metadata validation error, which was copied from the logout path.Tests
2 added to
SamlAuthenticatorTest:test_getMetadataResponse_withoutIdpSettings— with onlysaml.sp.base.urlset, aStreamResponseformetadata.xmlis returned. Fails before this change withSsoMessageException: Failed to process metadata.test_getMetadataResponse_reportsInvalidSpSettings— an unusable ACS URL is still reported assp_acs_not_found, pinning that droppingAuthdid not drop SP validationIndependent of #3239, which touches
getLoginCredential()in the same class; the two do not overlap.