2010-03-16 6 views
1

J'ai essayé de savoir pourquoi Spring Security ne créait pas le cookie de rappel de Spring Security (SPRING_SECURITY_REMEMBER_ME_COOKIE). Cependant, d'après ce que je vois via les en-têtes HTTP, le cookie est en train d'être défini, c'est juste qu'il y a une requête GET supplémentaire pour/j_spring_security_check qui provoque l'exception ci-dessous. Cela entraîne également le retrait du cookie. J'utilise Spring 3.0.1, Spring Snapshot et Google App Engine 1.3.1. Des idées sur ce qui se passe?Spring Security - Persistent Se souvenir de moi Problème

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 

Voici la partie pertinente de l'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" /> 

Voici les en-têtes HTTP pour le scénario que je vais avoir des problèmes avec:

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

J'ai posté un fil semblable sur le forum de printemps ici. Cela a également un fichier journal joint montrant plus de la journalisation de débogage. http://forum.springsource.org/showthread.php?t=86278 –

+0

J'ai créé un bogue de Spring Security pour suivre ce problème: http://jira.springframework.org/browse/SEC-1441 –

Répondre

2

Il s'avère que Firebug générait la requête GET supplémentaire.

0

Avez-vous essayé d'utiliser la version la plus simple de se souvenir-moi?

<remember-me key="myAppKey"/> 

Il se peut que votre implémentation personnalisée du référentiel de jetons soit en cause. Que fait votre PersistentTokenRepositoryImpl?

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

+0

Je dois mettre en œuvre mon propre PersistentTokenRepository parce que je dois interagir avec la banque de données App Engine. J'ai confirmé que l'appel persistentTokenRepository.createNewToken() persiste avec succès dans le magasin de données. –

+0

J'ai même été capable de le suivre jusqu'à UsernamePasswordAuthenticationFilter.successfulAuthentication (...) –

+0

J'ai mis à jour la question avec plus d'informations au cas où vous auriez des idées. –

0

Se souvenir de moi a été cassé de sécurité Spring 3.0.1: SEC-1356. Utilisez 3.0.2.

+0

L'état de ce bogue est "ne va pas réparer" alors comment 3.0.2 aider? On dirait qu'il n'y a pas eu de changement. –

+0

Peut-être que si j'utilise Spring Security 3.0.0, cela fonctionnerait? Je ne peux pas utiliser Spring Security 3.0.2 à cause de ce problème: http://jira.springframework.org/browse/SEC-1434. –

+0

@Taylor: Oui, dans 3.0.0 cela devrait fonctionner. Il est marqué "ne corrigera pas", car le problème d'origine a été résolu de manière incorrecte (tout casser) dans 3.0.1 et a été rétabli dans 3.0.2. – axtavt

Questions connexes