Skip to content

Commit 96d7c78

Browse files
committed
Polish Document Defer load CsrfToken
Issue gh-12105
1 parent d860775 commit 96d7c78

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

docs/modules/ROOT/pages/migration.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,60 @@ open fun springSecurity(http: HttpSecurity): SecurityFilterChain {
7171
----
7272
====
7373

74+
If this breaks your application, then you can explicitly opt into the 5.8 defaults using the following configuration:
75+
76+
.Defer Loading `CsrfToken`
77+
====
78+
.Java
79+
[source,java,role="primary"]
80+
----
81+
@Bean
82+
DefaultSecurityFilterChain springSecurity(HttpSecurity http) throws Exception {
83+
CsrfTokenRequestAttributeHandler requestHandler = new CsrfTokenRequestAttributeHandler();
84+
// set the name of the attribute the CsrfToken will be populated on
85+
requestHandler.setCsrfRequestAttributeName(null);
86+
http
87+
// ...
88+
.csrf((csrf) -> csrf
89+
.csrfTokenRequestHandler(requestHandler)
90+
);
91+
return http.build();
92+
}
93+
----
94+
95+
.Kotlin
96+
[source,kotlin,role="secondary"]
97+
----
98+
@Bean
99+
open fun springSecurity(http: HttpSecurity): SecurityFilterChain {
100+
val requestHandler = CsrfTokenRequestAttributeHandler()
101+
// set the name of the attribute the CsrfToken will be populated on
102+
requestHandler.setCsrfRequestAttributeName(null)
103+
http {
104+
csrf {
105+
csrfTokenRequestHandler = requestHandler
106+
}
107+
}
108+
return http.build()
109+
}
110+
----
111+
112+
.XML
113+
[source,xml,role="secondary"]
114+
----
115+
<http>
116+
<!-- ... -->
117+
<csrf request-handler-ref="requestHandler"/>
118+
</http>
119+
<b:bean id="requestHandler"
120+
class="org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler">
121+
<b:property name="csrfRequestAttributeName">
122+
<b:null/>
123+
</b:property>
124+
</b:bean>
125+
----
126+
====
127+
74128
=== Explicit Save SecurityContextRepository
75129

76130
In Spring Security 5, the default behavior is for the xref:servlet/authentication/architecture.adoc#servlet-authentication-securitycontext[`SecurityContext`] to automatically be saved to the xref:servlet/authentication/persistence.adoc#securitycontextrepository[`SecurityContextRepository`] using the xref:servlet/authentication/persistence.adoc#securitycontextpersistencefilter[`SecurityContextPersistenceFilter`].

0 commit comments

Comments
 (0)