参考: 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. Ubuntu 18.10连接Windows 桌面

    ========================= 适用于Linux连接Windows远程桌面 Linux版本:CentOS.Ubuntu等 1.终端命令安装远程桌面客户端工具,具体命令如下: sud ...

  2. js 命名空间

        yui的命名空间和继承机制 var YAHOO = window.YAHOO || {};YAHOO.namespace = function(ns) {    if (!ns || !ns. ...

  3. Oracle 基础知识入门

    前记: 近来项目用到Oracle数据库,大学学了点,后面基本忘记得差不多了,虽然基本语法跟sql 差不多,但是oracle知识是非常多的. 这里简单说点基础知识,希望后面补上更多的关于ORacle知识 ...

  4. 使用Apriori进行关联分析(一)

    大型超市有海量交易数据,我们可以通过聚类算法寻找购买相似物品的人群,从而为特定人群提供更具个性化的服务.但是对于超市来讲,更有价值的是如何找出商品的隐藏关联,从而打包促销,以增加营业收入.其中最经典的 ...

  5. RAC6——crsctl 和 srvctl 命令的区别理解

    Oracle Clusterware提供了丰富的工具,我们把常用的工具按照rac的四层机构做了划分,然后分别介绍: 节点层: olsnodes 参数-n -i -p 网络层: oifcfg 四个子命令 ...

  6. java 多线程之:wait()、notify()、notifyAll()等方法

    wait().notify().notifyAll()等方法介绍: 在Object.java中,定义了wait(), notify()和notifyAll()等接口.wait()的作用是让当前线程进入 ...

  7. centos7 MFS drbd keepalived

    环境: centos7.3 + moosefs 3.0.97 + drbd84-utils-8.9.8-1 + keepalived-1.2.13-9 工作原理: 架构图: 节点信息: 节点名     ...

  8. c# 多线程排队队列实现的源码

    [csharp] view plaincopy using System; using System.Threading; using System.Collections; using System ...

  9. 在doc下面执行zpl语言 Copy 文件名 lpt1

    在doc下面执行zpl语言 Copy 文件名 lpt1 测试斑马条码打印机并口是否能正常通讯: 1.Zebra打印机安装好标签和碳带,且打印机进入Ready状态.2.电脑端用Notepad编写输入如下 ...

  10. Android应用程序如何调用shell脚本(一)

    转自: Android应用程序如何调用shell脚本(一) 一般来说, Android 下的应用程序可以“直接”得到的最大的权限为 system ,但是如果我们需要在程序中执行某些需要 root 权限 ...