[版权声明] 本站内容采用 知识共享署名-非商业性使用-相同方式共享 3.0 中国大陆 (CC BY-NC-SA 3.0 CN) 进行许可。
部分内容和资源来自网络,纯学习研究使用。如有侵犯您的权益,请及时联系我,我将尽快处理。
如转载请注明来自: Broly的博客,本文链接: SpringSecurity+Thymeleaf中sec:authorize="isAuthenticated()"不生效问题
SpringSecurity+Thymeleaf的应用场景中,HTML模板文件使用验证身份的函数没生效
运行环境:
- Spring Boot 2.0.9
- Spring Security 5.x
- Thymeleaf 3.x
要点一:
pom.xml中要有对应Spring Security版本的thymeleaf-extras-springsecurity依赖:
1 2 3 4 |
<dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> </dependency> |
要点二:
HTML模板文件中,一定要加入三个命名空间声明,缺一不可:
1 2 3 4 |
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> |
最后问题解决。
参考文档:
《sec:authorize="isAuthenticated()" no longer works with thymeleaf-extras-springsecurity5 》
https://github.com/thymeleaf/thymeleaf-extras-springsecurity#namespace