所以我想在Spring Social Showcase-Sec-XML示例中添加一个remember-me功能。所以我想让它成为一个持久的记住我,但每当我将数据源添加到remember-me时,我都会收到错误。
这是我在security.xml中的代码
<http use-expressions="true">
<!-- Authentication policy -->
<form-login login-page="/signin" login-processing-url="/signin/authenticate" authentication-failure-url="/signin?param.error=bad_credentials" />
<logout logout-url="/signout" delete-cookies="JSESSIONID" />
<intercept-url pattern="/favicon.ico" access="permitAll" />
<intercept-url pattern="/resources/**" access="permitAll" />
<intercept-url pattern="/auth/**" access="permitAll" />
<intercept-url pattern="/signin/**" access="permitAll" />
<intercept-url pattern="/signup/**" access="permitAll" />
<intercept-url pattern="/disconnect/facebook" access="permitAll" />
<intercept-url pattern="/**" access="isAuthenticated()" />
<remember-me key="jbcpCalendar"
data-source-ref="dataSource"/>
<!-- Spring Social Security authentication filter -->
<custom-filter ref="socialAuthenticationFilter" before="PRE_AUTH_FILTER" />
</http>
这是给出错误的socialAuthenticationFilter bean。
<bean id="socialAuthenticationFilter" class="org.springframework.social.security.SocialAuthenticationFilter"
c:_0-ref="authenticationManager"
c:_1-ref="userIdSource"
c:_2-ref="usersConnectionRepository"
c:_3-ref="connectionFactoryLocator"
p:signupUrl="/spring-social-showcase/signup"
p:rememberMeServices-ref="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0" /> <!-- TODO: Figure out how to wire this without this name -->
这是出现的堆栈跟踪):
Cannot resolve reference to bean 'socialAuthenticationFilter' while setting
constructor argument with key [2]; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'socialAuthenticationFilter'
defined in ServletContext resource [/WEB-INF/spring/social-security.xml]: Cannot
resolve reference to bean
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0'
while setting bean property 'rememberMeServices'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named
'org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices#0' is defined
有没有办法让它在常规登录时使用持久性记住我?
答案 0 :(得分:1)
我认为你必须在配置了remembermeservices的命名空间上添加一个别名:
<remember-me services-alias="toto"
key="jbcpCalendar"
data-source-ref="dataSource"/>
使用socialAuthenticationFilter配置中的别名引用它:
<bean id="socialAuthenticationFilter" class="org.springframework.social.security.SocialAuthenticationFilter"
c:_0-ref="authenticationManager"
c:_1-ref="userIdSource"
c:_2-ref="usersConnectionRepository"
c:_3-ref="connectionFactoryLocator"
p:signupUrl="/spring-social-showcase/signup"
p:rememberMeServices-ref="toto" />