2010-03-16 95 views
1

我一直在试图追查为什么Spring Security没有创建Spring Security记得我cookie(SPRING_SECURITY_REMEMBER_ME_COOKIE)。但是,根据我通过HTTP标头看到的cookie正在设置,只是有一个额外的GET请求/ j_spring_security_check导致下面的异常。这也会导致Cookie被删除。Spring Security - Persistent记住我问题

FINE: Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Authentication method not supported: GET 

我使用Spring 3.0.1,Spring Security 3.0.3 Snapshot和Google App Engine 1.3.1。关于发生了什么的任何想法?

Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter doFilter 
FINE: Request is to process authentication 
Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter unsuccessfulAuthentication 
FINE: Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Authentication method not supported: GET 
Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter unsuccessfulAuthentication 
FINE: Updated SecurityContextHolder to contain null Authentication 
Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter unsuccessfulAuthentication 
FINE: Delegating to authentication failure handlerorg.springframework.se[email protected]4196c169 
Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices loginFail 
FINE: Interactive login attempt was unsuccessful. 
Mar 17, 2010 10:38:35 AM org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices cancelCookie 
FINE: Cancelling cookie 

下面是applicationContext-security.xml的相关部分。

<http auto-config="false"> 
    <intercept-url pattern="/css/**" filters="none" /> 
    <intercept-url pattern="/img/**" filters="none" /> 
    <intercept-url pattern="/js/**" filters="none" /> 
    <intercept-url pattern="/app/admin/**" filters="none" /> 
    <intercept-url pattern="/app/login/**" filters="none" /> 
    <intercept-url pattern="/app/register/**" filters="none" /> 
    <intercept-url pattern="/app/error/**" filters="none" /> 
    <intercept-url pattern="/" filters="none" /> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <logout logout-success-url="/" /> 
    <form-login login-page="/app/login" default-target-url="/" authentication-failure-url="/app/login?login_error=1" /> 
    <session-management invalid-session-url="/app/login" /> 
    <remember-me services-ref="rememberMeServices" key="myKey" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="userDetailsService"> 
     <password-encoder hash="sha-256" base64="true"> 
      <salt-source user-property="username" /> 
     </password-encoder> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="userDetailsService" class="com.my.service.auth.UserDetailsServiceImpl" /> 

<beans:bean id="rememberMeServices" class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices"> 
    <beans:property name="userDetailsService" ref="userDetailsService" /> 
    <beans:property name="tokenRepository" ref="persistentTokenRepository" /> 
    <beans:property name="key" value="myKey" /> 
</beans:bean> 

<beans:bean id="persistentTokenRepository" class="com.my.service.auth.PersistentTokenRepositoryImpl" /> 

下面是我遇到问题的情况下的HTTP标头:

http://localhost:8080/j_spring_security_check 

POST /j_spring_security_check HTTP/1.1 
Host: localhost:8080 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 115 
Connection: keep-alive 
Referer: http://localhost:8080/app/login 
Cookie: JSESSIONID=15t2gq1vo5noj 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 88 
j_username=test%40test.com&j_password=test&_spring _security_remember_me=on&submit=Submit 
HTTP/1.1 302 Found 
Expires: Thu, 01 Jan 1970 00:00:00 GMT 
Set-Cookie: JSESSIONID=1dymxpkh13z32;Path=/ 
Set-Cookie: SPRING_SECURITY_REMEMBER_ME_COOKIE=U05kS2NTakNIZTN Dd0hFcWxqZXRUQT09Oi90M3Q0NTA1czhxSjRadTQ5NW5FQVE9P Q;Path=/;Expires=Wed, 31-Mar-10 10:52:07 GMT 
Location: http://localhost:8080/app/helloWorld 
Content-Length: 0 
Server: Jetty(6.1.x) 
---------------------------------------------------------- 
http://localhost:8080/app/helloWorld 

GET /app/helloWorld HTTP/1.1 
Host: localhost:8080 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 115 
Connection: keep-alive 
Referer: http://localhost:8080/app/login 
Cookie: JSESSIONID=1dymxpkh13z32; SPRING_SECURITY_REMEMBER_ME_COOKIE=U05kS2NTakNIZTN Dd0hFcWxqZXRUQT09Oi90M3Q0NTA1czhxSjRadTQ5NW5FQVE9P Q 

HTTP/1.1 200 OK 
Content-Language: en-US 
Content-Type: text/html 
Content-Length: 526 
Server: Jetty(6.1.x) 
---------------------------------------------------------- 
http://localhost:8080/j_spring_security_check 

GET /j_spring_security_check HTTP/1.1 
Host: localhost:8080 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 115 
Connection: keep-alive 
Cookie: JSESSIONID=1dymxpkh13z32; SPRING_SECURITY_REMEMBER_ME_COOKIE=U05kS2NTakNIZTN Dd0hFcWxqZXRUQT09Oi90M3Q0NTA1czhxSjRadTQ5NW5FQVE9P Q 

HTTP/1.1 302 Found 
Expires: Thu, 01 Jan 1970 00:00:00 GMT 
Set-Cookie: SPRING_SECURITY_REMEMBER_ME_COOKIE=;Path=/;Expires=Thu, 01 Jan 1970 00:00:00 GMT 
Location: http://localhost:8080/app/login?login_error=1 
Content-Length: 0 
Server: Jetty(6.1.x) 
---------------------------------------------------------- 
http://localhost:8080/app/login?login_error=1 

GET /app/login?login_error=1 HTTP/1.1 
Host: localhost:8080 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 115 
Connection: keep-alive 
Cookie: JSESSIONID=1dymxpkh13z32 

HTTP/1.1 200 OK 
Content-Language: en-US 
Content-Type: text/html 
Content-Length: 928 
Server: Jetty(6.1.x) 
+0

我在这里发布了一个类似的线程在Spring论坛上。这也有一个附加的日志文件,显示更多的调试日志。 http://forum.springsource.org/showthread.php?t=86278 – 2010-03-17 21:30:27

+0

我创建了一个Spring Security bug来跟踪这个问题:http://jira.springframework.org/browse/SEC-1441 – 2010-03-17 22:26:52

回答

2

原来,Firebug正在生成额外的GET请求。

0

您是否尝试过使用记得,我的最简单的版本?

<remember-me key="myAppKey"/> 

可能是您的令牌存储库的自定义实施存在问题。你的PersistentTokenRepositoryImpl实际上做了什么?

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html

+0

我必须实现我的自己的PersistentTokenRepository,因为我必须与App Engine数据存储进行交互。我已经确认persistentTokenRepository.createNewToken()调用成功保存到数据存储。 – 2010-03-16 10:36:46

+0

我甚至已经能够跟踪到UsernamePasswordAuthenticationFilter.successfulAuthentication(...) – 2010-03-16 10:42:16

+0

我更新了这个问题,并提供更多信息以防万一您有任何想法。 – 2010-03-17 20:19:02

0

记住在春季安全3.0.1被打破:SEC-1356。使用3.0.2。

+0

该错误的状态是“不会修复”,因此3.0.2如何提供帮助?看起来没有改变。 – 2010-03-16 16:30:12

+0

也许如果我使用Spring Security 3.0.0的话会起作用?由于此问题,我无法使用Spring Security 3.0.2:http://jira.springframework.org/browse/SEC-1434。 – 2010-03-16 16:38:06

+0

@泰勒:是的,在3.0.0中应该可以工作。它被标记为“不会修复”,因为原始问题在3.0.1中被错误解决(破坏所有内容)并在3.0.2中被恢复。 – axtavt 2010-03-16 19:38:33

相关问题