@@ -23,12 +23,10 @@ You can easily do this with the following Java Configuration:
23
23
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
24
24
http
25
25
// ...
26
- .headers(headers ->
27
- headers
28
- .frameOptions(frameOptions ->
29
- frameOptions
30
- .mode(Mode.SAMEORIGIN)
31
- )
26
+ .headers(headers -> headers
27
+ .frameOptions(frameOptions -> frameOptions
28
+ .mode(Mode.SAMEORIGIN)
29
+ )
32
30
);
33
31
return http.build();
34
32
}
@@ -46,10 +44,7 @@ An example for both Java configuration is provided below:
46
44
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
47
45
http
48
46
// ...
49
- .headers(headers ->
50
- headers
51
- .disable()
52
- );
47
+ .headers(headers -> headers.disable());
53
48
return http.build();
54
49
}
55
50
----
@@ -76,9 +71,8 @@ If necessary, you can also disable Spring Security's cache control HTTP response
76
71
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
77
72
http
78
73
// ...
79
- .headers(headers ->
80
- headers
81
- .cache(cache -> cache.disable())
74
+ .headers(headers -> headers
75
+ .cache(cache -> cache.disable())
82
76
);
83
77
return http.build();
84
78
}
@@ -99,9 +93,8 @@ However, you can disable it in Java Configuration with:
99
93
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
100
94
http
101
95
// ...
102
- .headers(headers ->
103
- headers
104
- .contentTypeOptions(contentTypeOptions -> contentTypeOptions.disable())
96
+ .headers(headers -> headers
97
+ .contentTypeOptions(contentTypeOptions -> contentTypeOptions.disable())
105
98
);
106
99
return http.build();
107
100
}
@@ -122,14 +115,12 @@ For example, the following is an example of explicitly providing HSTS with Java
122
115
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
123
116
http
124
117
// ...
125
- .headers(headers ->
126
- headers
127
- .hsts(hsts ->
128
- hsts
129
- .includeSubdomains(true)
130
- .preload(true)
131
- .maxAge(Duration.ofDays(365))
132
- )
118
+ .headers(headers -> headers
119
+ .hsts(hsts -> hsts
120
+ .includeSubdomains(true)
121
+ .preload(true)
122
+ .maxAge(Duration.ofDays(365))
123
+ )
133
124
);
134
125
return http.build();
135
126
}
@@ -150,12 +141,10 @@ You can customize frame options to use the same origin within Java Configuration
150
141
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
151
142
http
152
143
// ...
153
- .headers(headers ->
154
- headers
155
- .frameOptions(frameOptions ->
156
- frameOptions
157
- .mode(SAMEORIGIN)
158
- )
144
+ .headers(headers -> headers
145
+ .frameOptions(frameOptions -> frameOptions
146
+ .mode(SAMEORIGIN)
147
+ )
159
148
);
160
149
return http.build();
161
150
}
@@ -175,9 +164,8 @@ You can disable `X-XSS-Protection` with the following Java Configuration:
175
164
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
176
165
http
177
166
// ...
178
- .headers(headers ->
179
- headers
180
- .xssProtection(xssProtection -> xssProtection.disable())
167
+ .headers(headers -> headers
168
+ .xssProtection(xssProtection -> xssProtection.disable())
181
169
);
182
170
return http.build();
183
171
}
@@ -209,12 +197,10 @@ You can enable the CSP header using Java configuration as shown below:
209
197
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
210
198
http
211
199
// ...
212
- .headers(headers ->
213
- headers
214
- .contentSecurityPolicy(contentSecurityPolicy ->
215
- contentSecurityPolicy
216
- .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
217
- )
200
+ .headers(headers -> headers
201
+ .contentSecurityPolicy(policy -> policy
202
+ .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
203
+ )
218
204
);
219
205
return http.build();
220
206
}
@@ -231,13 +217,11 @@ To enable the CSP `report-only` header, provide the following Java configuration
231
217
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
232
218
http
233
219
// ...
234
- .headers(headers ->
235
- headers
236
- .contentSecurityPolicy(contentSecurityPolicy ->
237
- contentSecurityPolicy
238
- .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
239
- .reportOnly()
240
- )
220
+ .headers(headers -> headers
221
+ .contentSecurityPolicy(policy -> policy
222
+ .policyDirectives("script-src 'self' https://trustedscripts.example.com; object-src https://trustedplugins.example.com; report-uri /csp-report-endpoint/")
223
+ .reportOnly()
224
+ )
241
225
);
242
226
return http.build();
243
227
}
@@ -258,12 +242,10 @@ You can enable the Referrer Policy header using Java configuration as shown belo
258
242
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
259
243
http
260
244
// ...
261
- .headers(headers ->
262
- headers
263
- .referrerPolicy(referrerPolicy ->
264
- referrerPolicy
265
- .policy(ReferrerPolicy.SAME_ORIGIN)
266
- )
245
+ .headers(headers -> headers
246
+ .referrerPolicy(referrer -> referrer
247
+ .policy(ReferrerPolicy.SAME_ORIGIN)
248
+ )
267
249
);
268
250
return http.build();
269
251
}
@@ -295,9 +277,8 @@ can enable the Feature Policy header using Java configuration as shown below:
295
277
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
296
278
http
297
279
// ...
298
- .headers(headers ->
299
- headers
300
- .featurePolicy("geolocation 'self'")
280
+ .headers(headers -> headers
281
+ .featurePolicy("geolocation 'self'")
301
282
);
302
283
return http.build();
303
284
}
0 commit comments