spring security之Remember Me
2021-07-01 20:04
标签:inter struct tail pattern osi handler 退出 out for spring-security.xml配置 环境: spring版本:5.0.7.RELEASE spring-security.xml引入: 1、添加以下remember-me服务需要的bean: 2、 添加你的 包括 并添加 详细如下: spring security之Remember Me 标签:inter struct tail pattern osi handler 退出 out for 原文地址:https://www.cnblogs.com/amunamuna/p/9636360.htmlhttp://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd
beans:bean id="myRememberMeAuthenticationProvider" class=
"org.springframework.security.authentication.RememberMeAuthenticationProvider">
beans:constructor-arg name="key" value="xxxxxxxx"/>
beans:bean>
beans:bean id="myRememberMeAuthenticationFilter" class=
"org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
beans:constructor-arg name="rememberMeServices" ref="myRememberMeServices"/>
beans:constructor-arg name="authenticationManager" ref="authenticationManager" />
beans:bean>
beans:bean id="myRememberMeServices" class=
"org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices">
beans:constructor-arg name="key" value="xxxxxxxx"/>
beans:constructor-arg name="userDetailsService" ref="myUserDetailService"/>
beans:constructor-arg name="tokenRepository" ref="myPersistentTokenRepository"/>
beans:property name="tokenValiditySeconds" value="86400"/>
beans:bean>
beans:bean id="myPersistentTokenRepository" class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl">
beans:property name="dataSource" ref="dataSource"/>
beans:bean>
RememberMeServices
实现UsernamePasswordAuthenticationFilter.setRememberMeServices()
的属性RememberMeAuthenticationProvider
在AuthenticationManager.setProviders()
中的列表,RememberMeAuthenticationFilter
到你的FilterChainProxy
(一般在你的UsernamePasswordAuthenticationFilter
之后) http auto-config="false" use-expressions="true" entry-point-ref="myLoginUrlAuthenticationEntryPoint">
intercept-url pattern="/**" access="authenticated"/>
custom-filter ref="loginAuthenticationFilter" position="FORM_LOGIN_FILTER"/>
custom-filter ref="myRememberMeAuthenticationFilter" position="REMEMBER_ME_FILTER"/>
logout logout-url="/logout"
logout-success-url="/login"
invalidate-session="true"
delete-cookies="JSESSIONID"/>
session-management invalid-session-url="/login">
concurrency-control max-sessions="1"/>
session-management>
csrf disabled="true" />
http>
beans:bean id="loginAuthenticationFilter"
class="com.example.demo.web.security.MyUsernamePasswordAuthenticationFilter">
beans:property name="usernameParameter" value="name"/>
beans:property name="passwordParameter" value="pass"/>
beans:property name="filterProcessesUrl" value="/signin"/>
beans:property name="authenticationSuccessHandler" ref="myAuthenticationSuccessHandler"/>
beans:property name="authenticationFailureHandler" ref="myAuthenticationFailureHandler"/>
beans:property name="authenticationManager" ref="authenticationManager"/>
beans:property name="rememberMeServices" ref="myRememberMeServices"/>
beans:bean>
authentication-manager alias="authenticationManager">
authentication-provider ref="myDaoAuthenticationProvider"/>
authentication-provider ref="myRememberMeAuthenticationProvider"/>
authentication-manager>
上一篇:A Guide to Python's Magic Methods
下一篇:解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误
文章标题:spring security之Remember Me
文章链接:http://soscw.com/essay/100459.html