参考: 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. centos7 使用mount 挂载window10 (超简单)

    一直使用vmware tools 挂载,发现好多问题,折腾了大半天放弃了,现在使用mount挂载,发现简单多了 一丶首先添加你需要共享的Windows文件夹,右键 记得要选择 Everyone 和一个 ...

  2. Thrift 个人实战--初次体验Thrift(转)

    前言: Thrift作为Facebook开源的RPC框架, 通过IDL中间语言, 并借助代码生成引擎生成各种主流语言的rpc框架服务端/客户端代码. 不过Thrift的实现, 简单使用离实际生产环境还 ...

  3. 如何调优JVM

    堆设置 -Xmx3550m:设置JVM最大堆内存 为3550M. -Xms3550m:设置JVM初始堆内存 为3550M.此值可以设置与-Xmx相同,以避免每次垃圾回收完成后JVM重新分配内存. -X ...

  4. day28 python学习反射 sinstance和issubclass

    isinstance和issubclass isinstance(obj,cls)检查是否obj是否是类 cls 的对象 判断这个对象是不是这个类,或者是不是这个类的子类的实例化 class Foo( ...

  5. vulcanjs schemas&& collections

    一张参考图 说明 从上图我们可以方便的看出schmea 能做的事情 Generate a GraphQL equivalent of your schema to control your Graph ...

  6. nyoj 某种序列

    某种序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 数列A满足An = An-1 + An-2 + An-3, n >= 3 编写程序,给定A0, A1 ...

  7. Java8 lam。。。表达式

    双冒号:相当于用了别人实现的方法,格式,类名::方法 Math::max等效于(a, b)->Math.max(a, b)String::startWith等效于(s1, s2)->s1. ...

  8. java IO字符流

    字节流:因为内存中数据都是字节,二进制数据. 字符流:方便处理文本数据.字符流是基于字节流的. ascii 编码表,并且各国都有自己的编码表. unicode码表,世界码表.优化后 utf-8码表. ...

  9. 通过 CeSi + Supervisor 可视化集中管理服务器节点进程

    通过 CeSi + Supervisor 可视化集中管理服务器节点进程 简介 Supervisor 的安装及基本使用 1. 安装 2. 基本使用  2.1 启动 supervisor 2.2 Supe ...

  10. [转]ASP.net Application 生命周期事件

    生命周期事件和 Global.asax 文件 在应用程序的生命周期期间,应用程序会引发可处理的事件并调用可重写的特定方法.若要处理应用程序事件或方法,可以在应用程序根目录中创建一个名为 Global. ...