2011-07-04 51 views
1

我需要使用2層來保護我的網站。首先是LDAP檢查,其次是用戶名/密碼條目。我爲這兩項檢查都編寫了自定義身份驗證過濾器。Spring Security中的累積過濾器3

如果LDAP篩選失敗,用戶應該被重定向到「拒絕訪問」頁面,如果用戶名/密碼失敗,用戶應該被重定向回登錄頁面。

如何在我的config.xml文件中設置這些過濾器?下面是我目前

<sec:http entry-point-ref="loginAuthenticationEntryPoint" 
    auto-config="false" use-expressions="true"> 
    <sec:intercept-url pattern="/login.htm" access="isAnonymous()" /> 
    <sec:intercept-url pattern="/*" 
     access="hasRole('ROLE_LDAP') and hasRole('ROLE_CRESTA')" /> 

    <sec:custom-filter ref="ldapAuthenticationFilter" 
     before="FORM_LOGIN_FILTER" /> 
    <sec:custom-filter ref="usernameAuthenticationFilter" 
     position="FORM_LOGIN_FILTER" /> 
</sec:http> 

public class LdapAuthenticationFilter extends AbstractPreAuthenticatedProcessingFilter 

public class CrestaUsernameAuthenticationFilter extends AbstractAuthenticationProcessingFilter 

我現在的想法是每個過濾器添加所需的角色之一,但是當LDAP過濾器沒有按不會添加這兩個角色,我立即拒絕訪問。

非常感謝

回答

0

我認爲這種做法是行不通的,因爲只要你的LDAP過濾器成功返回,春季安全考慮用戶已經完全驗證,並跳過用戶名/密碼過濾器。

在你的情況下,我會使用標準的表單登錄安全性,自定義我的UserDetailsS​​ervice,以便不用去Cresta創建UserDetails實例,它也會查詢你的LDAP服務器以獲取用戶角色。

+0

謝謝,這幾乎是我最終做的 – davecass

相關問題