Spring 安全拦截-url 的具体工作原理是什么?

How exactly works the Spring Security intercept-url's?

我正在研究 Spring 安全性,我发现在理解 拦截-url 的 概念并回答我在研究中发现的这个问题 material:

In which order do you have to write multiple intercept-url's?

所以,在我的研究中material,我发现了这个实际例子:

<beans>
    <security:http>
        <security:intercept-url pattern="/accounts/edit*"
access="ROLE_ADMIN" />
        <security:intercept-url pattern="/accounts/account*"
access="ROLE_ADMIN,ROLE_USER" />
        <security:intercept-url pattern="/accounts/**"
access="IS_AUTHENTICATED_FULLY" />
        <security:intercept-url pattern="/customers/**"
access="IS_AUTHENTICATED_ANONYMOUSLY" />
    </security:http>
</beans>

并指定:

intercept-urls are evaluated in the order listed: first match is used, put specific matches first.

但是究竟是什么意思呢?

所以我知道security命名空间的intercept-url's用来定义什么URL 是安全的(如果我断言错误,请纠正我)。

所以在前面的例子中这些 URLs:

但是究竟是什么代表了以下访问角色?

例如对于/accounts/edit* URL指定了access="ROLE_ADMIN"

/accounts/account*URL指定了access="ROLE_ADMIN,ROLE_USER"

等等。究竟是什么意思?我认为这意味着,但我绝对不确定,如果用户尝试访问 /accounts/edit* 如果他尝试访问则必须是管理员访问 /accounts/account* 可以是管理员,也可以是普通用户。

这个解释对还是不对?

如果它是正确的,我如何指定用户 "belong" 到 ROLE_ADMINROLE_USER?具体代表什么,在哪里定义的?

intercept-urls 的确切含义是按列出的顺序进行评估:使用第一个匹配项,将特定匹配项放在首位 ?

角色可由您任意定义,并为每个角色设置您喜欢的权限访问权限。

截距 URL 需要从最具体到最不具体的顺序列出,因为如果你把最不具体的放在前面,就像这样:

模式=“/foo/bar/**” pattern="/foo/bar/baz*"

当有人导航到 /foo/bar/baz 时,来自 /foo/bar 的权限设置将被应用,因为它在拦截列表 URL 中首先匹配。这需要开发人员付出更多的努力,但比匹配列表中每个 URL 的精确字符串要快。希望这有帮助。