2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[[servlet-saml2login-metadata]]
							 
						 
					
						
							
								
									
										
										
										
											2023-02-15 17:53:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								= Saml 2.0 Metadata
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Spring Security can <<parsing-asserting-party-metadata,parse asserting party metadata>> to produce an `AssertingPartyDetails` instance as well as <<publishing-relying-party-metadata,publish relying party metadata>> from a `RelyingPartyRegistration` instance.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[[parsing-asserting-party-metadata]]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								== Parsing `<saml2:IDPSSODescriptor>` metadata
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You can parse an asserting party's metadata xref:servlet/saml2/login/overview.adoc#servlet-saml2login-relyingpartyregistrationrepository[using `RelyingPartyRegistrations`].
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								When using the OpenSAML vendor support, the resulting `AssertingPartyDetails` will be of type `OpenSamlAssertingPartyDetails`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This means you'll be able to do get the underlying OpenSAML XMLObject by doing the following:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2023-02-15 17:53:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								OpenSamlAssertingPartyDetails details = (OpenSamlAssertingPartyDetails)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        registration.getAssertingPartyDetails();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								EntityDescriptor openSamlEntityDescriptor = details.getEntityDescriptor();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Kotlin::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2023-02-15 17:53:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val details: OpenSamlAssertingPartyDetails =
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        registration.getAssertingPartyDetails() as OpenSamlAssertingPartyDetails;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val openSamlEntityDescriptor: EntityDescriptor = details.getEntityDescriptor();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2023-02-15 17:53:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								[[publishing-relying-party-metadata]]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								== Producing `<saml2:SPSSODescriptor>` Metadata
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You can publish a metadata endpoint by adding the `Saml2MetadataFilter` to the filter chain, as you'll see below:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								DefaultRelyingPartyRegistrationResolver relyingPartyRegistrationResolver =
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        new DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Saml2MetadataFilter filter = new Saml2MetadataFilter(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        relyingPartyRegistrationResolver,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        new OpenSamlMetadataResolver());
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								http
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    .saml2Login(withDefaults())
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    .addFilterBefore(filter, Saml2WebSsoAuthenticationFilter.class);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Kotlin::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val relyingPartyRegistrationResolver: Converter<HttpServletRequest, RelyingPartyRegistration> =
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val filter = Saml2MetadataFilter(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    relyingPartyRegistrationResolver,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    OpenSamlMetadataResolver()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								http {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    //...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    saml2Login { }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    addFilterBefore<Saml2WebSsoAuthenticationFilter>(filter)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You can use this metadata endpoint to register your relying party with your asserting party.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								This is often as simple as finding the correct form field to supply the metadata endpoint.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								By default, the metadata endpoint is `+/saml2/service-provider-metadata/{registrationId}+`.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You can change this by calling the `setRequestMatcher` method on the filter:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Kotlin::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Or, if you have registered a custom relying party registration resolver in the constructor, then you can specify a path without a `registrationId` hint, like so:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata", "GET"));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Kotlin::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2021-10-29 11:29:35 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								[source,kotlin,role="secondary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata", "GET"))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:30:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 12:35:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								== Changing the Way a `RelyingPartyRegistration` Is Looked Up
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								To apply a custom `RelyingPartyRegistrationResolver` to the metadata endpoint, you can provide it directly in the filter constructor like so:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 12:35:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								RelyingPartyRegistrationResolver myRegistrationResolver = ...;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Saml2MetadataFilter metadata = new Saml2MetadataFilter(myRegistrationResolver, new OpenSamlMetadataResolver());
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								http.addFilterBefore(metadata, BasicAuthenticationFilter.class);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 12:35:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val myRegistrationResolver: RelyingPartyRegistrationResolver = ...;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								val metadata = new Saml2MetadataFilter(myRegistrationResolver, OpenSamlMetadataResolver());
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// ...
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								http.addFilterBefore(metadata, BasicAuthenticationFilter::class.java);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								In the event that you are applying a `RelyingPartyRegistrationResolver` to remove the `registrationId` from the URI, you must also change the URI in the filter like so:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[tabs]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Java::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								+
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 12:35:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[source,java,role="primary"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								metadata.setRequestMatcher("/saml2/metadata")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
									
										
										
										
											2023-06-18 21:31:35 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								======
							 
						 
					
						
							
								
									
										
										
										
											2023-02-28 12:35:04 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								.Kotlin
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								metadata.setRequestMatcher("/saml2/metadata")
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								----