update examples

This commit is contained in:
nnhai1991@gmail.com 2018-08-21 22:31:44 +08:00
parent 1842c33b3a
commit 7263e223c5
3 changed files with 23 additions and 19 deletions

View File

@ -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
}

View File

@ -9,24 +9,28 @@
<sec:csrfMetaTags />
<title>Home Page</title>
</head>
<body>
<sec:authorize access="isAnonymous()">
ANONYMOUS Content
<body>
<sec:authorize access="!isAuthenticated()">
Login
</sec:authorize>
<sec:authorize access="isAuthenticated()">
Logout
</sec:authorize>
<sec:authorize access="isAuthenticated()">
AUTHENTICATED Content
<sec:authorize access="hasRole('ADMIN')">
Content for users who have the "ADMIN" role.
</sec:authorize>
<h2>
Welcome back, <sec:authentication property="name" />
</h2>
</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>

View File

@ -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"));
}
}