SAML 2.0 SP Metadata Endpoint Support
Issue gh-8693
This commit is contained in:
committed by
Josh Cummings
parent
31bae546e2
commit
8a355240bc
+3
@@ -73,6 +73,9 @@ final class FilterComparator implements Comparator<Filter>, Serializable {
|
||||
filterToOrder.put(
|
||||
"org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter",
|
||||
order.next());
|
||||
filterToOrder.put(
|
||||
"org.springframework.security.saml2.provider.service.web.Saml2MetadataFilter",
|
||||
order.next());
|
||||
filterToOrder.put(
|
||||
"org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationRequestFilter",
|
||||
order.next());
|
||||
|
||||
+27
@@ -38,8 +38,11 @@ import org.springframework.security.saml2.provider.service.servlet.filter.Saml2W
|
||||
import org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationRequestFilter;
|
||||
import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver;
|
||||
import org.springframework.security.saml2.provider.service.web.DefaultSaml2AuthenticationRequestContextResolver;
|
||||
import org.springframework.security.saml2.provider.service.web.OpenSamlMetadataResolver;
|
||||
import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestContextResolver;
|
||||
import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter;
|
||||
import org.springframework.security.saml2.provider.service.web.Saml2MetadataFilter;
|
||||
import org.springframework.security.saml2.provider.service.web.Saml2MetadataResolver;
|
||||
import org.springframework.security.web.authentication.AuthenticationConverter;
|
||||
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
||||
import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter;
|
||||
@@ -110,10 +113,15 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>> extend
|
||||
private RelyingPartyRegistrationRepository relyingPartyRegistrationRepository;
|
||||
|
||||
private AuthenticationConverter authenticationConverter;
|
||||
|
||||
private Saml2MetadataResolver saml2MetadataResolver;
|
||||
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
private Saml2WebSsoAuthenticationFilter saml2WebSsoAuthenticationFilter;
|
||||
|
||||
private Saml2MetadataFilter saml2MetadataFilter;
|
||||
|
||||
/**
|
||||
* Use this {@link AuthenticationConverter} when converting incoming requests to an {@link Authentication}.
|
||||
* By default the {@link Saml2AuthenticationTokenConverter} is used.
|
||||
@@ -154,6 +162,16 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>> extend
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@code Saml2MetadataResolver}
|
||||
* @param saml2MetadataResolver the implementation of the metadata resolver
|
||||
* @return the {@link Saml2LoginConfigurer} for further configuration
|
||||
*/
|
||||
public Saml2LoginConfigurer saml2MetadataResolver(Saml2MetadataResolver saml2MetadataResolver) {
|
||||
this.saml2MetadataResolver = saml2MetadataResolver;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -211,6 +229,14 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>> extend
|
||||
setAuthenticationFilter(saml2WebSsoAuthenticationFilter);
|
||||
super.loginProcessingUrl(this.loginProcessingUrl);
|
||||
|
||||
if (this.saml2MetadataResolver == null) {
|
||||
this.saml2MetadataResolver = new OpenSamlMetadataResolver();
|
||||
}
|
||||
|
||||
saml2MetadataFilter = new Saml2MetadataFilter(
|
||||
this.relyingPartyRegistrationRepository, this.saml2MetadataResolver
|
||||
);
|
||||
|
||||
if (hasText(this.loginPage)) {
|
||||
// Set custom login page
|
||||
super.loginPage(this.loginPage);
|
||||
@@ -250,6 +276,7 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>> extend
|
||||
@Override
|
||||
public void configure(B http) throws Exception {
|
||||
http.addFilter(this.authenticationRequestEndpoint.build(http));
|
||||
http.addFilter(saml2MetadataFilter);
|
||||
super.configure(http);
|
||||
if (this.authenticationManager == null) {
|
||||
registerDefaultAuthenticationProvider(http);
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import org.springframework.security.saml2.credentials.Saml2X509Credential
|
||||
import org.springframework.security.saml2.credentials.Saml2X509Credential.Saml2X509CredentialType.VERIFICATION
|
||||
import org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository
|
||||
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration
|
||||
import org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter
|
||||
import org.springframework.security.saml2.provider.service.web.Saml2WebSsoAuthenticationFilter
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.get
|
||||
import java.security.cert.Certificate
|
||||
|
||||
Reference in New Issue
Block a user