-
Couldn't load subscription status.
- Fork 6.2k
Simplify OIDC Back-Channel Logout DSL (Closes gh-15817) #16698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,18 +16,8 @@ | |
|
|
||
| package org.springframework.security.config.annotation.web.builders; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import jakarta.servlet.Filter; | ||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.ServletRequest; | ||
| import jakarta.servlet.ServletResponse; | ||
| import jakarta.servlet.*; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
|
|
||
| import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
| import org.springframework.beans.factory.ObjectProvider; | ||
| import org.springframework.context.ApplicationContext; | ||
|
|
@@ -48,29 +38,8 @@ | |
| import org.springframework.security.config.annotation.web.RequestMatcherFactory; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration; | ||
| import org.springframework.security.config.annotation.web.configurers.AnonymousConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.*; | ||
| import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer.AuthorizationManagerRequestMatcherRegistry; | ||
| import org.springframework.security.config.annotation.web.configurers.ChannelSecurityConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.CorsConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.FormLoginConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.HttpsRedirectConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.JeeConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.PasswordManagementConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.PortMapperConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.RememberMeConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.RequestCacheConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.SecurityContextConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.ServletApiConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.SessionManagementConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.WebAuthnConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.X509Configurer; | ||
| import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2ClientConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer; | ||
| import org.springframework.security.config.annotation.web.configurers.oauth2.client.OidcLogoutConfigurer; | ||
|
|
@@ -103,6 +72,11 @@ | |
| import org.springframework.web.filter.CorsFilter; | ||
| import org.springframework.web.servlet.handler.HandlerMappingIntrospector; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * A {@link HttpSecurity} is similar to Spring Security's XML <http> element in the | ||
| * namespace configuration. It allows configuring web based security for specific http | ||
|
|
@@ -2870,6 +2844,14 @@ public HttpSecurity oidcLogout(Customizer<OidcLogoutConfigurer<HttpSecurity>> oi | |
| return HttpSecurity.this; | ||
| } | ||
|
|
||
| public HttpSecurity oidcBackChannelLogout(Customizer<OidcLogoutConfigurer<HttpSecurity>> oidcBackChannelLogoutCustomizer) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add JavaDoc so folks can read how to use the method. Please make sure the JavaDoc includes |
||
| throws Exception { | ||
| oidcBackChannelLogoutCustomizer.customize( | ||
| getOrApply(new OidcLogoutConfigurer<>()).backChannel(Customizer.withDefaults()) | ||
| ); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures OAuth 2.0 Client support. | ||
| * @return the {@link OAuth2ClientConfigurer} for further customizations | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,8 @@ | |
|
|
||
| package org.springframework.security.config.annotation.web.configurers.oauth2.client; | ||
|
|
||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
|
|
||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.security.authentication.AuthenticationManager; | ||
| import org.springframework.security.authentication.ProviderManager; | ||
|
|
@@ -40,6 +36,9 @@ | |
| import org.springframework.security.web.csrf.CsrfFilter; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * An {@link AbstractHttpConfigurer} for OIDC Logout flows | ||
| * | ||
|
|
@@ -102,7 +101,10 @@ public OidcLogoutConfigurer<B> oidcSessionRegistry(OidcSessionRegistry oidcSessi | |
| /** | ||
| * Configure OIDC Back-Channel Logout using the provided {@link Consumer} | ||
| * @return the {@link OidcLogoutConfigurer} for further configuration | ||
| * @deprecated For removal in a future release. Use | ||
| * {@link HttpSecurity#oidcBackChannelLogout(Customizer)} instead. | ||
| */ | ||
| @Deprecated(since = "6.2", forRemoval = true) | ||
|
||
| public OidcLogoutConfigurer<B> backChannel(Customizer<BackChannelLogoutConfigurer> backChannelLogoutConfigurer) { | ||
| if (this.backChannel == null) { | ||
| this.backChannel = new BackChannelLogoutConfigurer(); | ||
|
|
@@ -157,35 +159,6 @@ private LogoutHandler logoutHandler(B http) { | |
| return logoutHandler; | ||
| } | ||
|
|
||
| /** | ||
| * Use this endpoint when invoking a back-channel logout. | ||
| * | ||
| * <p> | ||
| * The resulting {@link LogoutHandler} will {@code POST} the session cookie and | ||
| * CSRF token to this endpoint to invalidate the corresponding end-user session. | ||
| * | ||
| * <p> | ||
| * Supports URI templates like {@code {baseUrl}}, {@code {baseScheme}}, and | ||
| * {@code {basePort}}. | ||
| * | ||
| * <p> | ||
| * By default, the URI is set to | ||
| * {@code {baseScheme}://localhost{basePort}/logout}, meaning that the scheme and | ||
| * port of the original back-channel request is preserved, while the host and | ||
| * endpoint are changed. | ||
| * | ||
| * <p> | ||
| * If you are using Spring Security for the logout endpoint, the path part of this | ||
| * URI should match the value configured there. | ||
| * | ||
| * <p> | ||
| * Otherwise, this is handy in the event that your server configuration means that | ||
| * the scheme, server name, or port in the {@code Host} header are different from | ||
| * how you would address the same server internally. | ||
| * @param logoutUri the URI to request logout on the back-channel | ||
| * @return the {@link BackChannelLogoutConfigurer} for further customizations | ||
| * @since 6.2.4 | ||
| */ | ||
| public BackChannelLogoutConfigurer logoutUri(String logoutUri) { | ||
| this.logoutHandler = (http) -> { | ||
| OidcBackChannelLogoutHandler logoutHandler = new OidcBackChannelLogoutHandler( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave the import statements as-is.