参考: 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. 《DSP using MATLAB》 Problem 3.19

    先求模拟信号经过采样后,对应的数字角频率: 明显看出,第3种采样出现假频了.DTFT是以2π为周期的,所以假频出现在10π-2kπ=0处. 代码: %% ----------------------- ...

  2. 使用webpack搭建vue项目中遇到的问题

    1:data数据文件经试验,需要放在生成的build文件夹中才能生效,但是应该把data文件夹先放在src中,然后如何定义config文件,让其复制过去? new CopyWebpackPlugin( ...

  3. benthos 通过配置文件配置 stream 说明

    stream 模式,我们也可以通过配置文件进行配置 参考配置文件 input: type: http_server buffer: type: memory pipeline: threads: 4 ...

  4. CodeIgniter 安装指导

    CodeIgniter 安装分为四个步骤: 解压缩安装包. 把 CodeIgniter 文件夹和里面的文件上传到你的服务器.通常 index.php 在根目录. 用任何文本编辑器打开 applicat ...

  5. zeroMQ 学习

    zeroMQ 是一个高性能的分布式设计的消息队列,网上有人进行过性能的比较,非常厉害,并且很大约40多种语言的API 可以调用,真实很不错的. 而且有一点就是使用简单,不需要服务器,对于使用C/C++ ...

  6. 使用 mysqldump 备份时的一些参数

    因为还没有用到 ThinkPHP 的迁移组件,暂时使用 mysqldump 来备份,并版本控制. 有几个参数需要用到. --skip-dump-date 不要完成时间. --skip-extended ...

  7. NPOI控制Excel格式

    1.//sheet.SetColumnWidth(3, 50 * 256);  控制第三列宽,单位为1/256个字符 dataRow.Height = 18 * 20; 控制行高,单位为1/20点 s ...

  8. TroubleShoot: Fail to deploy Windows UAP to device: 0x80073CFD

    After creating "Blank App(Windows Universal)" targeting Windows Phone 10 in Visual Studio ...

  9. ios如何动态改变title

    刚刚用vue发现document.title=title在ios上并不能动态改变title(iphone上的微信端),但是在电脑上和安卓手机上却没有问题,仔细查了一下原来是ios存在title不刷新的 ...

  10. bzoj4693: 雪中送温暖

    Description 每年的1月10日是温暖节,在这一天,化身出题人的C_SUNSHINE将会给OIer们送温暖.OIer们只要在门口放上一个 仙人掌,就能在早上的某个时刻听到门外传来一声:“开门, ...