Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Last active October 10, 2018 14:01
Show Gist options
  • Save artem-smotrakov/1fafe7d74b93f10c99591e19248204c2 to your computer and use it in GitHub Desktop.
Save artem-smotrakov/1fafe7d74b93f10c99591e19248204c2 to your computer and use it in GitHub Desktop.
Enforcing HTTPS and enabling HSTS header in Spring security config, see more in https://blog.gypsyengineer.com/en/security/tips-configuring-security-rest-api-spring.html
@Configuration
@EnableWebSecurity
public class ChannelSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requiresChannel().anyRequest().requiresSecure();
http.headers().httpStrictTransportSecurity();
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment