我有AuthenticationProvider
方法的自定义authenticate
。
@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,Firefox登录时,没有任何问题。
在IE 8/9中,我有一个非常奇怪的问题。有时它只会调用方法authenticate
一次,它会登录,一切都按预期工作。但有时,它会调用authenticate
两次,并且无法登录。
有人有任何线索吗?
我已经在Tomcat btw上测试了它。
答案 0 :(得分:2)
我发现了问题,仔细跟踪了Spring Security的调试日志。希望这将有助于将来的某些人。
显然,spring security default会在登录后迁移会话。但在IE中,它不会将身份验证cookie迁移到新会话,从而导致显示登录页面。
修复很简单,可以在Spring Security 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>
答案 1 :(得分:1)
请查看此Internet Explorer buggy when accessing a custom weblogic provider。
也许你可以禁用cookie而不是你的Tomcat
答案 2 :(得分:1)
迁移会话完全是服务器端进程,对浏览器应该是不可见的。它应该看到的是JSESSIONID的一个新的Set-Cookie
标题,它应该尊重它。
我最好的猜测是你看到this tomcat bug,这将导致不同的效果,具体取决于浏览器如何解释重复的标头。最初报道的原因是this issue with a Blackberry browser,这与您在此处看到的内容密切相关。
但是你不会说你正在使用Spring Security或Tomcat的哪个版本(总是一个好主意:-)),所以很难说肯定。
答案 3 :(得分:0)
目录 快速参考 Spring Security Core插件 &LT;&LT; 17IP地址限制19登记处理程序&gt;&gt; 18会话固定预防 - 参考文档 作者:Burt Beckwith,Beverley Talbott 版本:2.0-RC3 18会话固定预防 要防止会话固定攻击,请将useSessionFixationPrevention属性设置为true: grails.plugin.springsecurity.useSessionFixationPrevention = true 验证成功后,将创建一个新的HTTP会话,并将先前会话的属性复制到其中。如果您通过单击某人试图入侵您的帐户(包含活动会话ID)生成的链接来启动会话,则您在登录后不再共享上一个会话。你有自己的会话。
由于Grails默认情况下不包含URL中的jsessionid(请参阅此JIRA问题),因此会话固定不是问题,但使用此功能仍然是个好主意。
请注意,使用cookie-session插件时存在问题;有关详细信息,请参阅此问题。
该表显示了会话固定的配置选项。
属性默认值含义 useSessionFixationPrevention true是否使用会话固定预防。 sessionFixationPrevention.migrate true是否在登录后将现有会话的会话属性复制到新会话。 sessionFixationPrevention.alwaysCreateSession false即使在请求开始时不存在会话,是否始终创建会话。
http://grails-plugins.github.io/grails-spring-security-core/guide/sessionFixation.html