2010-08-08 120 views
7

ROLE_USER和ROLE_ANONYMOUS在Spring攔截url配置(如下例)中有什麼區別?在Spring攔截url配置中,ROLE_USER和ROLE_ANONYMOUS有什麼區別?

<http auto-config="false" access-decision-manager-ref="accessDecisionManager" 
    use-expressions="true"> 
    <intercept-url pattern="/admin/**" access="hasRole('ROLE_ANONYMOUS')" 
     requires-channel="http" /> 
    <intercept-url pattern="/login/**" access="hasRole('ROLE_ANONYMOUS')" 
     requires-channel="${application.secureChannel}" /> 
    <intercept-url pattern="/error/**" access="hasRole('ROLE_ANONYMOUS')" 
     requires-channel="http" /> 
    <intercept-url pattern="/register/**" access="hasRole('ROLE_ANONYMOUS')" 
     requires-channel="${application.secureChannel}" /> 
    <intercept-url pattern="/" access="hasRole('ROLE_ANONYMOUS')" 
     requires-channel="http" /> 
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" 
     requires-channel="http" /> 
    <form-login login-page="/login" login-processing-url="/login/submit" 
     authentication-failure-url="/login/error" /> 
    <logout logout-url="/logout" /> 
</http> 

回答

13

ROLE_ANONYMOUS配置我的解釋是分配給一個未認證用戶(匿名)用戶的默認角色時,配置使用Spring Security的"anonymous authentication" filter。這是默認啓用的。但是,如果使用表達式isAnonymous(),則它可能會更清晰一些,它們的含義相同。

ROLE_USER沒有意義,除非您的用戶在通過身份驗證(您負責爲已驗證的用戶加載角色(權限))時將此角色分配給您的用戶。這不是Spring Security基礎架構的名稱。在給定的例子中,假設該角色被分配給經過認證的用戶。

1

ROLE_ANONYMOUS沒有用戶憑證,ROLE_USER有用戶憑證...已經過驗證。

這是基於提供