update examples
This commit is contained in:
		
							parent
							
								
									1842c33b3a
								
							
						
					
					
						commit
						7263e223c5
					
				| @ -35,7 +35,7 @@ public class ApplicationConfig extends WebSecurityConfigurerAdapter { | ||||
|         http.csrf() | ||||
|                 .and() | ||||
|             .authorizeRequests() | ||||
|                 .antMatchers("/adminOnlyURL").hasRole("ADMIN") | ||||
|                 .antMatchers("/userManagement").hasRole("ADMIN") | ||||
|                 .anyRequest().permitAll().and().httpBasic(); | ||||
|         // @formatter:on | ||||
|     } | ||||
|  | ||||
| @ -10,23 +10,27 @@ | ||||
| <title>Home Page</title> | ||||
| </head> | ||||
| <body>     | ||||
|     <sec:authorize access="isAnonymous()"> | ||||
|         ANONYMOUS Content | ||||
|     <sec:authorize access="!isAuthenticated()"> | ||||
|         Login | ||||
|     </sec:authorize> | ||||
|      | ||||
|     <sec:authorize access="isAuthenticated()"> | ||||
|         AUTHENTICATED Content  | ||||
|         <sec:authorize access="hasRole('ADMIN')"> | ||||
|             Content for users who have the "ADMIN" role. | ||||
|         Logout | ||||
|     </sec:authorize> | ||||
|      | ||||
|     <sec:authorize access="isAuthenticated()"> | ||||
|         <h2> | ||||
|             Welcome back, <sec:authentication property="name" /> | ||||
|         </h2>          | ||||
|         <sec:authorize access="hasRole('ADMIN')"> | ||||
|             Manage Users | ||||
|         </sec:authorize> | ||||
|         <form> | ||||
|             <sec:csrfInput /> | ||||
|             Text Field: <br /> <input type="text" name="textField" /> | ||||
|         </form> | ||||
|         <sec:authorize url="/adminOnlyURL"> | ||||
|             <a href="/adminOnlyURL">Go to Admin Only URL</a> | ||||
|         <sec:authorize url="/userManagement"> | ||||
|             <a href="/userManagement">Manage Users</a> | ||||
|         </sec:authorize> | ||||
|     </sec:authorize> | ||||
| </body> | ||||
|  | ||||
| @ -24,20 +24,20 @@ public class HomeControllerTest { | ||||
|             .getForEntity("/", String.class) | ||||
|             .getBody(); | ||||
| 
 | ||||
|         // test <sec:authorize access="isAnonymous()"> | ||||
|         assertFalse(body.contains("ANONYMOUS")); | ||||
|         // test <sec:authorize access="!isAuthenticated()"> | ||||
|         assertFalse(body.contains("Login")); | ||||
| 
 | ||||
|         // test <sec:authorize access="isAuthenticated()"> | ||||
|         assertTrue(body.contains("AUTHENTICATED Content")); | ||||
|         assertTrue(body.contains("Logout")); | ||||
| 
 | ||||
|         // test <sec:authorize access="hasRole('ADMIN')"> | ||||
|         assertTrue(body.contains("Content for users who have the \"ADMIN\" role.")); | ||||
|         assertTrue(body.contains("Manage Users")); | ||||
| 
 | ||||
|         // test <sec:authentication property="principal.username" /> | ||||
|         assertTrue(body.contains("testUser")); | ||||
| 
 | ||||
|         // test <sec:authorize url="/adminOnlyURL"> | ||||
|         assertTrue(body.contains("<a href=\"/adminOnlyURL\">")); | ||||
|         assertTrue(body.contains("<a href=\"/userManagement\">")); | ||||
|          | ||||
|         // test <sec:csrfInput /> | ||||
|         assertTrue(body.contains("<input type=\"hidden\" name=\"_csrf\" value=\"")); | ||||
| @ -51,10 +51,10 @@ public class HomeControllerTest { | ||||
|         String body = this.restTemplate.getForEntity("/", String.class) | ||||
|             .getBody(); | ||||
| 
 | ||||
|         // test <sec:authorize access="isAnonymous()"> | ||||
|         assertTrue(body.contains("ANONYMOUS Content")); | ||||
|         // test <sec:authorize access="!isAuthenticated()"> | ||||
|         assertTrue(body.contains("Login")); | ||||
| 
 | ||||
|         // test <sec:authorize access="isAuthenticated()"> | ||||
|         assertFalse(body.contains("AUTHENTICATED Content")); | ||||
|         assertFalse(body.contains("Logout")); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user