• Shiro之授权&注解


    目录

    一、shiro之授权角色、权限

    二、shiro之注解式开发


    一、shiro之授权角色、权限

     分析如图:

    步骤:

    1,mapper层,service层

     usermapper.xml

    1. <select id="selectRoleIdByUserName" resultType="java.lang.String" parameterType="java.lang.String" >
    2. select
    3. <include refid="Base_Column_List" />
    4. select roleid from t_shiro_user u,t_shiro_user_role ur
    5. where u.userid=ur.userid and u.username = #{userName}
    6. </select>
    7. <!---->
    8. <select id="selectPerIdsByUserName" resultType="java.lang.String" parameterType="java.lang.String" >
    9. select
    10. <include refid="Base_Column_List" />
    11. select rp.perid from t_shiro_user u,t_shiro_user_role ur ,t_shiro_role_permission rp
    12. where u.userid= ur.userid and ur.roleid=rp.roleid and u.username = #{userName}
    13. </select>

     usermapper.java类

    1. //角色编号查找
    2. Set<String> selectRoleIdByUserName(@Param("userName") String username);
    3. //查看权限
    4. Set<String> selectPerIdsByUserName(@Param("userName") String username);

     实现类

    1. package com.zking.oa.biz;
    2. import com.zking.oa.mapper.UserMapper;
    3. import com.zking.oa.model.User;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Service;
    6. import java.util.Set;
    7. /**
    8. * @author 锦鲤
    9. * @site www.lucy.com
    10. * @company xxx公司
    11. * @create  2022-08-25 18:47
    12. * //@ContextConfiguration(locations = "classpath:applicationContext-shiro.xml","classpath:UserMapper.xml")
    13. */
    14. @Service("userbiz")
    15. public class UserBizImpl implements UserBiz {
    16. @Autowired
    17. private UserMapper usermapper;
    18. @Override
    19. public int deleteByPrimaryKey(Integer userid) {
    20. return usermapper.deleteByPrimaryKey(userid);
    21. }
    22. @Override
    23. public int insert(User record) {
    24. return usermapper.insert(record);
    25. }
    26. @Override
    27. public int insertSelective(User record) {
    28. return usermapper.insertSelective(record);
    29. }
    30. @Override
    31. public User selectByPrimaryKey(Integer userid) {
    32. return usermapper.selectByPrimaryKey(userid);
    33. }
    34. @Override
    35. public int updateByPrimaryKeySelective(User record) {
    36. return usermapper.updateByPrimaryKeySelective(record);
    37. }
    38. @Override
    39. public int updateByPrimaryKey(User record) {
    40. return usermapper.updateByPrimaryKey(record);
    41. }
    42. @Override
    43. public User queryUserByUserName(String userName) {
    44. return usermapper.queryUserByUserName(userName);
    45. }
    46. @Override
    47. public Set<String> selectRoleIdByUserName(String username) {
    48. return usermapper.selectRoleIdByUserName(username);
    49. }
    50. @Override
    51. public Set<String> selectPerIdsByUserName(String username) {
    52. return usermapper.selectPerIdsByUserName(username);
    53. }
    54. }

    2,shiro的授权方法

    1. package com.zking.oa.controller;
    2. import org.apache.shiro.SecurityUtils;
    3. import org.apache.shiro.authc.UsernamePasswordToken;
    4. import org.apache.shiro.subject.Subject;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import javax.servlet.http.HttpServletRequest;
    8. /**
    9. * @author 锦鲤
    10. * @site www.lucy.com
    11. * @company xxx公司
    12. * @create  2022-08-19 21:46
  • 相关阅读:
    想学好C语言这些关键字不能少(深度解剖)
    Iptables防火墙limit模块扩展匹配规则
    可视化图表组件之股票数据分析应用
    18.Hystrix 的常用配置
    数据库实践 Hw08
    OGG-01224 Address already in use 问题
    C语言第三十六弹---文件操作(中)
    Mysql数据库指定某数据库或某表赋予增删改查操作权限各类划分权限的方法总结实战
    JS(JavaScript)
    基于SSM的摄影约拍系统
  • 原文地址:https://blog.csdn.net/qq_66924116/article/details/126548877