当前位置: 首页 > 知识库问答 >
问题:

AWS ELB HTTPS到HTTP使用Spring-Boot MVC登录不工作

符渊
2023-03-14

我使用的是在带有弹性负载均衡器的 AWS 实例中运行的Spring启动。我正在使用带有登录安全性的Spring MVC,服务器端口设置为8080。我在 ELB 中安装了一个 AWS 生成的证书,该证书具有正确的 Web 名称 test.mydomain.com。弹性负载均衡侦听器针对端口 80 HTTP 进行了设置

public class WebSecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    UserDetailsService userDS;

    @Override
    protected void configure(HttpSecurity http) throws Exception{

        // Allows access for .css, .js, and .images files
        http.authorizeRequests()
            .antMatchers("/resources/**")
            .permitAll()
            .anyRequest()
            .permitAll();

        // Access management for all other requests
        http.authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/home")
            .invalidateHttpSession(true)
            .permitAll();

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDS).passwordEncoder(passwordEncoder());

    }

    @Override
    protected UserDetailsService userDetailsService() {
        return userDS;

    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        PasswordEncoder encoder = new BCryptPasswordEncoder();
        return encoder;
    }


}

当我访问主页时,https://test.mydomian.com/home,一切正常,页面安全。我确信证书有效。我尝试使用curl-vk https:test.mydomain。com/home并验证证书是否有效。当我单击login时,页面恢复为HTTP(Unsecure),接下来的所有其他页面都是HTTP。

我用ELB尝试了以下实验。我取消了端口80侦听器,因此我在443-443 HTTPS上只有一个侦听器

共有1个答案

周飞语
2023-03-14

由于ELB将充当代理,因此您必须通过设置server来配置Spring(以及您正在运行的服务器)以使用转发头。在application.properties中使用转发头totrue

编辑:从Spring Boot 2.2开始,< code > server . use-forward-headers 属性已被弃用,而代之以< code > server . forward-headers-strategy 。请参阅https://github . com/Spring-projects/Spring-Boot/wiki/Spring-Boot-2.2-Release-Notes # deprecations-in-Spring-Boot-22

 类似资料:
  • 我尝试使用spring security进行登录,但它不起作用,因为它返回给我这个链接:http://localhost:8080/login?error并在主页上报告我:这是代码: 静态页面中的一个索引,它重新链接我: 在模板中,我有以下内容: 并且捕获它的请求映射就在那里: 日志:在6.958秒内启动了ProgettoSiwApplication(JVM运行7.964)2018-06-21 1

  • 首先,我想让你知道,我是新来的Symfony。我在路上把我的PHP项目从我自己的“基本”MVC转到SimfOn.该项目已经运行良好,但我在适应Symfony时遇到了一些问题。 我从基本的框架开始,make: user和make: auth。模板运行良好。但是我未能将登录过程转换为AJAX和JSON。 我遵循了这个官方教程:https://symfonycasts.com/screencast/ap

  • 问题内容: 默认情况下,我的网站使用HTTP。我确实有一个启用HTTPS的证书,但是只有其中的某些区域会强制建立安全连接。 登录是通过Ajax处理的,即使请求来自HTTP,我也想开始使用SSL。 我尝试强制请求的地址具有HTTPS,它可以完美地答复。但是,在ajax回调中,尽管回复正常,但似乎从未设置会话。 如果请求来自HTTPS,一切都会顺利进行。 为什么会这样? 我可以理解为什么浏览器拒绝HT

  • 问题内容: 我正在一个springMVC项目中,其中用户身份验证基于Spring安全性。 这个想法是要拥有一个移动(android)应用程序,以便能够将某种数据发送到后端。 因此,在开始开发android之前,我决定使用cURL模拟登录表单的情况。 我们网站上的登录表单如下: 我使用以下命令: 但是我将获得登录页面,换句话说,我无法根据模拟情况通过用户身份验证。 只需注意:对于每一个请求,spri

  • 我正在Java创建一个管理系统。 我有这个登录表。与数据库的连接看起来很好,因为它没有给出错误。 但是当我尝试执行try{}和catch{}时,它给出了一个错误。 我希望有谁能帮助我。 它总是给出: catch(Exception ex){JoptionPane.ShowMessageDialog(null,“登录操作错误”,“登录错误”,JoptionPane.Error_Message);}

  • 我有一个登记表,它可以注册和登录用户。我使用