gpt4 book ai didi

java - Spring security拦截url将模式参数传递给访问方法

转载 作者:行者123 更新时间:2023-12-02 07:18:46 24 4
gpt4 key购买 nike

在 Spring Security 中,我们可以使用以下构造来限制对某些 Web 资源的访问: <intercept-url pattern="/admin.xhtml" access="hasPermission('admin')" />

现在,我有很多页面,要访问每个页面,应该具有与页面名称相同的特殊权限。 intercept-url接受模式,但似乎不提供从 pattern 中的正则表达式匹配组传递参数至access 。我想要这样的东西:

<intercept-url pattern="/([a-z]+).xhtml" access="hasPermission('$1')" />

最佳答案

遗憾的是,您无法在访问规则中使用匹配的正则表达式组。作为解决方法,您可以尝试定义自定义 Web 安全表达式。它将负责提取一些匹配的正则表达式组:

<intercept-url pattern="/([a-z]+).xhtml" access="hasPermission(extractGroup('$1', '/([a-z]+).xhtml'))" />

在执行期间extractGroup(...)方法将能够使用当前的HttpRequest。这个解决方案有两个缺点:1)做起来并不那么简单2)正则表达式模式将在您的conf.d文件中重复。如果您觉得合适,那么您可以阅读如何添加自定义 Web 安全表达式 here .

关于java - Spring security拦截url将模式参数传递给访问方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14545341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com