4

我已经看到 Spring Security OAuth2 示例spring-servlet.xml

   <http pattern="/users/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
      access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security">
    <anonymous enabled="false" />
    <intercept-url pattern="/photos" access="ROLE_USER,SCOPE_READ" />
    <intercept-url pattern="/photos/trusted/**" access="ROLE_CLIENT,SCOPE_TRUST" />
    <intercept-url pattern="/photos/user/**" access="ROLE_USER,SCOPE_TRUST" />
    <intercept-url pattern="/photos/**" access="ROLE_USER,SCOPE_READ" />
    <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
    <access-denied-handler ref="oauthAccessDeniedHandler" />
</http>

标签中的pattern属性是否有效?http我在spring-security-2.0.1.xsd. 如果有效,这个模式与intercept-url'pattern属性有什么关系?举个例子,拦截路径/photos/user/**是否有最终匹配的拦截路径/users/photos/user/**?谢谢。

4

2 回答 2

8

pattern属性是在3.1中引入的,它引入了对多个过滤器链的命名空间支持。Spring Security 2 已经过时了(你不应该使用它)。

元素中的模式intercept-url是独立的,因为它们与传入请求 URI 的匹配方式与http检查过滤器链模式的方式相同。但是,如果后者不匹配,则过滤器链将根本不会应用于请求,因此为了产生任何效果,它们必须与过滤器链模式一致。

对于您发布的示例,这意味着所有/photos模式都没有任何效果。它们都应该具有主过滤器链匹配的前缀 - 即它们应该以 . 开头/users/photos

于 2014-10-03T16:57:30.103 回答
1

在spring security 4的情况下,通过haseRole('ADMIN')检查Role,试试看。

这对我来说可以。

于 2016-03-21T04:41:49.123 回答