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