https Configure a Spring Boot app for HTTPS on Amazon AWS.
参考: 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.的更多相关文章
- Https系列之三:让服务器同时支持http、https,基于spring boot
Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http ...
- Spring Boot2 系列教程(八)Spring Boot 中配置 Https
https 现在已经越来越普及了,特别是做一些小程序或者公众号开发的时候,https 基本上都是刚需了. 不过一个 https 证书还是挺费钱的,个人开发者可以在各个云服务提供商那里申请一个免费的证书 ...
- 在Spring Boot中使用Https
本文介绍如何在Spring Boot中,使用Https提供服务,并将Http请求自动重定向到Https. Https证书 巧妇难为无米之炊,开始的开始,要先取得Https证书.你可以向证书机构申请证书 ...
- Spring Boot 集成配置 HTTPS
这是泥瓦匠的第108篇原创 文章工程: * JDK 1.8 * Maven 3.5.2 * Spring Boot 1.5.9.RELEASE ## 一.HTTPS 是什么 问:什么是HTTP? 答: ...
- Nginx 使用自签名证书实现 https 反代 Spring Boot 中碰到的页面跳转问题
问题一:页面自动跳转到 80 端口 问题描述 最近在使用Nginx反代一个Spring Boot项目中碰到了一个问题,使用 Spring Boot 中的 redirect: 进行页面跳转的时候,通过 ...
- Spring Boot中启动HTTPS
一,生成https 的证书 1,在相应的根目录下 keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize -keyst ...
- spring boot 自签发https证书
一.使用Jdk自带的工具生成数字证书,如下: Java代码 ./keytool -genkey -v -alias tomcat -keyalg RSA -keystore /root/tomca ...
- spring boot接口 支持https
1.拥有证书,可自己生成测试用javatool生成 keytool -keystore [keyname].jks -genkey -alias tomcat -keyalg RSA 接下来输入相关信 ...
- Spring Boot下启用https
1.需要一个证书,可以自己生成或者购买.下面是我们通过keytool自己生成. 打开运行,输入cmd,进入命令行 输入生成命令: keytool -genkey -alias tomcat -stor ...
随机推荐
- java导出Excel 好文收藏
http://www.cnblogs.com/Damon-Luo/p/5919656.html https://www.cnblogs.com/klguang/p/6425422.html
- Microsoft - Find Biggest Node
public Node findBiggest (Node n1, Node n2){ Node c1 = n1; Node c2 = n2; boolean isPositive = false; ...
- WPF如何用TreeView制作好友列表、播放列表(转)
WPF如何用TreeView制作好友列表.播放列表 前言 TreeView这个控件对于我来说是用得比较多的,以前做的小聊天软件(好友列表).音乐播放器(播放列表).类库展示器(树形类结构)等都用的是T ...
- IBM WebSphere MQ介绍安装以及配置服务详解(转)
首先介绍一下MQ MQ消息队列的简称是一种应用程序对应用程序的通信方法.说白了也就是通过队列的方式来对应用程序进行数据通信.而无需专用链接来链接它们. MQ的通讯方式 1.数据报的方式 Datagra ...
- Git中特别的命令
Rebase 假设我们的分支结构如下: rebase 会把从 Merge Base 以来的所有提交,以补丁的形式一个一个重新达到目标分支上.这使得目标分支合并该分支的时候会直接 Fast Forwar ...
- JUC线程池之 线程池拒绝策略
拒绝策略介绍 线程池的拒绝策略,是指当任务添加到线程池中被拒绝,而采取的处理措施. 当任务添加到线程池中之所以被拒绝,可能是由于:第一,线程池异常关闭.第二,任务数量超过线程池的最大限制. 线程池共包 ...
- OpenWrt的web服务器
参考: http://www.szchehang.com/news/10602.html 我们登录的路由器主界面就是通过这个软件指定了80端口来访问的.我们要添加自己额外的网站服务,那只需要重新定义一 ...
- Django Model基础 ORM
ORM 对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的 ...
- SQL的datetime类型数据转换为字符串格式大全
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...
- Gradle Build速度加快终极方法(android studio)
Android Studio用起来越来越顺手,但是却发现Build的速度实在不敢恭维,在google和度娘了几把(....)之后,大体就是分配更高的内存,步骤:Setting-->搜索gradl ...