2014-05-23 29 views
1

我在基於Spring MVC的Web應用程序中設置了Spring Security。但由於某些外部系統限制,我希望用戶roles爲小寫。Spring Security:不區分大小寫的角色

但是測試使用本地內存中時,用戶,應用程序只允許在身份驗證的用戶UPPER_CASE具有角色的訪問,並儘快更改角色爲小寫給403。

有沒有這樣的限制有隻在大寫的角色。我在文檔中找不到任何提及的內容?

我還發現有關屬性lowercase-comparisonsfilter-invocation-definition-source ..這是爲了比較URL或角色?

下面是FilterSecurityInterceptor定義:

<bean id="fsi" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> 
    <property name="authenticationManager" ref="authenticationManager" /> 
    <property name="accessDecisionManager" ref="accessDecisionManager" /> 
    <property name="objectDefinitionSource"> 
     <sec:filter-invocation-definition-source lowercase-comparisons="true"> 
      <sec:intercept-url pattern="/logout.jsp"   access="ROLE_ANONYMOUS" /> 
      <sec:intercept-url pattern="/welcome.htm"   access="ROLE_executer,ROLE_viewer,ROLE_admin_user" /> 

      <!-- Write Access --> 
      <sec:intercept-url pattern="/addNewRecord.htm"  access="ROLE_executer,ROLE_admin_user" /> 
      <sec:intercept-url pattern="/updateRecord.htm"  access="ROLE_executer,ROLE_admin_user" /> 
      <sec:intercept-url pattern="/deleteRecord.htm"  access="ROLE_executer,ROLE_admin_user" /> 
      <sec:intercept-url pattern="/uploadFile.htm"  access="ROLE_executer,ROLE_admin_user" /> 

      <!-- Read Access to All Other--> 
      <sec:intercept-url pattern="/**"     access="ROLE_executer,ROLE_viewer,ROLE_admin_user"/>       
     </sec:filter-invocation-definition-source> 
    </property> 
</bean> 

感謝您的幫助。

回答

2

角色不一定是大寫。但是,在正常配置中,RoleVoter會查找區分大小寫的前綴ROLE_。見this FAQ

您可以將角色選舉器配置爲具有空白前綴(或小寫,如果這是您想要的),或者您可以使用基於表達式的訪問 - 請參閱this answer。看到this answer -

或者,你可以用一個GrantedAuthoritiesMapper其角色從外部系統將其轉換爲可以通過Spring Security的RoleVoter消耗值配置AuthenticationProvider

+0

這是正確的。值得指出的另一件事是,這些「角色」不是典型意義上的角色(角色/特權)。這些僅僅是以String表示的GrantedAuthority。 RoleVoter檢查用戶授權中是否存在這些授權的權限。 – Shailendra

+0

如果你想要他們,他們可以是「典型的角色」。 'GrantedAuthority'只是一個內部接口,它的含義取決於選民。 'RoleVoter'只是將字符串表示與爲URL或安全方法列出的訪問控制屬性進行比較,這是對應用程序中基於角色訪問的典型解釋。 –