ForceEagerSessionCreationFilter

Closes gh-11109
This commit is contained in:
Rob Winch
2022-04-15 10:35:14 -05:00
parent 9601efd341
commit 9a9a43a0c0
14 changed files with 152 additions and 2 deletions

View File

@@ -167,6 +167,7 @@ However, there are times that it is beneficial to know the ordering.
The following is a comprehensive list of Spring Security Filter ordering:
* xref:servlet/authentication/session-management.adoc#session-mgmt-force-session-creation[`ForceEagerSessionCreationFilter`]
* `ChannelProcessingFilter`
* `WebAsyncManagerIntegrationFilter`
* `SecurityContextPersistenceFilter`

View File

@@ -3,6 +3,35 @@
HTTP session-related functionality is handled by a combination of the {security-api-url}org/springframework/security/authentication/AuthenticationProvider.html[`SessionManagementFilter`] and the {security-api-url}org/springframework/security/web/authentication/session/SessionAuthenticationStrategy.html[`SessionAuthenticationStrategy`] interface, to which the filter delegates.
Typical usage includes session-fixation protection attack prevention, detection of session timeouts, and restrictions on how many sessions an authenticated user may have open concurrently.
[[session-mgmt-force-session-creation]]
== Force Eager Session Creation
At times it can be valuable to eagerly create sessions.
This can be done by using the {security-api-url}org/springframework/security/web/session/ForceEagerSessionCreationFilter.html[`ForceEagerSessionCreationFilter`] which can be configured using:
====
.Java
[source,java,role="primary"]
----
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) {
http
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
);
return http.build();
}
----
.XML
[source,xml,role="secondary"]
----
<http create-session="ALWAYS">
</http>
----
====
== Detecting Timeouts
You can configure Spring Security to detect the submission of an invalid session ID and redirect the user to an appropriate URL.
To do so, configure the `session-management` element:

View File

@@ -274,6 +274,10 @@ The filters, aliases, and namespace elements and attributes that create the filt
| `DisableEncodeUrlFilter`
| `http@disable-url-rewriting`
| FORCE_EAGER_SESSION_FILTER
| `ForceEagerSessionCreationFilter`
| `http@create-session="ALWAYS"`
| CHANNEL_FILTER
| `ChannelProcessingFilter`
| `http/intercept-url@requires-channel`