我有一个带有 authenticate
方法的自定义 AuthenticationProvider
。
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
> Check username, password, throw exceptions where needed
return new CustomAuthenticationToken(username, grantedAuthorities);
}
还有 token :
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 上测试过了。
最佳答案
通过仔细跟踪 Spring Security 的调试日志,我发现了问题。希望这对将来的人有所帮助。
显然,spring security 默认会在登录后迁移 session 。但在 IE 中,它不会将身份验证 cookie 迁移到新 session ,从而导致显示登录页面。
修复很简单,可以在 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>
关于java - AuthenticationProvider authenticate 在 IE 中调用两次,登录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13623994/