当前位置: 首页 > news >正文

springboot实战项目之使用AOP技术实现各种角色的鉴权功能

前言

项目开发需求,会员有不同的角色,不同的角色被赋予不同的权限,这就需要对会员的操作进行鉴权处理。

方案

采用aop,可实现满足这种需求,创建匿名类。对外提供接口的时候都会拦截,这种会有弊端,当并发量大时,会存在瓶颈。

@Configuration
@Aspect
public class BusyAop {@Autowiredprivate DdMemberRolesMapper ddMemberRolesMapper;@Pointcut("@annotation(com.ruoyi.shop.api.aop.BusyOperatorRole)")private void permissionCheck() {}@Around("permissionCheck()")public Object around(ProceedingJoinPoint p) throws Throwable{WxLoginUser user=(WxLoginUser) getAuthentication().getPrincipal();//建议采用redis缓存方案,更好List<MemberRolesDo> list = getUserPermissions(user);if(CollUtil.size(list)==0){return AjaxResult.warn("无权访问");}Map<String, Object> response = (Map<String, Object>) p.proceed();return response;}private List<MemberRolesDo> getUserPermissions(WxLoginUser user) {MPJLambdaWrapper<MemberRolesDo> wrapper = new MPJLambdaWrapper<MemberRolesDo>().selectAll(MemberRolesDo.class).leftJoin(BusyMerchDto.class, BusyMerchDto::getMemberId, MemberRolesDo::getMemberId).leftJoin(BusyGroupDto.class, BusyGroupDto::getBusyMerchId, BusyMerchDto::getBusyMerchId).eq(MemberRolesDo::getRolesType, 6).eq(BusyGroupDto::getMemberId, user.getUserId());return ddMemberRolesMapper.selectJoinList(MemberRolesDo.class, wrapper);}}

如果有更好的方案,请评论私聊我。

http://www.lryc.cn/news/261749.html

相关文章:

  • 华为配置基本QinQ示例
  • 【漏洞复现】系列集合
  • TCP报文头(首部)详解
  • 第4章-第1节-初识Java的数组
  • 大数据技术10:Flink从入门到精通
  • IDEA中工具条中的debug按钮不能用了显示灰色
  • 【MySQL内置函数】
  • C++相关闲碎记录(14)
  • 18、vue3(十八):菜单权限,按钮权限,打包,发布nginx
  • 04 在Vue3中使用setup语法糖
  • vite+ts——user.ts——ts接口定义+axios请求的写法
  • 环境搭建及源码运行_java环境搭建_mysql安装
  • Android camera的metadata
  • ElasticSearch面试题
  • C++ 数据结构知识点合集-C/C++ 数组允许定义可存储相同类型数据项的变量-供大家学习研究参考
  • 【机器学习】5分钟掌握机器学习算法线上部署方法
  • Vue3-21-组件-子组件给父组件发送事件
  • [密码学]AES
  • CentOS 7 部署pure-ftp
  • Vue2-动态组件案例
  • 【源码】车牌检测+QT界面+附带数据库
  • 实战1-python爬取安全客新闻
  • 光栅化渲染:可见性问题和深度缓冲区算法
  • docker入门小结
  • LLM Agent发展演进历史(观看metagpt视频笔记)
  • Linux(操作系统)面经——part2
  • Flink系列之:WITH clause
  • JMeter直连数据库
  • Linux部署MySQL5.7和8.0版本 | CentOS和Ubuntu系统详细步骤安装
  • STL中set和multiset容器的用法(轻松易懂~)