2013-03-30 109 views
1

我一直在試圖實現春季安全3.0記得我在我的應用程序的服務,但不幸的是無法得到它的工作。春季安全3.0記得我功能

我沒有找到任何與此相關的具體示例,即使在春季文檔中也沒有。如果有人能夠給出一個可用的示例代碼,那將會很好。請查找我的spring-security.xml文件的代碼。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:security="http://www.springframework.org/schema/security" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 


<security:http entry-point-ref="myAuthenticationEntryPoint"> 

    <security:session-management 
     session-fixation-protection="newSession" /> 
    <security:custom-filter position="FORM_LOGIN_FILTER" 
     ref="processingFilter" /> 
    <security:logout logout-url="/logout" 
     logout-success-url="/login" /> 
    <security:intercept-url pattern='/index.jsp' 
     filters='none' /> 
    <security:intercept-url pattern='/login*' 
     filters='none' /> 
    <security:remember-me key="springrocks" /> 

    <security:intercept-url pattern='/admin/**' 
     access="ROLE_ADMIN" /> 

</security:http> 

<security:authentication-manager> 
    <security:authentication-provider 
     ref="myAuthenticationProvider"></security:authentication-provider> 
</security:authentication-manager> 
<bean id="myAuthenticationProvider" 
    class="example.AuthenticationProviderExtended"> 

</bean> 

<bean id="authenticationManager" class="example.AuthenticationManagerExtended" /> 

<bean id="processingFilter" class="example.FormBasedProcessingFilter"> 
    <property name="authenticationManager" ref="authenticationManager" /> 
    <property name="usernameParameter" value="username" /> 
    <property name="passwordParameter" value="password" /> 
    <property name="allowSessionCreation" value="true" /> 
    <property name="authenticationFailureHandler" ref="simpleUrlAuthenticationFailureHandler" /> 
    <property name="authenticationSuccessHandler" ref="simpleUrlAuthenticationSuccessHandler" /> 
    <property name="filterProcessesUrl" value="/performLogin" /> 
</bean> 


<bean id="simpleUrlAuthenticationFailureHandler" class="example.AuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/login"></property> 
</bean> 

<bean id="simpleUrlAuthenticationSuccessHandler" 
    class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"> 
    <property name="defaultTargetUrl" value="/home" /> 
</bean> 


<bean id="myAuthenticationEntryPoint" 
    class="example.CustomAuthenticationEntryPoint"> 
    <property name="loginFormUrl" value="/login" /> 
</bean> 

<bean id="rememberMeFilter" 
    class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter"> 
    <property name="rememberMeServices" ref="rememberMeServices" /> 
    <property name="authenticationManager" ref="authenticationManager" /> 
</bean> 

<bean id="rememberMeServices" 
    class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices"> 
    <property name="userDetailsService" ref="myUserDetailsService" /> 
    <property name="key" value="springRocks" /> 
</bean> 

<bean id="rememberMeAuthenticationProvider" 
    class="org.springframework.security.authentication.RememberMeAuthenticationProvider"> 
    <property name="key" value="springRocks" /> 
</bean> 

<bean id="myUserDetailsService" class="example.MyCustomeUserDetailsService"> 

</bean> 

</beans> 
+0

如果它回答你的問題,你可以接受和促進我的答案:) – Michael

回答

0

你需要確保你的表單包含一個複選框(或其他類型的輸入)的記得我屬性名稱

<input type="checkbox" name="_spring_security_remember_me"/> 

此屬性可通過xml上的記憶 - 參數進行配置,例如:

<remember-me remember-me-parameter="please_remember"/>