开发者社区 > 云原生 > 正文

使用者项目的AuthorityRule上下文.getOrigin()为null

我有一个问题。 我使用这个权威规则来保护我的项目的配音服务。 但另一个项目不使用sentinel,也从不导入sentinel dubbo适配器。 所以在我的项目调试点方法AuthorityRuleChecker-passCheck中:

class AuthorityRuleChecker { static boolean passCheck(AuthorityRule rule, Context context) { String requester = context.getOrigin(); // Empty origin or empty limitApp will pass. if (StringUtil.isEmpty(requester) || StringUtil.isEmpty(rule.getLimitApp())) { return true; } }

我发现这个请求者的值为null。因为{getOrigin}来自dubbo附件{dubboApplication} dubbo jar从不使用此附件。 所以我必须在另一个项目中导入sentinel dubbo适配器才能获得{dubboApplication}。 否则,它将不会在所有AuthorityRule中使用

public static final String SENTINEL_DUBBO_APPLICATION_KEY = "dubboApplication"; public static String getApplication(Invocation invocation, String defaultValue) { if (invocation == null || invocation.getAttachments() == null) { throw new IllegalArgumentException("Bad invocation instance"); } return invocation.getAttachment(SENTINEL_DUBBO_APPLICATION_KEY, defaultValue); } }

中文意思是:为什么要用dubboApplication这个属性来获取dubbo name,如果客户端没有引入sentinel的dubbo适配包,这里永远为空,加上判断,永远进不去AuthorityRuleChecker 这段逻辑. 我认为应该去的StringUtil.isEmpty(requester),否则会漏掉其他没有适配到的包.因为不一定每个项目都会引入这个包.所以配置了黑白名单,还是有其他系统能调用到服务端接口的.

这一点想请教一下这样设计的目的是为什么呢?盼复,Thanks♪(・ω・)ノ

原提问者GitHub用户cookiejoo

展开
收起
云上静思 2023-05-19 16:45:01 1410 0
1 条回答
写回答
取消 提交回答
  • 在我看来,这个适配器只是可能的实现之一,并且仅适用于成对集成的sentinel-dubo适配器。

    对于那些我们不想引入适配器的消费者,我们可以自己填充附件(遵循原则),或者我们可以随意实现一个全新的适配器。

    原回答者GitHub用户jasonjoo2010

    2023-05-19 22:43:30
    赞同 展开评论 打赏
问答标签:
问答地址:

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载