mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	
		
			
	
	
		
			30 lines
		
	
	
		
			819 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			30 lines
		
	
	
		
			819 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
|  | = Testing HTTP Basic Authentication | ||
|  | 
 | ||
|  | While it has always been possible to authenticate with HTTP Basic, it was a bit tedious to remember the header name, format, and encode the values. | ||
|  | Now this can be done using Spring Security's `httpBasic` xref:servlet/test/mockmvc/request-post-processors.adoc[`RequestPostProcessor`]. | ||
|  | For example, the snippet below: | ||
|  | 
 | ||
|  | ==== | ||
|  | .Java | ||
|  | [source,java,role="primary"] | ||
|  | ---- | ||
|  | mvc | ||
|  | 	.perform(get("/").with(httpBasic("user","password"))) | ||
|  | ---- | ||
|  | 
 | ||
|  | .Kotlin | ||
|  | [source,kotlin,role="secondary"] | ||
|  | ---- | ||
|  | mvc.get("/") { | ||
|  |     with(httpBasic("user","password")) | ||
|  | } | ||
|  | ---- | ||
|  | ==== | ||
|  | 
 | ||
|  | will attempt to use HTTP Basic to authenticate a user with the username "user" and the password "password" by ensuring the following header is populated on the HTTP Request: | ||
|  | 
 | ||
|  | [source,text] | ||
|  | ---- | ||
|  | Authorization: Basic dXNlcjpwYXNzd29yZA== | ||
|  | ---- |