Spring Security--在Thymeleaf中取值

本文详细介绍了如何在Thymeleaf中利用Spring Security进行权限管理和内容控制。内容包括通过`sec:authentication`获取UsernamePasswordAuthenticationToken的属性,如用户名、权限等,并展示了创建`demo.html`页面进行权限判断的步骤。此外,还讲解了使用`sec:authorize`进行权限判断的用法,以决定页面上元素的可见性。
摘要由CSDN通过智能技术生成

    Thymeleaf 中 Spring Security 的使用

    Spring Security 可以在一些视图技术中进行控制显示效果。例如:
JSP 或 Thymeleaf。在非前后端分离且使用 Spring Boot 的项目中多使用 Thymeleaf 作为视图展示技术。Thymeleaf对Spring Security 的支持都放在 thymeleaf-extras-springsecurityX 中,目前最新版本为 5。
      所以需要在项目中添加此 jar 包的依赖和 thymeleaf 的依赖。

<dependency> 
	<groupId>org.thymeleaf.extras</groupId> 
	<artifactId>thymeleaf-extras-springsecurity5</artifactId> 
</dependency> 
<dependency> 
	<groupId>org.springframework.boot</groupId> 
	<artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 

      在 html 页面中引入 thymeleaf 命名空间和 security 命名空间

<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:th="http://www.thymeleaf.org" 
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值