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

Web URL的具体IP的AuthorityRule无效

1、I used sentinel version 1.7.2

2、configured it in the. YML file sentinel: datasource: authority: nacos: server-addr: 127.0.0.1:8848 dataId: ${spring.application.name}-authority-rules rule-type: authority data-type: json

3、Add profile in Nacos named hszsd-ds-crm-service-authority-rules [ { "resource": "/getUserInfo", "limitApp": "172.16.201.214", "strategy": 1 } ]

4、Check the source code 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;
}

// Do exact match with origin name.
int pos = rule.getLimitApp().indexOf(requester);
boolean contain = pos > -1;

if (contain) {
    boolean exactlyMatch = false;
    String[] appArray = rule.getLimitApp().split(",");
    for (String app : appArray) {
        if (requester.equals(app)) {
            exactlyMatch = true;
            break;
        }
    }

    contain = exactlyMatch;
}

int strategy = rule.getStrategy();
if (strategy == RuleConstant.AUTHORITY_BLACK && contain) {
    return false;
}

if (strategy == RuleConstant.AUTHORITY_WHITE && !contain) {
    return false;
}

return true;

}

原提问者GitHub用户hejinrong0602

展开
收起
学习娃 2023-05-19 16:13:59 94 0
1 条回答
写回答
取消 提交回答
  • 参考:https://github.com/alibaba/Sentinel/wiki/FAQ#q-怎么针对特定调用端限流比如我想针对某个-ip-或者来源应用进行限流规则里面-limitapp流控应用的作用

    原回答者GitHub用户sczyh30

    2023-05-19 20:53:50
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:

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

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载