代码拉取完成,页面将自动刷新
同步操作将从 小牛肉/cs-wiki 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
退出登录特别的简单,这个 Spring Security 就已经帮我们实现了,只需要在 form 表单中通过 post
方式提交 /logout
请求即可,如下示例代码 index.html
:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security入门</title>
</head>
<body>
<h1>欢迎使用Spring Security!</h1>
<form th:action="@{/logout}" method="post">
<input type="submit" value="退出登录"/>
</form>
<p>点击 <a th:href="@{/hello}">这里</a> 打个招呼吧</p>
<p> <a th:href="@{/hello/helloAdmin}">admin page</a></p>
<p><a th:href="@{/hello/helloUser}">user page</a></p>
</body>
</html>
如果使用 user 的账号进行登录,然后访问 admin page 的话,会报 403 的 ErrorPage,这个很不友好,我们需要重新定义这个 403 页面。
对于 403 异常的处理有很多种方案,这里采用的是:重新定义一个 403.html
页面,将该文件放到 /templates/error
下,这样 Spring 就可以找到我们自己定义的 403 页面了,403.html
示例代码如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>没有权限</title>
</head>
<body>
<h1 th:inline="text">抱歉!</h1>
<p>您没有权限访问该页面 -------这是403界面.</p>
<p><a th:href="@{/hello/helloUser}">前往普通用户界面</a></p>
<form th:action="@{/logout}" method="post">
<input type="submit" value="退出登录"/>
</form>
</body>
</html>
正确的目录结构如下:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。