注销及权限控制
注销前端
<a th:href="@{/logout}">注销</a>
注销后端config
http.logout().logoutSuccessUrl("/");
权限控制
导包
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
前端页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
li{
list-style: none;
}
</style>
<body>
<div sec:authorize="!isAuthenticated()">
<a href="/toLogin">登录</a>
</div>
<div sec:authorize="isAuthenticated()">
用户名: <span sec:authentication="name"></span>
角色: <span sec:authentication="authorities"></span>
</div>
<div sec:authorize="isAuthenticated()">
<a th:href="@{/logout}">注销</a>
</div>
<hr>
<h2>level1</h2>
<div sec:authorize="hasRole('vip1')">
<ul>
<li><a href="/level1/1">level1-1</a></li>
<li><a href="/level1/2">level1-2</a></li>
<li><a href="/level1/3">level1-3</a></li>
</ul>
</div>
<hr>
<h2>level2</h2>
<ul sec:authorize="hasRole('vip2')">
<li><a href="/level2/1">level2-1</a></li>
<li><a href="/level2/2">level2-2</a></li>
<li><a href="/level2/3">level2-3</a></li>
</ul>
<hr>
<h2>level3</h2>
<ul sec:authorize="hasRole('vip3')">
<li><a href="/level3/1">level3-1</a></li>
<li><a href="/level3/2">level3-2</a></li>
<li><a href="/level3/3">level3-3</a></li>
</ul>
</body>
</html>
http.csrf().disable();