-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Open
alswp006
wants to merge
2
commits into
spring-projects:main
Choose a base branch
from
alswp006:gh-15817
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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 | ||
|
This file contains 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
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) | ||
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 change the since value to |
||
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( | ||
|
This file contains 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
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.
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.