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

sentinel控制台设置接口授权之后不生效

我在sentinel上设置了授权规则

提问166.png

之后使用浏览器访问,这个授权的黑名单并没有生效

提问167.png

我的代码是这样的 `@RestController public class Function1 {

private final Logger logger = LoggerFactory.getLogger(Function1.class);

private static final String GET_SOURCE = "getSource";

@GetMapping("hello") @SentinelResource(value="hello",entryType = EntryType.IN,blockHandler = "blockHandlerForGet") public Msg get(@RequestParam("origin") String origin){ ContextUtil.enter("hello",origin); ContextUtil.exit(); return Msg.success(origin); }

public Msg blockHandlerForGet(@RequestParam("origin") String origin, BlockException ex) {

return Msg.fail();

}

提问168.png

控制台中看得见链路

`@Configuration public class SentinelAspectConfiguration {

@Bean
public SentinelResourceAspect sentinelResourceAspect() {
    return new SentinelResourceAspect();
}

}`

并且也配置了该配置项,可是在创建了对aaa的黑名单后还是无效

原提问者GitHub用户418545106

展开
收起
云上静思 2023-05-19 16:37:52 214 0
1 条回答
写回答
取消 提交回答
  • Context 设置需要在进入埋点前才生效,因此如果需要的话应该在流量入口处调用 ContextUtil.enter(contextName, origin)。若引入了 Web filter,则需要根据 Web 适配的配置来自定义 origin 解析逻辑:https://github.com/alibaba/Sentinel/wiki/主流框架的适配#web-servlet

    也可以参考 FAQ 相关内容:https://github.com/alibaba/Sentinel/wiki/FAQ

    原回答者GitHub用户cdfive

    2023-05-19 22:43:26
    赞同 展开评论 打赏

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

相关电子书

更多
workshop专场-微服务专场-开发者动手实践营-微服务-使用Sentinel进行微服务流量控制 立即下载
Sentinel分布式系统下的流量防卫兵 立即下载
DTS控制台一本通 立即下载