SpringBoot Security如何与Thymeleaf实现高效整合配置?
- 内容介绍
- 文章标签
- 相关推荐
本文共计492个文字,预计阅读时间需要2分钟。
功能:解决网站登录、权限验证、授权等功能优点:在不影响网站业务代码的情况下,可以权限控制地授权与验证到业务中
1、要添加的依赖:
功能:解决web站点的登录,权限验证,授权等功能
优点:在不影响站点业务代码,可以权限的授权与验证横切到业务中
1、要添加的依赖
<!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--security 和 thymeleaf 整合包--> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> </dependency> <!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--security--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
2、Security 下授权与验证的简单配置(Security下有登录,注销,记住我等功能,可以快速集成到自己的login页上)
Tis:如果template页中使用了 Frame页,默认是不能访问的,需要添加 www.thymeleaf.org" xmlns:sec="www.thymeleaf.org/extras/spring-security">
<!--
sec:authorize="isAuthenticated()" 用户是否登录
sec:authorize="hasAnyRole('admin1')" 是否具有某个角色
sec:authentication="name" 当前登录用户
sec:authentication="principal.authorities" 当前用户全部角色
-->
<div sec:authorize="isAuthenticated()">
<h2><span sec:authentication="name"></span>,您好 您的身份是
<span sec:authentication="principal.authorities"></span>
</h2>
</div>
<li sec:authorize="hasRole('admin2')">
<a onclick="xadmin.add_tab('权限管理','admin/rule')">
<cite>权限管理</cite>
</a>
</li>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。
本文共计492个文字,预计阅读时间需要2分钟。
功能:解决网站登录、权限验证、授权等功能优点:在不影响网站业务代码的情况下,可以权限控制地授权与验证到业务中
1、要添加的依赖:
功能:解决web站点的登录,权限验证,授权等功能
优点:在不影响站点业务代码,可以权限的授权与验证横切到业务中
1、要添加的依赖
<!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--security 和 thymeleaf 整合包--> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> </dependency> <!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--security--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
2、Security 下授权与验证的简单配置(Security下有登录,注销,记住我等功能,可以快速集成到自己的login页上)
Tis:如果template页中使用了 Frame页,默认是不能访问的,需要添加 www.thymeleaf.org" xmlns:sec="www.thymeleaf.org/extras/spring-security">
<!--
sec:authorize="isAuthenticated()" 用户是否登录
sec:authorize="hasAnyRole('admin1')" 是否具有某个角色
sec:authentication="name" 当前登录用户
sec:authentication="principal.authorities" 当前用户全部角色
-->
<div sec:authorize="isAuthenticated()">
<h2><span sec:authentication="name"></span>,您好 您的身份是
<span sec:authentication="principal.authorities"></span>
</h2>
</div>
<li sec:authorize="hasRole('admin2')">
<a onclick="xadmin.add_tab('权限管理','admin/rule')">
<cite>权限管理</cite>
</a>
</li>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

