在搞权限时候,发现登录页面是混乱的,在没登录的情况下,展示出了“您好,您的角色有” 这种本该是登陆状态下才展示的东西,我觉得应该是"isAuthenticated()"没有生效,没有准确判断出登录状态以及该展示的东西。
网上查到说:是springboot在引入security的时候在springboot的2.0.7之后的版本中对于此标签好像不支持,所以就会出现写了之后无反应的情况,将我们引入的springboot版本改到2.0.7或者之前版本就好了,经过我多次尝试,发现是引入版本的问题
前端页面中引入的命名空间是springsecurity4版本,但是pom文件中引入的是5,可能冲突了,于是统一全引入5:
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
前端展示:
<h1 align="center">欢迎光临武林秘籍管理系统</h1>
<div sec:authorize="!isAuthenticated()">
<h2 align="center">游客您好,如果想查看武林秘籍 <a th:href="@{/login}">请登录</a></h2>
</div>
<div sec:authorize="isAuthenticated()">
<h2><span sec:authentication="name"></span>,您好,您的角色有:
<span sec:authentication="principal.authorities"></span>
</h2>
<form th:action="@{/logout}" method="post">
<input type="submit" value="注销">
</form>
</div>
pom文件:
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
/*<version>3.0.4.RELEASE</version>*/
</dependency>
springbootyou版本控制,不用刻意指定
未登录展示:
成功登录展示:
版权声明:本文为weixin_42260782原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。