2012-11-29 16 views
1

我使用authenticate方法自定义了AuthenticationProviderAuthenticationProvider身份验证在IE中调用了两次,但无法登录

@Override 
public Authentication authenticate(Authentication authentication) throws AuthenticationException { 

     > Check username, password, throw exceptions where needed 

     return new CustomAuthenticationToken(username, grantedAuthorities); 
    } 

和令牌:

public class CustomAuthenticationToken extends UsernamePasswordAuthenticationToken 
{ 
    public CustomAuthenticationToken(ICurrentUserContext currentUser, List<GrantedAuthority> authorities) { 
     super(currentUser.getUsername(), currentUser.getPassword(), authorities); 
    } 
} 

当我使用Chrome,火狐登录,也没有任何问题。

在IE 8/9中,我有一个很奇怪的问题。有时它只会调用方法authenticate一次,它会登录并且一切按预期工作。但时不时会拨打authenticate两次,并且未能登录。

有没有人有任何线索?

我已经在Tomcat btw上测试过它。

回答

2

我发现这个问题,仔细追查的Spring Security的调试日志..希望这会帮助别人的未来。

可以看出,春季安全默认会在登录后迁移会话。但在IE中,它不会将身份验证cookie迁移到新会话,从而导致呈现登录页面。

的修复是容易的,你可以在Spring XML安全性来完成:

<http use-expressions="true"> 

    <!-- 
     This settings is for IE. Default this setting is on migrateSession. 
     When IE tries to migrate the session, the auth cookie does not migrate, 
     resulting in a nice login screen again, after you've logged in. 

     This setting ensures that the session will not be invalidated, and thus IE will still work as expected. 
    --> 
    <session-management session-fixation-protection="none" /> 
</http> 
+2

这没有任何意义。除了在响应中设置新的JSESSIONID cookie之外,浏览器不应该知道会话迁移的任何内容。请看看我的单独答案,看看是否适用。由于这有助于特定目的,因此最好避免禁用它。 –

1

迁移会议完全是一个服务器端的过程,应当是不可见的浏览器。它应该看到的是JSESSIONID的一个新的Set-Cookie头,它应该尊重它。

我最好的猜测是你看到this tomcat bug,这将导致不同的效果,这取决于浏览器如何解释重复标题。最初报告是因为this issue with a Blackberry browser,这与您在此处看到的内容密切相关。

但是你不会说你正在使用Spring Security或Tomcat的哪个版本(总是一个好主意:-)),所以很难肯定地说。

+0

是的,但如何从这里..我使用vFabric tc服务器v2.7,与春天3.0 – Arcturus

+0

可见,IE不尊重Set-Cookie头? – Arcturus

+0

所有的浏览器都应该遵守这个标题(否则它们将不能使用cookie)。你使用的是什么版本的Spring Security? 3.0不是特定的版本号。您最好的选择是调试浏览器插件中的实际响应,看看这是否适用(即您是否看到cookie被设置,并且是否有多个标头设置相同的cookie)。然后在当前的tomcat版本上尝试一下,看看它是否有效。 –

0

内容 快速参考 的Spring Security核心插件表 < < 17IP地址Restrictions19Logout处理程序>> 18名会话固定预防 - 参考文档 作者:伯特·贝克威思,贝弗利塔尔博特 版本:2.0 RC3 18会话固定预防 为了防止会话注入攻击,将useSessionFixationPrevention属性设置为true: grails.plugin.springsecurity.useSessionFixationPrevention = true 成功验证后,会创建一个新的HTTP会话并创建前一会话的attri butes被复制到它。如果您通过点击某人试图破解您的帐户(其中包含活动会话ID)生成的链接来开始会话,那么登录后您将不再共享以前的会话。你有你自己的会议。

由于默认情况下,Grails缺少在URL中包含jsessionid(请参阅此JIRA问题),所以会话修复问题不大,但使用此功能仍是一个好主意。

请注意,使用cookie会话插件时存在问题;请参阅此问题了解更多详情。

该表显示会话固定的配置选项。

属性默认值含义 useSessionFixationPrevention true是否使用会话固定防护。 sessionFixationPrevention.migrate true登录后是否将现有会话的会话属性复制到新会话。 sessionFixationPrevention.alwaysCreateSession false是否始终创建会话,即使请求开始时不存在会话。

http://grails-plugins.github.io/grails-spring-security-core/guide/sessionFixation.html

+0

没有Grails我的朋友:) – Arcturus