I have a Spring Boot app that was running perfectly fine without HTTPS. Now, I got my SSL certificate for use in the prod environment, and I now want to make all endpoints HTTPS by default.
I have been using Spring Security to configure my pages' access, and this is what I have :
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");
I read that you could add this to my config above to force all requests to HTTPS, but I wanted to make sure where it should go so I don't break production :
.requiresChannel().anyRequest().requiresSecure();
I am running my app via AWS Elastic Beanstalk, and the SSL cert is already installed properly on AWS successfully( ready to go ). Just to clarify, the SSL/HTTPS is terminated at the Load Balance and not at the EC2 instance, so this might change the configuration in Spring Boot I guess?
Also, it would be great if I could test out the https with Spring locally on my machine too, but I am not sure how to proceed with that. A lot of the online examples seem pretty complex.
What is everyone's advice on this? Thanks