【问题标题】:apache shiro url config for path variable路径变量的 apache shiro url 配置
【发布时间】:2020-05-30 01:46:52
【问题描述】:

我有一个弹簧控制器,如下所示:

@Controller
@RequestMapping("/tickets")
public class TicketWeb {

    @GetMapping("/{ticketNo}")
    ...

    @GetMapping("/a")

    @GetMapping("/b")

    @PostMapping("/c")

    //maybe more fixed path mapping
}

在这个控制器中,我有一个path variable,比如/{ticketNo},其他的都是固定路径。

对于 apache shiro,我只希望 annon 用于路径变量,所有其他固定路径都是 authc

根据apache shiro doc,似乎只有两种解决方案可以实现我的目标:

选项 1 是:

filterChainDefinitionMap.put("/tickets/a","authc");
filterChainDefinitionMap.put("/tickets/b","authc");
filterChainDefinitionMap.put("/tickets/c","authc");

filterChainDefinitionMap.put("/tickets/*","annon");

即明确地将fixed path 设置为authc,将path variable 设置为annon,但这并不好,因为将来可能会有一些fixed path 或添加更多fixed path

选项 2 是将路径变量 /{ticketNo} 更改为另一个,例如/annon/{ticketNo},区分固定路径,方便开发者设置

filterChainDefinitionMap.put("/tickets/annon/*","annon");

filterChainDefinitionMap.put("/tickets/*","authc");

只有两行。

所以只有这两种解决方案可以实现我的目标,对吗?

【问题讨论】:

    标签: shiro


    【解决方案1】:

    Shiro 使用 Ant 样式的模式匹配,请参阅:https://shiro.apache.org/static/1.5.0/apidocs/org/apache/shiro/util/AntPathMatcher.html 获取一些示例。

    【讨论】:

    • 是的,我查看了官方文档,但似乎我必须更改路径才能实现我的意图,即我的帖子中的option 2,对吧?
    猜你喜欢
    • 1970-01-01
    • 2019-06-29
    • 2016-09-28
    • 2017-01-22
    • 2012-10-20
    • 2017-09-08
    • 1970-01-01
    • 2019-07-25
    • 2011-08-18
    相关资源
    最近更新 更多