首页 > 解决方案 > 登录后如何配置 Spring Security 以使用 https 重定向?

问题描述

Chrome 中的一个新功能/错误 ( https://bugs.chromium.org/p/chromium/issues/detail?id=1158169 ) 向我的用户显示一个错误,因为 Spring Security 在 http (而不是 https ) 即使登录页面和登录表单都是 https。我有一个负载均衡器,它强制使用 https,然后使用 http 传递到多个 Apache/Tomcat 服务器。

关于如何纠正这个问题的任何想法?

如果需要,我的 Spring Security 登录设置如下:

// Apply sameOrigin policy for iframe embeddings
http.headers().frameOptions().sameOrigin();

// Authorization filters
http.authorizeRequests().antMatchers("/sysAdmin/**", "/monitoring/**").access("isFullyAuthenticated() and hasRole('GOD')");
http.authorizeRequests().antMatchers("/app/**").authenticated();
http.authorizeRequests().antMatchers("/**").permitAll();

http.formLogin()
        .loginPage("/public/login.jsp")
        .loginProcessingUrl("/login")
        .usernameParameter("username")
        .passwordParameter("password")
        .defaultSuccessUrl("/app/Dashboard.action", false)
        .failureHandler(customAuthenticationFailureHandler());

// Disable so that logout "get" url works (otherwise you have to do a html form)
http.csrf().disable();
http.logout().logoutSuccessUrl("/public/login.jsp");

http.sessionManagement()
        .invalidSessionUrl("/public/expiredSession.jsp?expiredId=2")
        .maximumSessions(2)
        .sessionRegistry(sessionRegistry())
        .expiredUrl("/public/expiredSession.jsp?expiredId=3");

标签: google-chromespring-securityhttps

解决方案


如果您在使用 SSL 终止的代理服务器后面运行,那么您需要确保正确设置它。这通常涉及确保代理发送正确的X-Forwarded-标头并启用 Spring ForwardedHeaderFilter


推荐阅读