首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

shiro框架权限demo

后端 110.93KB 29 需要积分: 1
立即下载

资源介绍:

shiro框架权限demo
package com.yueke.gemini.shiro.realm; /** * Created by admin on 2019/2/23. */ import com.yueke.gemini.shiro.constants.Global; import com.yueke.gemini.shiro.entity.Menu; import com.yueke.gemini.shiro.entity.Role; import com.yueke.gemini.shiro.entity.User; import com.yueke.gemini.shiro.service.UserService; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.session.Session; import org.apache.shiro.subject.PrincipalCollection; import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 自定义的指定Shiro验证用户登录的类 * 在本例中定义了2个用户:jadyer和玄玉,jadyer具有admin角色和admin:manage权限,玄玉不具有任何角色和权限 * @User: coding99 * */ @Service public class SystemAuthorizingRealm extends AuthorizingRealm { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private UserService userService; // @Autowired // private RoleService roleService; // @Autowired // private MenuService menuService; /** * 为当前登录的Subject授予角色和权限 * 经测试:本例中该方法的调用时机为需授权资源被访问时 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { //获取当前登录的用户名,等价于(String)principals.fromRealm(this.getName()).iterator().next() String currentAccount = (String) super.getAvailablePrincipal(principals); List roleNameList = new ArrayList(); List permissionList = new ArrayList(); //从数据库中获取当前登录用户的详细信息 User user = getUser(); if (null != user) { SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); List roleList = null;// roleService.selectRoleByUserId(user.getId()); Map map = new HashMap(); map.put("userId", user.getId()); map.put("permission", "permission"); List menuList = null; // menuService.selectMenuByUserId(map); /*构建用户的角色集合*/ for (Role role : roleList) { roleNameList.add(role.getRolename()); } info.addRoles(roleNameList); /*构建用户的权限代码集合*/ // for (Menu menu : menuList) { // if (StringUtils.isNotBlank(menu.getPermission())) { // if (StringUtils.isNotEmpty(menu.getPermission())) { // String[] permissions = menu.getPermission().split(","); // for (int i = 0; i < permissions.length; i++) { // if (StringUtils.isNotEmpty(permissions[i])) { // permissionList.add(permissions[i]); // } // } // } // } // } info.addStringPermissions(permissionList); return info; } else { return null; } } /** * 验证当前登录的Subject * 经测试:本例中该方法的调用时机为LoginController.login()方法中执行Subject.login()时 */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; String username = token.getUsername(); User user = userService.findByName(username); if (user == null) { throw new UnknownAccountException("帐号找不到"); } if ("0".equals(user.getStatus())) { throw new LockedAccountException("msg:该已帐号禁止登录."); } SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), getName()); setSession(Global.GLOBAL_USER, user); return authenticationInfo; } /** * 将一些数据放到ShiroSession中,以便于其它地方使用 * 比如Controller,使用时直接用HttpSession.getAttribute(key)就可以取到 */ private void setSession(Object key, Object value) { Subject currentUser = SecurityUtils.getSubject(); if (null != currentUser) { Session session = currentUser.getSession(); System.out.println("Session默认超时时间为[" + session.getTimeout() + "]毫秒"); if (null != session) { session.setAttribute(key, value); } } } private User getUser() { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute(Global.GLOBAL_USER); return user; } }

资源文件列表:

gemini-shiro.zip 大约有81个文件
  1. gemini-shiro/
  2. gemini-shiro/.idea/
  3. gemini-shiro/.idea/compiler.xml 789B
  4. gemini-shiro/.idea/copyright/
  5. gemini-shiro/.idea/copyright/profiles_settings.xml 76B
  6. gemini-shiro/.idea/encodings.xml 271B
  7. gemini-shiro/.idea/libraries/
  8. gemini-shiro/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml 514B
  9. gemini-shiro/.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_8_3.xml 594B
  10. gemini-shiro/.idea/libraries/Maven__commons_dbcp_commons_dbcp_1_4.xml 525B
  11. gemini-shiro/.idea/libraries/Maven__commons_logging_commons_logging_1_1_1.xml 572B
  12. gemini-shiro/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml 539B
  13. gemini-shiro/.idea/libraries/Maven__com_fasterxml_classmate_0_8_0.xml 522B
  14. gemini-shiro/.idea/libraries/Maven__javax_inject_javax_inject_1.xml 511B
  15. gemini-shiro/.idea/libraries/Maven__javax_persistence_javax_persistence_api_2_2.xml 608B
  16. gemini-shiro/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml 473B
  17. gemini-shiro/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml 522B
  18. gemini-shiro/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml 611B
  19. gemini-shiro/.idea/libraries/Maven__junit_junit_3_8_1.xml 462B
  20. gemini-shiro/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_26.xml 574B
  21. gemini-shiro/.idea/libraries/Maven__net_sf_ehcache_ehcache_2_7_2.xml 512B
  22. gemini-shiro/.idea/libraries/Maven__org_apache_commons_commons_lang3_3_8_1.xml 570B
  23. gemini-shiro/.idea/libraries/Maven__org_apache_shiro_shiro_core_1_2_2.xml 541B
  24. gemini-shiro/.idea/libraries/Maven__org_apache_shiro_shiro_spring_1_2_2.xml 555B
  25. gemini-shiro/.idea/libraries/Maven__org_apache_shiro_shiro_web_1_2_2.xml 534B
  26. gemini-shiro/.idea/libraries/Maven__org_codehaus_jackson_jackson_core_asl_1_9_13.xml 606B
  27. gemini-shiro/.idea/libraries/Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_13.xml 620B
  28. gemini-shiro/.idea/libraries/Maven__org_hibernate_hibernate_validator_5_0_1_Final.xml 634B
  29. gemini-shiro/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_1_1_GA.xml 587B
  30. gemini-shiro/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_6.xml 506B
  31. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_aop_3_2_4_RELEASE.xml 609B
  32. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_beans_3_2_4_RELEASE.xml 623B
  33. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_context_3_2_4_RELEASE.xml 637B
  34. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_core_3_2_4_RELEASE.xml 616B
  35. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_expression_3_2_4_RELEASE.xml 658B
  36. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_jdbc_3_2_4_RELEASE.xml 616B
  37. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_orm_3_2_4_RELEASE.xml 609B
  38. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_tx_3_2_4_RELEASE.xml 602B
  39. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_webmvc_3_2_4_RELEASE.xml 630B
  40. gemini-shiro/.idea/libraries/Maven__org_springframework_spring_web_3_2_4_RELEASE.xml 609B
  41. gemini-shiro/.idea/misc.xml 1.16KB
  42. gemini-shiro/.idea/modules.xml 264B
  43. gemini-shiro/.idea/workspace.xml 62.75KB
  44. gemini-shiro/gemini-shiro.iml 4.15KB
  45. gemini-shiro/pom.xml 4.81KB
  46. gemini-shiro/Shiro.md 1.64KB
  47. gemini-shiro/src/
  48. gemini-shiro/src/main/
  49. gemini-shiro/src/main/java/
  50. gemini-shiro/src/main/java/com/
  51. gemini-shiro/src/main/java/com/yueke/
  52. gemini-shiro/src/main/java/com/yueke/gemini/
  53. gemini-shiro/src/main/java/com/yueke/gemini/shiro/
  54. gemini-shiro/src/main/java/com/yueke/gemini/shiro/constants/
  55. gemini-shiro/src/main/java/com/yueke/gemini/shiro/constants/Global.java 174B
  56. gemini-shiro/src/main/java/com/yueke/gemini/shiro/controller/
  57. gemini-shiro/src/main/java/com/yueke/gemini/shiro/controller/HomeController.java 2.26KB
  58. gemini-shiro/src/main/java/com/yueke/gemini/shiro/entity/
  59. gemini-shiro/src/main/java/com/yueke/gemini/shiro/entity/Menu.java 167B
  60. gemini-shiro/src/main/java/com/yueke/gemini/shiro/entity/Permission.java 917B
  61. gemini-shiro/src/main/java/com/yueke/gemini/shiro/entity/Role.java 1.63KB
  62. gemini-shiro/src/main/java/com/yueke/gemini/shiro/entity/User.java 1.81KB
  63. gemini-shiro/src/main/java/com/yueke/gemini/shiro/realm/
  64. gemini-shiro/src/main/java/com/yueke/gemini/shiro/realm/SystemAuthorizingRealm.java 5.19KB
  65. gemini-shiro/src/main/java/com/yueke/gemini/shiro/realm/UserRealm.java 2.37KB
  66. gemini-shiro/src/main/java/com/yueke/gemini/shiro/service/
  67. gemini-shiro/src/main/java/com/yueke/gemini/shiro/service/impl/
  68. gemini-shiro/src/main/java/com/yueke/gemini/shiro/service/impl/UserServiceImpl.java 409B
  69. gemini-shiro/src/main/java/com/yueke/gemini/shiro/service/UserService.java 289B
  70. gemini-shiro/src/main/resources/
  71. gemini-shiro/src/main/resources/applicationContext-Servlet.xml 2.6KB
  72. gemini-shiro/src/main/resources/applicationContext-Shiro.xml 4.42KB
  73. gemini-shiro/src/main/webapp/
  74. gemini-shiro/src/main/webapp/403.jsp 391B
  75. gemini-shiro/src/main/webapp/login.jsp 760B
  76. gemini-shiro/src/main/webapp/user.jsp 2.01KB
  77. gemini-shiro/src/main/webapp/WEB-INF/
  78. gemini-shiro/src/main/webapp/WEB-INF/web.xml 1.57KB
  79. gemini-shiro/src/test/
  80. gemini-shiro/src/test/java/
  81. gemini-shiro/权限.png 71.92KB
0评论
提交 加载更多评论
其他资源 使用springcloud框架练习代码
使用springcloud框架练习代码
链表HuffmanTree.zip
链表HuffmanTree.zip
SPSS(2)(重点看多元统计).zip
数学建模spss学习笔记
SPSS(2)(重点看多元统计).zip SPSS(2)(重点看多元统计).zip SPSS(2)(重点看多元统计).zip
最优控制公式推导(代数里卡提方程,李雅普诺夫方程,HJB方程)
本文探讨了线性时不变系统(LTI系统)的最优控制问题,特别是线性二次调节器(LQR)问题。通过Hamilton-Jacobi-Bellman (HJB) 方程的推导,求得了系统的最优控制律,并进一步推导了代数里卡提方程(ARE)和李雅普诺夫方程,从而实现系统的最优控制。 关键词:线性二次调节器,Hamilton-Jacobi-Bellman方程,代数里卡提方程,李雅普诺夫方程,最优控制律 https://blog.csdn.net/weixin_44346182/article/details/140479211
最优控制公式推导(代数里卡提方程,李雅普诺夫方程,HJB方程)
SEA J1939 英文版
SEA J1939 标准英文原版 高清
SEA J1939 英文版 SEA J1939 英文版 SEA J1939 英文版
iis批量申请证书工具,免费的Let's Encrypt证书批量申请续费
iis批量申请证书工具,免费的Let's Encrypt证书批量申请续费
GP88写频软件(含驱动)
GP88写频软件(含驱动)
GP88写频软件(含驱动) GP88写频软件(含驱动) GP88写频软件(含驱动)
JavaWeb学生成绩管理系统,编写了一个简单的学生成绩管理系统,完成学生信息及课程成绩的增删改查操作
我的文章:“【Java Web】学生成绩管理系统”的资源包,详细步骤可以参考文章。 实验:JSP数据库程序设计 实验目的: 1. 掌握JDBC的常用接口及类; 2. 掌握JDBC访问数据库的方法; 实验内容及基本要求: 实验内容: 1. 编写一个简单的学生成绩管理系统,完成学生信息及课程成绩的增删改查操作。 基本要求: 1. 写出实验步骤 2. 写出实验中遇到的问题及解决的方法 目录: Java Web实验_学生成绩管理系统 2 一、新建项目 2 1. 复制项目shop 2 二、结构 2 1. 框架结构 2 2. 代码结构 3 三、学生信息管理 3 1. 实体 3 2. Dao层 4 3. DaoImpl实现类 4 4. Servlet控制器 7 5. 数据库 7 6. Servlet 和 Student的jsp 8 四、课程成绩管理 15 (一) 添加 15 (二) 删除 15 (三) 修改 16 (四) 查询 17 实验问题 17 1 复制的项目student直接部署然后访问,访问不到? 17 (1) 复制项目 17 (2) 问题 18 (3)修改上下文 18 (4)重新部署 1