|
@@ -58,6 +58,7 @@ import org.springframework.security.authorization.AuthorizationDecision;
|
|
|
import org.springframework.security.authorization.ObservationReactiveAuthorizationManager;
|
|
|
import org.springframework.security.authorization.ReactiveAuthorizationManager;
|
|
|
import org.springframework.security.config.Customizer;
|
|
|
+import org.springframework.security.config.annotation.web.configurers.oauth2.client.OidcLogoutConfigurer;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
@@ -110,6 +111,7 @@ import org.springframework.security.oauth2.server.resource.web.access.server.Bea
|
|
|
import org.springframework.security.oauth2.server.resource.web.server.BearerTokenServerAuthenticationEntryPoint;
|
|
|
import org.springframework.security.oauth2.server.resource.web.server.authentication.ServerBearerTokenAuthenticationConverter;
|
|
|
import org.springframework.security.web.PortMapper;
|
|
|
+import org.springframework.security.web.authentication.logout.LogoutHandler;
|
|
|
import org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor;
|
|
|
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
|
|
|
import org.springframework.security.web.server.DefaultServerRedirectStrategy;
|
|
@@ -5074,7 +5076,7 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private final ReactiveAuthenticationManager authenticationManager = new OidcBackChannelLogoutReactiveAuthenticationManager();
|
|
|
|
|
|
- private ServerLogoutHandler logoutHandler;
|
|
|
+ private Supplier<ServerLogoutHandler> logoutHandler = this::logoutHandler;
|
|
|
|
|
|
private ServerAuthenticationConverter authenticationConverter() {
|
|
|
if (this.authenticationConverter == null) {
|
|
@@ -5089,18 +5091,56 @@ public class ServerHttpSecurity {
|
|
|
}
|
|
|
|
|
|
private ServerLogoutHandler logoutHandler() {
|
|
|
- if (this.logoutHandler == null) {
|
|
|
+ OidcBackChannelServerLogoutHandler logoutHandler = new OidcBackChannelServerLogoutHandler();
|
|
|
+ logoutHandler.setSessionRegistry(OidcLogoutSpec.this.getSessionRegistry());
|
|
|
+ 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 OidcLogoutConfigurer.BackChannelLogoutConfigurer} for
|
|
|
+ * further customizations
|
|
|
+ * @since 6.2.4
|
|
|
+ */
|
|
|
+ public BackChannelLogoutConfigurer logoutUri(String logoutUri) {
|
|
|
+ this.logoutHandler = () -> {
|
|
|
OidcBackChannelServerLogoutHandler logoutHandler = new OidcBackChannelServerLogoutHandler();
|
|
|
logoutHandler.setSessionRegistry(OidcLogoutSpec.this.getSessionRegistry());
|
|
|
- this.logoutHandler = logoutHandler;
|
|
|
- }
|
|
|
- return this.logoutHandler;
|
|
|
+ logoutHandler.setLogoutUri(logoutUri);
|
|
|
+ return logoutHandler;
|
|
|
+ };
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
void configure(ServerHttpSecurity http) {
|
|
|
OidcBackChannelLogoutWebFilter filter = new OidcBackChannelLogoutWebFilter(authenticationConverter(),
|
|
|
authenticationManager());
|
|
|
- filter.setLogoutHandler(logoutHandler());
|
|
|
+ filter.setLogoutHandler(this.logoutHandler.get());
|
|
|
http.addFilterBefore(filter, SecurityWebFiltersOrder.CSRF);
|
|
|
}
|
|
|
|