2011-09-07 61 views
1

我正在使用GWT和spring安全性。我有一個自定義身份驗證提供程序,我執行所有身份驗證。如何在不使用UserDetailsS​​ervice的情況下配置記住我功能?我沒有使用LDAP。Spring Security使用自定義身份驗證提供程序記住我

我AppliationContext_security.xml

<http auto-config="true" entry-point-ref="UnauthorizedEntryPoint" 
    create-session="always"> 
    <form-login authentication-success-handler-ref="authenticationSuccessHandler" 
     authentication-failure-handler-ref="authenticationFailureHandler" /> 
    <logout success-handler-ref="logoutSuccessHandler" 
     invalidate-session="true" /> 
    <intercept-url pattern="/**/myapp.rpc" access="ROLE_USER" /> 

    <custom-filter before="CONCURRENT_SESSION_FILTER" ref="XSRFAttackFilter" /> 

</http> 

<authentication-manager>   
    <authentication-provider ref="myAuthenticationProvider" /> 
</authentication-manager> 

在我的自定義身份驗證提供者,

@Override 
public Authentication authenticate(Authentication authentication) 
     throws AuthenticationException { 
    String username = (String) authentication.getPrincipal(); 
    String password = (String) authentication.getCredentials(); 

    boolean response = loginmanager.authenticateUser(username, password, 
      ((ServletRequestAttributes) RequestContextHolder 
        .getRequestAttributes()).getRequest().getSession()); 
    if (!response) { 
     throw new BadCredentialsException(
       "Invalid Credentials."); 
    } 

    Authentication authentication = ... 
    authentication.setAuthenticated(true); 

    return authentication; 
} 

任何幫助將不勝感激。

回答

0

您將需要創建一個自定義UserDetailsService,從loginmanager正在讀取它的同一位置獲取用戶名/密碼。查看TokenBasedRememberMeServices.processAutoLoginCookie()的來源,看看它是如何使用的。

相關問題