File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed 
spring-boot-sample-web-method-security/src/main/resources/templates 
spring-boot-sample-web-secure/src 
test/java/sample/ui/secure Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 2020			< p  th:if ="${param.logout} " class ="alert "> You have been logged out</ p > 
2121			< p  th:if ="${param.error} " class ="alert alert-error "> There was an error, please try again</ p > 
2222			< h2 > Login with Username and Password</ h2 > 
23- 			< form  name ="form " action ="/login " method ="POST "> 
23+ 			< form  name ="form " th:action =" @{/login} "  action ="/login " method ="POST "> 
2424				< fieldset > 
2525					< input  type ="text " name ="username " value ="" placeholder ="Username " /> 
2626					< input  type ="password " name ="password " placeholder ="Password " /> 
2727				</ fieldset > 
2828				< input  type ="submit " id ="login " value ="Login "
29- 					class ="btn btn-primary " />  < input  type ="hidden "
30- 					th:name ="${_csrf.parameterName} " th:value ="${_csrf.token} " /> 
29+ 					class ="btn btn-primary " /> 
3130			</ form > 
3231		</ div > 
3332	</ div > 
Original file line number Diff line number Diff line change 2020			< p  th:if ="${param.logout} " class ="alert "> You have been logged out</ p > 
2121			< p  th:if ="${param.error} " class ="alert alert-error "> There was an error, please try again</ p > 
2222			< h2 > Login with Username and Password</ h2 > 
23- 			< form  name ="form " action ="/login " method ="POST "> 
23+ 			< form  name ="form " th:action =" @{/login} "  action ="/login " method ="POST "> 
2424				< fieldset > 
2525					< input  type ="text " name ="username " value ="" placeholder ="Username " /> 
2626					< input  type ="password " name ="password " placeholder ="Password " /> 
2727				</ fieldset > 
2828				< input  type ="submit " id ="login " value ="Login "
29- 					class ="btn btn-primary " />  < input  type ="hidden "
30- 					th:name ="${_csrf.parameterName} " th:value ="${_csrf.token} "/> 
29+ 					class ="btn btn-primary " /> 
3130			</ form > 
3231		</ div > 
3332	</ div > 
Original file line number Diff line number Diff line change @@ -69,6 +69,18 @@ public void testHome() throws Exception {
6969				entity .getHeaders ().getLocation ().toString ().endsWith (port  + "/login" ));
7070	}
7171
72+ 	@ Test 
73+ 	public  void  testLoginPage () throws  Exception  {
74+ 		HttpHeaders  headers  = new  HttpHeaders ();
75+ 		headers .setAccept (Arrays .asList (MediaType .TEXT_HTML ));
76+ 		ResponseEntity <String > entity  = new  TestRestTemplate ().exchange (
77+ 				"http://localhost:"  + this .port  + "/login" , HttpMethod .GET , new  HttpEntity <Void >(
78+ 						headers ), String .class );
79+ 		assertEquals (HttpStatus .OK , entity .getStatusCode ());
80+ 		assertTrue ("Wrong content:\n "  + entity .getBody (),
81+ 				entity .getBody ().contains ("_csrf" ));
82+ 	}
83+ 
7284	@ Test 
7385	public  void  testLogin () throws  Exception  {
7486		HttpHeaders  headers  = getHeaders ();
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments