参考: https://geocolumbus.github.io/HTTPS-ELB-AWS-Spring-Boot/

1.  在服务器端配置  证书 域名 映射

2. 导入依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

3.配置

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired
private LdapConfig ldapConfig; @Autowired
private CorsConfig corsConfig; @Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
} @Value("${security.https.path}")
private String httpsPath; // 项目路径 ,正式环境 配置 "/" 即可 @Override
protected void configure(HttpSecurity http) throws Exception {
http
.requiresChannel().antMatchers(httpsPath).requiresSecure()
.and()
.authorizeRequests()
//.antMatchers("/ui/**").fullyAuthenticated()
//.antMatchers("/file/**").fullyAuthenticated()
.antMatchers("/**").permitAll()
.and().cors()
.and().csrf().disable();
} }

(备份)

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired
private LdapConfig ldapConfig; @Autowired
private CorsConfig corsConfig; @Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
} @Value("${security.https.path}")
private String httpsPath; @Bean
public UserDetailsContextMapper userDetailsContextMapper() {
return new LdapUserDetailsMapper() {
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx, String username,
Collection<? extends GrantedAuthority> authorities) {
UserDetails details = super.mapUserFromContext(ctx, username, authorities);
return new UserDetail((LdapUserDetails) details);
}
};
} @Override
protected void configure(HttpSecurity http) throws Exception {
http
.requiresChannel().antMatchers(httpsPath).requiresSecure()
.and()
.authorizeRequests()
.antMatchers("/ui/**").fullyAuthenticated()
.antMatchers("/file/**").fullyAuthenticated()
.antMatchers("/**").permitAll()
.and().cors()
.and().csrf().disable();
} @Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDetailsContextMapper(userDetailsContextMapper())
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource()
.url(ldapConfig.getUrl()+ldapConfig.getBase_dc())
.managerDn(ldapConfig.getUsername())
.managerPassword(ldapConfig.getPassword());
} @Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(corsConfig.getAllowedOrigins());
configuration.setAllowedMethods(corsConfig.getAllowedMethods());
configuration.setAllowedHeaders(corsConfig.getAllowedHeaders());
configuration.setAllowCredentials(corsConfig.getAllowedCredentials());
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}

4.在application. yml 或者 application.properties 中配置:

server:
port:
servlet:
session:
timeout:
tomcat:
max-threads:
remote-ip-header: x-forwarded-for
protocol-header: x-forwarded-proto

https Configure a Spring Boot app for HTTPS on Amazon AWS.的更多相关文章

  1. Https系列之三:让服务器同时支持http、https,基于spring boot

    Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http ...

  2. Spring Boot2 系列教程(八)Spring Boot 中配置 Https

    https 现在已经越来越普及了,特别是做一些小程序或者公众号开发的时候,https 基本上都是刚需了. 不过一个 https 证书还是挺费钱的,个人开发者可以在各个云服务提供商那里申请一个免费的证书 ...

  3. 在Spring Boot中使用Https

    本文介绍如何在Spring Boot中,使用Https提供服务,并将Http请求自动重定向到Https. Https证书 巧妇难为无米之炊,开始的开始,要先取得Https证书.你可以向证书机构申请证书 ...

  4. Spring Boot 集成配置 HTTPS

    这是泥瓦匠的第108篇原创 文章工程: * JDK 1.8 * Maven 3.5.2 * Spring Boot 1.5.9.RELEASE ## 一.HTTPS 是什么 问:什么是HTTP? 答: ...

  5. Nginx 使用自签名证书实现 https 反代 Spring Boot 中碰到的页面跳转问题

    问题一:页面自动跳转到 80 端口 问题描述 最近在使用Nginx反代一个Spring Boot项目中碰到了一个问题,使用 Spring Boot 中的 redirect: 进行页面跳转的时候,通过 ...

  6. Spring Boot中启动HTTPS

    一,生成https 的证书 1,在相应的根目录下 keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize -keyst ...

  7. spring boot 自签发https证书

    一.使用Jdk自带的工具生成数字证书,如下: Java代码   ./keytool -genkey -v -alias tomcat -keyalg RSA -keystore /root/tomca ...

  8. spring boot接口 支持https

    1.拥有证书,可自己生成测试用javatool生成 keytool -keystore [keyname].jks -genkey -alias tomcat -keyalg RSA 接下来输入相关信 ...

  9. Spring Boot下启用https

    1.需要一个证书,可以自己生成或者购买.下面是我们通过keytool自己生成. 打开运行,输入cmd,进入命令行 输入生成命令: keytool -genkey -alias tomcat -stor ...

随机推荐

  1. POJ 3253 Fence Repair STL 优先队列

    这题做完后觉得很水,主要的想法就是逆过程思考,原题是截断,可以想成是拼装,一共有n根木棍,最后要拼成一根完整的,每两根小的拼成一根大的,拼成后的木棍长度就是费用,要求费用最少.显然的是一共会拼接n-1 ...

  2. CTF之LSB信息隐藏术

    LSB也就是最低有效位,原理是图片中的像素一般是由三种颜色构成,即三原色(绿红蓝),由这三种颜色可以组成其它各种颜色. 例如在PNG图片的储存中,每个颜色会有8bit,LSB隐写就是修改了像素中的最低 ...

  3. 各大OJ题目分类

    http://www.pythontip.com/acm/problemCategory

  4. string str将str转字符数组以及字符数组初始化

    c和指针(<pointers on c>) 8.1.11 一个字符串,如"hello",一般为字符串常量,可以用它对字符指针赋值,或初始化,相当于把这个字符串常量的首地 ...

  5. android 图片解码显示流程

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jingxia2008/article/details/32327699 问题来源 android 能 ...

  6. 【转】每天一个linux命令(29):chgrp命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/12/03/2799003.html 在lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理. ...

  7. Oracle 基于用户管理恢复的处理

    ================================ -- Oracle 基于用户管理恢复的处理 --================================ Oracle支持多种 ...

  8. async(await)知识点

    async 函数是 Generator 函数的语法糖. async 函数对 Generator 函数的改进体现在: async 内置执行器. Generator 函数的执行必须靠执行器,需要调用 ne ...

  9. npm 构建时,次要版本变化引起的问题

    问题:下载项目后,运行 npm install 或 yarn install,vue-awesome-swiper 做的功能显示不正常. 解决:从 官方网站 文件 README.md 中找到: // ...

  10. gitlab HA集群

    https://docs.gitlab.com/ee/administration/high_availability/gitlab.html https://about.gitlab.com/hig ...