java - AuthenticationProvider authenticate 在 IE 中调用两次,登录失败

标签 java spring tomcat spring-security

我有一个带有 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/

相关文章:

java - BeanNotOfRequiredTypeException 但实际上是 $Proxy 类型

Java - AWT 从 1.4 到 1.5 的差异(适用于 Unix 和 Windows)

java - 添加功能 - 使用 Ant 构建的 Java servlet

java - eclipse:在服务器上运行消失

java - 如何创建灵活的 MVC 结构?

java - 将 Spring 字段注入(inject)转换为构造函数注入(inject)(IntelliJ IDEA)?

java - 无法从 Spring Boot 微服务模块中的 Zuul header 获取 JWT token

java - 成功登录后 CAS 重定向至 URL

mysql - EntityManager 创建查询显示意外标记 :

java - Spring Maven 清理错误 - 请求的配置文件 "pom.xml"无法激活,因为它不存在