首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用户登陆后的显示权限列表

用户登陆后的显示权限列表

作者头像
微醺
发布2019-01-17 12:52:32
1.4K0
发布2019-01-17 12:52:32
举报

1.查找用户列表,并添加到当前session中

@Controller
	public class HomeController {
	    @Autowired
	    private SysUserService sysUserService;
	    @RequestMapping({"/","/index"})
	    public String index(HttpServletRequest request){
	        //通过安全管理工具,获取用户对象
	        Subject subject = SecurityUtils.getSubject();
	        //获取用户身份-------用户名
	        String username = (String)subject.getPrincipal();
	        //获取当前对象所在的session
	        Session session = subject.getSession();
	        //获取权限列表
	        List<SysPermission> permissionList = sysUserService.findPermission(username);
	        //添加权限列表到session回话中
	        session.setAttribute("menuList",permissionList);
	        return "index";
	    }
	}

2.index.html 使用th显示权限列表菜单

<!DOCTYPE html>
	<html xmlns:th="http://www.thymeleaf.org">
		<head>
		    <meta charset="UTF-8">
		    <title>Title</title>
		</head>
		<body>
		    index
		
		    <table>
		        <thead>
		        <tr>
		            <th>序号</th>
		            <th>菜单名称</th>
		            <th>权限</th>
		            <th>url路径</th>
		        </tr>
		        <tr th:each="menu:${session.menuList}">
		            <td th:text="${menu.id}"></td>
		            <td th:text="${menu.name}"></td>
		            <td th:text="${menu.percode}"></td>
		            <td th:text="${menu.url}"></td>
		        </tr>
		        </thead>
		    </table>
		</body>
	</html>

3.使用shiro控制哪些权限可见,哪些不可见

1.导入依赖

 <dependency>
			<groupId>com.github.theborakompanioni</groupId>
			<artifactId>thymeleaf-extras-shiro</artifactId>
			<version>1.2.1</version>
		</dependency>

2.index.html

<!DOCTYPE html>
	<html xmlns:th="http://www.thymeleaf.org"
	      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
	<head>
	    <meta charset="UTF-8">
	    <title>Title</title>
	</head>
	<body>
	    <span shiro:authenticated="true" >
	          <span>我已登录</span>
	    </span>
	    <span shiro:haspermission="aaa" >
	          <span>没有权限</span>
	    </span>
	    <span shiro:haspermission="userInfo:delete" >
	          <span>我有权限</span>
	    </span>
	</body>
	</html>

密码登录次数限制

测试

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年12月26日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.查找用户列表,并添加到当前session中
  • 2.index.html 使用th显示权限列表菜单
  • 3.使用shiro控制哪些权限可见,哪些不可见
    • 1.导入依赖
      • 2.index.html
      • 测试
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档