【发布时间】:2017-09-26 17:17:24
【问题描述】:
我有一个 Spring Boot 应用程序,它在没有 HTTPS 的情况下运行得非常好。现在,我获得了在 prod 环境中使用的 SSL 证书,我现在想将所有端点默认设置为 HTTPS。
我一直在使用 Spring Security 来配置我的页面的访问权限,这就是我所拥有的:
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(
"/images/**",
"/css/**",
"/js/**",
....bunch of endpoints....
"/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.failureUrl("/login")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.clearAuthentication(true)
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID", "remember-me")
.logoutSuccessUrl("/")
.permitAll()
.and()
.exceptionHandling()
.accessDeniedPage("/error");
我读到你可以将它添加到我上面的配置中以强制所有请求使用 HTTPS,但我想确定它应该去哪里,这样我就不会中断生产:
.requiresChannel().anyRequest().requiresSecure();
我正在通过 AWS Elastic Beanstalk 运行我的应用程序,并且 SSL 证书已经 已成功在 AWS 上正确安装(准备就绪)。 澄清一下,SSL/HTTPS 在负载平衡处终止,而不是在 EC2 实例处终止,所以我猜这可能会更改 Spring Boot 中的配置?
另外,如果我也可以在我的机器上使用 Spring 本地测试 https,那就太好了,但我不确定如何继续。很多在线示例看起来都非常复杂。
大家对此有何建议?谢谢
【问题讨论】:
标签: spring ssl spring-boot spring-security https