springboot配置http跳轉(zhuǎn)https的過(guò)程
SSL是為網(wǎng)絡(luò)通信提供安全以及保證數(shù)據(jù)完整性的的一種安全協(xié)議,SSL在網(wǎng)絡(luò)傳輸層對(duì)網(wǎng)絡(luò)連接進(jìn)行加密。
例:cas 的單點(diǎn)登陸就用到了SSL
一、安全證書(shū)的生成
1、可以使用jdk自帶的證書(shū)生成工具,jdk自帶一個(gè)叫keytool的證書(shū)管理工具,可以用它來(lái)實(shí)現(xiàn)簽名的證書(shū)。
2、先配置好基本的java環(huán)境,ctrl+r 輸入cmd ,進(jìn)入java 的目錄
3、例:生成一個(gè)別名叫tomcat 的證書(shū) 先使用命令進(jìn)入jdk的bin 這里的密碼是123456
keytool -genkey -alias tomcat -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/keys/tomcat.keystore -storepass 123456
4、獲取一個(gè)tomcat.keystore的文件,將這個(gè)文件放到項(xiàng)目的目錄中
二、配置SSL
1、編輯application.properties這個(gè)文件
package com.example; import org.apache.catalina.Context; import org.apache.catalina.connector.Connector; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; @SpringBootApplication public class SpringBootHttpsApplication { public static void main(String[] args) { SpringApplication.run(SpringBootHttpsApplication.class, args); } @Bean public EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { @Override protected void postProcessContext(Context context) { SecurityConstraint constraint = new SecurityConstraint(); constraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); constraint.addCollection(collection); context.addConstraint(constraint); } }; tomcat.addAdditionalTomcatConnectors(httpConnector()); return tomcat; } @Bean public Connector httpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); //Connector監(jiān)聽(tīng)的http的端口號(hào) connector.setPort(8080); connector.setSecure(false); //監(jiān)聽(tīng)到http的端口號(hào)后轉(zhuǎn)向到的https的端口號(hào) connector.setRedirectPort(8443); return connector; } }
三、測(cè)試使用
1、查看啟動(dòng)信息
2、訪問(wèn)地址localhost:8080/AmazeUI-2.7.2/login.html 我自定義了一個(gè)html網(wǎng)頁(yè),它已經(jīng)轉(zhuǎn)向到了8443端口
3、瀏覽器的地址欄中顯示不安全:因?yàn)檫@個(gè)證書(shū)是不收信任的,傳統(tǒng)一般都企業(yè)都是需要購(gòu)買此證書(shū)的
到此這篇關(guān)于springboot配置http跳轉(zhuǎn)https的過(guò)程的文章就介紹到這了,更多相關(guān)springboot http跳轉(zhuǎn)https內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springboot如何配置ssl支持https
- SpringBoot配置HTTPS及開(kāi)發(fā)調(diào)試的操作方法
- springboot實(shí)現(xiàn)的https單向認(rèn)證和雙向認(rèn)證(java生成證書(shū))
- SpringBoot配置Https訪問(wèn)的詳細(xì)步驟
- SpringBoot配置Https入門(mén)實(shí)踐
- springboot項(xiàng)目開(kāi)啟https協(xié)議的項(xiàng)目實(shí)現(xiàn)
- SpringBoot的HTTPS配置實(shí)現(xiàn)
- springboot如何將http轉(zhuǎn)https
- springboot支持https請(qǐng)求的實(shí)現(xiàn)
- SpringBoot中支持Https協(xié)議的實(shí)現(xiàn)
- SpringBoot整合HTTPS的項(xiàng)目實(shí)踐
相關(guān)文章
Spring的Aware接口實(shí)現(xiàn)及執(zhí)行順序詳解
這篇文章主要為大家介紹了Spring的Aware接口實(shí)現(xiàn)及執(zhí)行順序詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Java實(shí)現(xiàn)簡(jiǎn)單雙色球搖獎(jiǎng)功能過(guò)程解析
這篇文章主要介紹了Java實(shí)現(xiàn)簡(jiǎn)單雙色球搖獎(jiǎng)功能過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09Spring思維導(dǎo)圖助你輕松學(xué)習(xí)Spring
這篇文章主要為大家詳細(xì)介紹了Spring思維導(dǎo)圖,幫助你輕松學(xué)習(xí)Spring的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Java消息隊(duì)列的簡(jiǎn)單實(shí)現(xiàn)代碼
本篇文章主要介紹了Java消息隊(duì)列的簡(jiǎn)單實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07Spring 中jdbcTemplate 實(shí)現(xiàn)執(zhí)行多條sql語(yǔ)句示例
本篇文章主要介紹了Spring 中jdbcTemplate 實(shí)現(xiàn)執(zhí)行多條sql語(yǔ)句示例,可以對(duì)多個(gè)表執(zhí)行多個(gè)sql語(yǔ)句,有興趣的可以了解一下。2017-01-01