additional tests and content

This commit is contained in:
nnhai1991@gmail.com 2018-08-19 17:24:43 +08:00
parent 0d684eed97
commit 3f8eddad33
3 changed files with 10 additions and 3 deletions

View File

@ -35,6 +35,7 @@ public class ApplicationConfig extends WebSecurityConfigurerAdapter {
http.csrf()
.and()
.authorizeRequests()
.antMatchers("/adminOnlyURL").hasRole("ADMIN")
.anyRequest().permitAll().and().httpBasic();
// @formatter:on
}

View File

@ -14,9 +14,9 @@
ANONYMOUS
</sec:authorize>
<sec:authorize access="isAuthenticated()">
AUTHENTICATED
AUTHENTICATED Content
<sec:authorize access="hasRole('ADMIN')">
ADMIN ROLE
Content for users who have the "ADMIN" role.
</sec:authorize>
<h2>
principal.username:
@ -26,6 +26,9 @@
<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>
</sec:authorize>
</body>
</html>

View File

@ -31,11 +31,14 @@ public class HomeControllerTest {
assertTrue(body.contains("AUTHENTICATED"));
// test <sec:authorize access="hasRole('ADMIN')">
assertTrue(body.contains("ADMIN ROLE"));
assertTrue(body.contains("Content for users who have the \"ADMIN\" role."));
// test <sec:authentication property="principal.username" />
assertTrue(body.contains("testUser"));
// test <sec:authorize url="/adminOnlyURL">
assertTrue(body.contains("<a href=\"/adminOnlyURL\">"));
// test <sec:csrfInput />
assertTrue(body.contains("<input type=\"hidden\" name=\"_csrf\" value=\""));