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

网站后台管理需求上海seo优化培训机构

网站后台管理需求,上海seo优化培训机构,wordpress修改语言设置,wordpress 二次验证失败在Spring框架中,可以使用面向切面编程(AOP)来实现注解鉴权。这通常涉及到定义一个切面(Aspect),该切面会在方法执行前进行拦截,并根据注解value值来决定是否允许执行该方法。 简单思路&#xf…

在Spring框架中,可以使用面向切面编程(AOP)来实现注解鉴权。这通常涉及到定义一个切面(Aspect),该切面会在方法执行前进行拦截,并根据注解value值来决定是否允许执行该方法。

简单思路:

权限标识如:"business:project:list" 字段保存在菜单表,用户表与菜单表关联。如果自定义注解中的参数值@RequiresPermissions("business:project:list") 存在于当前用户所拥有的权限中,则该请求允许访问该方法,否则拒绝。

首先,需要定义一个注解 RequiresPermissions

/*** 权限认证:必须具有指定权限才能进入该方法* * @author digipower**/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface RequiresPermissions {/*** 需要校验的权限码*/String[] value() default {};}

然后,你需要定义一个切面,该切面会拦截带有 @RequiresPermissions 注解的方法

import java.lang.reflect.Method;import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;import com.digipower.component.security.annotation.RequiresLogin;
import com.digipower.component.security.annotation.RequiresPermissions;
import com.digipower.component.security.annotation.RequiresRoles;
import com.digipower.component.security.auth.AuthUtil;/*** 基于 Spring Aop 的注解鉴权*/
@Aspect
@Component
public class AuthAspect {/** 权限标识 */private static final String ALL_PERMISSION = "*:*:*";/*** 构建*/public AuthAspect() {}/*** 声明AOP签名*/@Pointcut(@annotation(com.bibo.test.RequiresPermissions))public void pointcut() {}/*** 环绕切入*/@Around("pointcut()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable {// 获取签名MethodSignature signature = (MethodSignature)joinPoint.getSignature();// 校验 @RequiresPermissions 注解RequiresPermissions requiresPermissions = signature.getMethod().getAnnotation(RequiresPermissions.class);if (requiresPermissions != null) {// 获取当前用户的全部权限,可以从redis、Spring Security安全上下文等Set<String> permissionSet = getXX();for (String permission : requiresPermissions.value()) {if (!hasPermission(permissionSet, permission)) {throw new NotPermissionException(permission);}}}try {// 执行原有逻辑Object obj = joinPoint.proceed();return obj;} catch (Throwable e) {throw e;}}/*** 判断是否包含权限* * @param authorities*            权限列表* @param permission*            权限字符串* @return 用户是否具备某权限*/public boolean hasPermission(Collection<String> authorities, String permission) {return authorities.stream().filter().anyMatch(x -> ALL_PERMISSION.contains(x) || PatternMatchUtils.simpleMatch(x, permission));}
}

最后,在你的服务或控制器中,你可以使用

@RequiresPermissions注解来标记需要进行鉴权的方法

/*** 查询列表*/
@RequiresPermissions("business:project:list")
@GetMapping("/list")
public PageDataResult list(BizInfo bizInfo) {...return ..
}

这样,每当 list 方法被调用时,AuthAspect 会进行鉴权检查。如果鉴权失败,将抛出异常或返回错误信息,阻止方法的执行。

http://www.hkea.cn/news/277679/

相关文章:

  • 廊坊网站建大型网站建站公司
  • 远程桌面做网站sem和seo区别与联系
  • 做贷款网站优化大师有用吗
  • 有没有便宜的网站制作制作网页教程
  • 医院网站制作优化关键词的方法有哪些
  • wordpress安装到网站吗泰安seo
  • 长春网站开发培训价格google play三件套
  • 做生存分析的网站有哪些国外新闻最新消息
  • 济南网站优化收费百度互联网营销
  • bootstrap响应网站模板下载发帖推广百度首页
  • 动态网站上的查询怎么做新媒体运营培训学校
  • 网站开发人员必备技能百度优化推广
  • 花都 网站建设百度推广怎么添加关键词
  • 开发公司成本部职责岗位职责和流程苏州网站建设优化
  • 湛江网站制作系统seo排名需要多少钱
  • 城乡现代社区建设seo关键词推广案例
  • 旅游网站开发外文文献关键洞察力
  • 大学生asp网站开发的实训周长沙百度快速优化
  • 黑龙江省建设网站百度投流运营
  • 网站关键词太多好不好兰州seo整站优化服务商
  • 义乌网站设计网店推广策划方案
  • 无锡网站优化工作室网站关键词排名优化推广软件
  • 长沙做网站的公司亚马逊seo什么意思
  • 仪征建设银行官方网站怎么优化一个网站
  • 那个网站可以查询美做空基金宁波网站推广平台效果好
  • 杨凌企业网站建设天津seo优化
  • 建设网站的工具免费b站在线观看人数在哪儿
  • 毕业设计餐饮网站建设国内前10电商代运营公司
  • 日本b2b网站市场调研的步骤
  • 强企网做网站网店推广有哪些