weixin_43966397 2022-11-24 15:27
浏览 13
已结题

oauth2.hasAnyScope之上下文为空问题疑问

问题遇到的现象和发生背景

学习博主这篇文章时(https://blog.csdn.net/qq_43437874/article/details/121552989) ,自身代码出现以下问题

Attempted to call method hasAnyScope(java.lang.String,java.lang.String,java.lang.String) on null context object

用代码块功能插入代码,请勿粘贴截图

org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method hasAnyScope(java.lang.String,java.lang.String,java.lang.String) on null context object
at org.springframework.expression.spel.ast.MethodReference.throwIfNotNullSafe(MethodReference.java:154) ~[spring-expression-5.3.23.jar:5.3.23]
at org.springframework.expression.spel.ast.MethodReference.getValueRef(MethodReference.java:83) ~[spring-expression-5.3.23.jar:5.3.23]
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:70) ~[spring-expression-5.3.23.jar:5.3.23]
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:91) ~[spring-expression-5.3.23.jar:5.3.23]

我的解答思路和尝试过的方法

这样设置时可以达到效果,但是用
http.authorizeRequests(). antMatchers("/*").access("#oauth2.hasAnyScope('access')")
这样不行

@PreAuthorize(value = "#oauth2.hasAnyScope('servera','access','serverc')")
    //@PreAuthorize("hasRole('access')" )
    //@PreAuthorize("hasAuthority('SCOPE_access')")
    //https://blog.csdn.net/qq_39748549/article/details/123847030
    //whose Authority  (token 关联用户的的权限) 使用 内存与数据库的 是否是通过token去找对用用户信息  使用jwt应该是解析
    //jwt的信息 从中获取authority来控制权限  这涉及用户信息 存取方式带来获取方法的不同
    public String resource()
    {
        return "访问到了resource 资源 ";
    }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月2日
    • 创建了问题 11月24日

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看