Shiro学习笔记_04:Shiro整合springboot之 thymeleaf权限控制

Shiro 学习笔记

本文基于B站UP主【编程不良人】视频教程【2020最新版Shiro教程,整合SpringBoot项目实战教程】进行整理记录,仅用于个人学习交流使用。

视频链接:https://www.bilibili.com/video/BV1uz4y197Zm

官方文档:http://www.baizhiedu.xin

目录标题

  • Shiro 学习笔记
    • 七、Shiro整合springboot之thymeleaf权限控制
      • 1.引入扩展依赖
      • 2.页面中引入命名空间
      • 3.常见权限控制标签使用
      • 4.加入shiro的方言配置

七、Shiro整合springboot之thymeleaf权限控制

1.引入扩展依赖

<dependency>
    <groupId>com.github.theborakompanionigroupId>
    <artifactId>thymeleaf-extras-shiroartifactId>
    <version>2.0.0version>
dependency>

2.页面中引入命名空间

xmlns:shiro=“http://www.pollix.at/thymeleaf/shiro”

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
......

3.常见权限控制标签使用


<p shiro:guest="">Please <a href="login.html">logina>p>



<p shiro:user="">
    Welcome back John! Not John? Click <a href="login.html">herea> to login.
p>


<p shiro:authenticated="">
    Hello, <span shiro:principal="">span>, how are you today?
p>
<a shiro:authenticated="" href="updateAccount.html">Update your contact informationa>


<p>Hello, <shiro:principal/>, how are you today?p>



<p shiro:notAuthenticated="">
    Please <a href="login.html">logina> in order to update your credit card information.
p>


<a shiro:hasRole="admin" href="admin.html">Administer the systema>


<p shiro:lacksRole="developer">
    Sorry, you are not allowed to developer the system.
p>


<p shiro:hasAllRoles="developer, 2">
    You are a developer and a admin.
p>


<p shiro:hasAnyRoles="admin, vip, developer,1">
    You are a admin, vip, or developer.
p>


<a shiro:hasPermission="userInfo:add" href="createUser.html">添加用户a>


<p shiro:lacksPermission="userInfo:del">
    Sorry, you are not allowed to delete user accounts.
p>


<p shiro:hasAllPermissions="userInfo:view, userInfo:add">
    You can see or add users.
p>


<p shiro:hasAnyPermissions="userInfo:view, userInfo:del">
    You can see or delete users.
p>
<a shiro:hasPermission="pp" href="createUser.html">Create a new Usera>

4.加入shiro的方言配置

  • 页面标签不起作用一定要记住加入方言处理
@Bean(name = "shiroDialect")
public ShiroDialect shiroDialect(){
  return new ShiroDialect();
}

Shiro学习笔记_04:Shiro整合springboot之 thymeleaf权限控制_第1张图片


作者:耿鬼不会笑
时间:2021年1月

你可能感兴趣的:(Java框架&中间件,python,html,shiro,人工智能,linux)