Skip to content

Commit 6335caa

Browse files
therepanicjzheaux
authored andcommitted
polish
Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
1 parent c3e0b98 commit 6335caa

File tree

7 files changed

+97
-36
lines changed

7 files changed

+97
-36
lines changed

docs/modules/ROOT/pages/servlet/architecture.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ The previous description already gives us a clue on where to add the filter, sin
248248

249249
Based on the rule of thumb, you can add it before xref:servlet/authentication/logout.adoc[`LogoutFilter`], like so:
250250

251-
include-code::./SecurityConfig[tag=snippet-before,indent=0]
251+
include-code::./SecurityConfigBefore[tag=snippet,indent=0]
252252

253253
<1> Use `HttpSecurity#addFilterBefore` to add the `TenantFilter` before the `LogoutFilter`.
254254

255255
Or after xref:servlet/authentication/anonymous.adoc[`AnonymousAuthenticationFilter`], the last authentication filter in the chain, like so:
256256

257-
include-code::./SecurityConfig[tag=snippet-after,indent=0]
257+
include-code::./SecurityConfigAfter[tag=snippet,indent=0]
258258

259259
<1> Use `HttpSecurity#addFilterAfter` to add the `TenantFilter` after the `AnonymousAuthenticationFilter`.
260260

docs/src/test/java/org/springframework/security/docs/servlet/addingcustomfilter/CustomFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
@ContextConfiguration(classes = {
4848
CustomFilterTests.UserDetailsConfig.class,
4949
CustomFilterTests.ApiController.class,
50-
SecurityConfig.class })
50+
SecurityConfigBefore.class })
5151
@WebAppConfiguration
5252
public class CustomFilterTests {
5353

docs/src/test/java/org/springframework/security/docs/servlet/addingcustomfilter/SecurityConfig.java renamed to docs/src/test/java/org/springframework/security/docs/servlet/addingcustomfilter/SecurityConfigAfter.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,21 @@
2222
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
2323
import org.springframework.security.web.SecurityFilterChain;
2424
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
25-
import org.springframework.security.web.authentication.logout.LogoutFilter;
2625
import org.springframework.test.context.ContextConfiguration;
2726

2827
@Configuration
29-
@ContextConfiguration(classes = { SecurityConfig.class })
28+
@ContextConfiguration(classes = { SecurityConfigAfter.class })
3029
@EnableWebSecurity
31-
public class SecurityConfig {
30+
public class SecurityConfigAfter {
3231

33-
// tag::snippet-before[]
32+
// tag::snippet[]
3433
@Bean
35-
public SecurityFilterChain filterChainBefore(HttpSecurity http) throws Exception {
36-
http
37-
// ...
38-
.addFilterBefore(new TenantFilter(), LogoutFilter.class); // <1>
39-
return http.build();
40-
}
41-
// end::snippet-before[]
42-
43-
// tag::snippet-after[]
44-
@Bean
45-
public SecurityFilterChain filterChainAfter(HttpSecurity http) throws Exception {
34+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
4635
http
4736
// ...
4837
.addFilterAfter(new TenantFilter(), AnonymousAuthenticationFilter.class); // <1>
4938
return http.build();
5039
}
51-
// end::snippet-after[]
40+
// end::snippet[]
5241

5342
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.docs.servlet.addingcustomfilter;
18+
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
22+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
23+
import org.springframework.security.web.SecurityFilterChain;
24+
import org.springframework.security.web.authentication.logout.LogoutFilter;
25+
import org.springframework.test.context.ContextConfiguration;
26+
27+
@Configuration
28+
@ContextConfiguration(classes = { SecurityConfigBefore.class })
29+
@EnableWebSecurity
30+
public class SecurityConfigBefore {
31+
32+
// tag::snippet[]
33+
@Bean
34+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
35+
http
36+
// ...
37+
.addFilterBefore(new TenantFilter(), LogoutFilter.class); // <1>
38+
return http.build();
39+
}
40+
// end::snippet[]
41+
42+
}

docs/src/test/kotlin/org/springframework/security/kt/docs/servlet/addingcustomfilter/CustomFilterTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import org.springframework.web.bind.annotation.RestController
4747
classes = [
4848
CustomFilterTests.UserDetailsConfig::class,
4949
CustomFilterTests.ApiController::class,
50-
SecurityConfig::class
50+
SecurityConfigBefore::class
5151
]
5252
)
5353
@WebAppConfiguration
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2004-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.kt.docs.servlet.addingcustomfilter
18+
19+
import org.springframework.context.annotation.Bean
20+
import org.springframework.context.annotation.Configuration
21+
import org.springframework.security.config.annotation.web.builders.HttpSecurity
22+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
23+
import org.springframework.security.config.annotation.web.invoke
24+
import org.springframework.security.web.SecurityFilterChain
25+
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter
26+
27+
@Configuration
28+
@EnableWebSecurity
29+
open class SecurityConfigAfter {
30+
31+
// tag::snippet[]
32+
@Bean
33+
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
34+
http {
35+
// ...
36+
addFilterAfter<AnonymousAuthenticationFilter>(TenantFilter()) // <1>
37+
}
38+
return http.build()
39+
}
40+
// end::snippet[]
41+
42+
}

docs/src/test/kotlin/org/springframework/security/kt/docs/servlet/addingcustomfilter/SecurityConfig.kt renamed to docs/src/test/kotlin/org/springframework/security/kt/docs/servlet/addingcustomfilter/SecurityConfigBefore.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,21 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity
2222
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
2323
import org.springframework.security.config.annotation.web.invoke
2424
import org.springframework.security.web.SecurityFilterChain
25-
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter
2625
import org.springframework.security.web.authentication.logout.LogoutFilter
2726

2827
@Configuration
2928
@EnableWebSecurity
30-
open class SecurityConfig {
29+
open class SecurityConfigBefore {
3130

32-
// tag::snippet-before[]
31+
// tag::snippet[]
3332
@Bean
34-
open fun filterChainBefore(http: HttpSecurity): SecurityFilterChain {
33+
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
3534
http {
3635
// ...
3736
addFilterBefore<LogoutFilter>(TenantFilter()) // <1>
3837
}
3938
return http.build()
4039
}
41-
// end::snippet-before[]
42-
43-
// tag::snippet-after[]
44-
@Bean
45-
open fun filterChainAfter(http: HttpSecurity): SecurityFilterChain {
46-
http {
47-
// ...
48-
addFilterAfter<AnonymousAuthenticationFilter>(TenantFilter()) // <1>
49-
}
50-
return http.build()
51-
}
52-
// end::snippet-after[]
40+
// end::snippet[]
5341

5442
}

0 commit comments

Comments
 (0)