Fix servlet/architecture.adoc disable Sample

- Switch `include-java` (does not exist) to `include-code`
- Update kotlin to have the `disable` tag
- Update to suppress deprecation use for User builder (allowed for samples)

Signed-off-by: Robert Winch <362503+rwinch@users.noreply.github.com>
This commit is contained in:
Robert Winch 2026-02-23 16:34:18 -06:00
parent 62d1bc86e3
commit 0c394696ce
No known key found for this signature in database
4 changed files with 21 additions and 5 deletions

View File

@ -301,7 +301,7 @@ In this case, remove the call to `httpBasic` since you are constructing `BasicAu
====
In the event that you are unable to reconfigure `HttpSecurity` to not add a certain filter, you can typically disable the Spring Security filter by calling its DSL's `disable` method like so:
include-java::./CustomizingFilterTests[tag=disable,indent=0]
include-code::./CustomizingFilterTests[tag=disable,indent=0]
====
[[servlet-exceptiontranslationfilter]]

View File

@ -142,16 +142,16 @@ public class CustomizingFilterTests {
@EnableWebSecurity
static class SecurityConfigDisable {
// tag::disable[]
@Bean
SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
// tag::disable[]
.httpBasic((basic) -> basic.disable());
// end::disable[]
// ...
return http.build();
}
// end::disable[]
}

View File

@ -84,6 +84,7 @@ class CustomFilterTests {
open class UserDetailsConfig {
@Bean
open fun userDetailsService(): UserDetailsService {
@Suppress("DEPRECATION")
val user: UserDetails = User.withDefaultPasswordEncoder()
.username("user")
.password("password")

View File

@ -26,7 +26,6 @@ import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.invoke
@ -36,7 +35,6 @@ import org.springframework.security.web.FilterChainProxy
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.get
/**
* Tests for customizing security filters.
@ -120,6 +118,23 @@ class CustomizingFilterTests {
}
@Configuration @EnableWebSecurity
open class SecurityConfigDisable {
// tag::disable[]
@Bean
open fun filterChain(http: HttpSecurity): SecurityFilterChain {
http {
httpBasic {
disable()
}
// ...
}
return http.build()
}
// end::disable[]
}
@Configuration
@EnableWebSecurity
open class SecurityConfigIncorrect {