给spring security添加remember me function

1.如果不是自己重新复写了 userDetailsService 那么添加remember me 很简单

<http auto-config="true">
    ......
   <remember-me key="HedahaiSetThisKey" />
</http>


 

 2.如果你自己复写了 userDetailsService那么添加remember me 需要自己写filter

<http>
    ......
   <remember-me key="HedahaiSetThisKey" />
</http>

<beans:bean id="rememberMeServices"
	class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices">
	<beans:property name="userDetailsService" ref="userDetailsService" />
	<beans:property name="key" value="HedahaiSetThisKey" />
</beans:bean>

<beans:bean id="rememberMeAuthenticationProvider"
	class="org.springframework.security.providers.rememberme.RememberMeAuthenticationProvider">
	<beans:property name="key" value="HedahaiSetThisKey" />
</beans:bean>

<beans:bean id="authenticationProcessingFilter"
	class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter">
	<beans:property name="filterProcessesUrl">
            <beans:value>/loginPage.jsp</beans:value> 
        </beans:property>
        <beans:property name="authenticationFailureUrl">
            <beans:value>/loginPage.jsp?error=true</beans:value> 
        </beans:property>
        <beans:property name="defaultTargetUrl">
            <beans:value>/index.jsp</beans:value> 
        </beans:property>
	<beans:property name="authenticationManager">
		<beans:ref bean="authenticationManager" />
	</beans:property>
	<beans:property name="rememberMeServices">
                <beans:ref bean="rememberMeServices" />
        </beans:property>
</beans:bean>
	
<beans:bean id="rememberMeProcessingFilter"
        class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter">
        <beans:property name="rememberMeServices" ref="rememberMeServices" />
        <beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>

<beans:bean id="authenticationManager"
	class="org.springframework.security.providers.ProviderManager">
	<beans:property name="providers">
		<beans:list>
			<beans:ref local="daoAuthenticationProvider" />
			<beans:ref local="rememberMeAuthenticationProvider" />
		</beans:list>
	</beans:property>
</beans:bean>

<beans:bean id="userDetailsService" class="com.mis.bean.UserDetailsServiceImpl">
	<beans:constructor-arg ref="userRepository" />
</beans:bean>

<beans:bean id="passwordEncoder"
        class="org.springframework.security.providers.encoding.Md5PasswordEncoder" />

<beans:bean id="daoAuthenticationProvider"
	class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
	<beans:property name="userDetailsService" ref="userDetailsService" />
	<beans:property name="passwordEncoder">
		<beans:ref local="passwordEncoder" />
	</beans:property>
</beans:bean>

以上配置都是基于2.0的配置,如果是3.0 包的位置不一样 请参考文档

你可能感兴趣的:(spring,jsp,bean,UI,Security)