mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-31 14:48:54 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| = WebTestClient Security Setup
 | |
| 
 | |
| The basic setup looks like this:
 | |
| 
 | |
| ====
 | |
| .Java
 | |
| [source,java,role="primary"]
 | |
| ----
 | |
| @ExtendWith(SpringExtension.class)
 | |
| @ContextConfiguration(classes = HelloWebfluxMethodApplication.class)
 | |
| public class HelloWebfluxMethodApplicationTests {
 | |
| 	@Autowired
 | |
| 	ApplicationContext context;
 | |
| 
 | |
| 	WebTestClient rest;
 | |
| 
 | |
| 	@BeforeEach
 | |
| 	public void setup() {
 | |
| 		this.rest = WebTestClient
 | |
| 			.bindToApplicationContext(this.context)
 | |
| 			// add Spring Security test Support
 | |
| 			.apply(springSecurity())
 | |
| 			.configureClient()
 | |
| 			.filter(basicAuthentication("user", "password"))
 | |
| 			.build();
 | |
| 	}
 | |
| 	// ...
 | |
| }
 | |
| ----
 | |
| 
 | |
| .Kotlin
 | |
| [source,kotlin,role="secondary"]
 | |
| ----
 | |
| @ExtendWith(SpringExtension::class)
 | |
| @ContextConfiguration(classes = [HelloWebfluxMethodApplication::class])
 | |
| class HelloWebfluxMethodApplicationTests {
 | |
|     @Autowired
 | |
|     lateinit var context: ApplicationContext
 | |
| 
 | |
|     lateinit var rest: WebTestClient
 | |
| 
 | |
|     @BeforeEach
 | |
|     fun setup() {
 | |
|         this.rest = WebTestClient
 | |
|             .bindToApplicationContext(this.context)
 | |
|             // add Spring Security test Support
 | |
|             .apply(springSecurity())
 | |
|             .configureClient()
 | |
|             .filter(basicAuthentication("user", "password"))
 | |
|             .build()
 | |
|     }
 | |
|     // ...
 | |
| }
 | |
| ----
 | |
| ====
 |