Description
Describe the bug
Methods such as RelyingPartyRegistrations.collectionFromMetadataLocation
use the entity
of the asserting party as the registrationId
.
SAML entity IDs are usually URIs (and often a URL to their metadata), and Spring's SAML support (incl. the default login page) requires the registrationId
to be added to a URL.
This typically results in an error when trying to access e.g. https://relyingparty.com/saml2/authenticate/https://assertingparty.com/SAML/metadata.xml
To Reproduce
Construct a RelyingPartyRegistrationRepository
using RelyingPartyRegistrations
without changing the default registrationId
.
Expected behavior
registrationId
should always be generated as URL-safe, or should always be escaped when used in a URL.
Workaround
List<RelyingPartyRegistration> registrations = RelyingPartyRegistrations.collectionFromMetadataLocation(url)
.stream()
.map(builder -> builder
.entityId("https://relyingparty.com/saml-metadata.xml")
// etc.
.build())
.map(reg -> reg.mutate()
.registrationId(reg.getAssertingPartyDetails().getEntityId().replaceAll("[:/?#]+", "_"))
.build())
.toList();
Caveat
Using URLEncoder.encode
to make it safe is not sufficient, as you still get a 400 Bad Request from a default Spring Boot server.