shiro-realm查询认证信息在页面展示
来源:互联网 发布:网络兼职 知乎 编辑:程序博客网 时间:2024/05/30 18:30
认证信息在页面显示
1、认证后用户菜单在首页显示
2、认证后用户的信息在页头显示
修改realm设置完整认证信息
realm从数据库查询用户信息,将用户菜单、usercode、username等设置在SimpleAuthenticationInfo中。
先使用静态代码实现:
//注入SysService来调用数据库的相关数据@Autowiredprivate SysService sysService;//realm的认证方法,模拟从数据库查询用户信息protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {//token是用户输入的//模拟从数据库中查询到的密码String password = "111111";//模拟静态数据ActiveUser activeUser = new ActiveUser();activeUser.setUserid("zhangsan");activeUser.setUsercode("zhangsan");activeUser.setUsername("张三");List<SysPermission> menus = null;//根据用户的id取出菜单try {menus = sysService.findMenuListByUserId("zhangsan");//在实际的数据库中,张三存在菜单的} catch (Exception e) {e.printStackTrace();}//将用户的菜单设置到activeUser中activeUser.setMenus(menus);//将activeUser设置到simpleAuthenticationInfo中SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(activeUser, password, this.getName());return simpleAuthenticationInfo;}
修改first.action将认证信息在页面显示
//系统首页@RequestMapping("/first")public String first(Model model)throws Exception{//从shiro的session中取出activeUserSubject subject = SecurityUtils.getSubject();//取出身份信息ActiveUser activeUser = (ActiveUser) subject.getPrincipal();//通过model传给页面model.addAttribute("activeUser", activeUser);return "/first";}
阅读全文
0 0
- shiro-realm查询认证信息在页面展示
- Shiro开发框架,固定信息Realm认证。
- shiro-realm认证
- Shiro 自定义realm认证
- Shiro入门6:自定义realm查询数据库进行认证
- Shiro 的身份认证-Realm
- Shiro身份认证、Realm&JDBC Reaml
- Shiro多个Realm认证及授权
- Shiro-学习总结-认证之自定义realm
- shiro多登录入口,多realm认证
- shiro授权,自定义realm实现授权,shiro与项目集成,在项目中实现认证及授权
- shiro简介,认证,认证流程,自定义realm,散列算法
- Shiro之多Realm的认证及认证策略-yellowcong
- Shiro第二篇【介绍Shiro、认证流程、自定义realm、自定义realm支持md5】
- (六) shiro在web中自定义Realm
- Shiro Review——自定义Realm实现认证
- apache-shiro杂记(二) 关于多realm认证的策略
- Shiro 自定义realm授权与认证的实现
- Matlab中image、imagesc和imshow函数用法解析
- k-近邻算法
- sql-server 查询
- cs231n_assignment1
- 最小编辑距离算法
- shiro-realm查询认证信息在页面展示
- 变参函数详解
- Python 正则表达式入门(中级篇)
- bzoj4897
- Ceilometr: 11、Grafana接入Gnocchi翻译
- RecyclerView解析
- AMBA片上总线设计之Ahb2ApbBridge总结
- ocx基础
- S5PV210系列 (裸机十)之按键和CPU的中断系统(二)