最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot配置http跳轉(zhuǎn)https的過(guò)程

 更新時(shí)間:2023年04月01日 09:12:54   作者:樂(lè)蘭特  
SSL是為網(wǎng)絡(luò)通信提供安全以及保證數(shù)據(jù)完整性的的一種安全協(xié)議,SSL在網(wǎng)絡(luò)傳輸層對(duì)網(wǎng)絡(luò)連接進(jìn)行加密,這篇文章主要介紹了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

一、安全證書的生成

1、可以使用jdk自帶的證書生成工具,jdk自帶一個(gè)叫keytool的證書管理工具,可以用它來(lái)實(shí)現(xiàn)簽名的證書。

2、先配置好基本的java環(huán)境,ctrl+r 輸入cmd ,進(jìn)入java 的目錄

3、例:生成一個(gè)別名叫tomcat 的證書 先使用命令進(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)聽的http的端口號(hào)
        connector.setPort(8080);
        connector.setSecure(false);
        //監(jiān)聽到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è)證書是不收信任的,傳統(tǒng)一般都企業(yè)都是需要購(gòu)買此證書的

到此這篇關(guān)于springboot配置http跳轉(zhuǎn)https的過(guò)程的文章就介紹到這了,更多相關(guān)springboot http跳轉(zhuǎn)https內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

乌鲁木齐市| 菏泽市| 安义县| 临朐县| 阳东县| 和田县| 若尔盖县| 兴义市| 和平县| 噶尔县| 平南县| 新安县| 新密市| 新田县| 闽侯县| 津南区| 荔浦县| 郓城县| 五莲县| 普洱| 连南| 商水县| 邢台市| 若羌县| 武胜县| 保靖县| 浏阳市| 桐柏县| 温泉县| 容城县| 资阳市| 乐山市| 工布江达县| 安国市| 讷河市| 兰州市| 陵川县| 弋阳县| 南涧| 三门县| 新晃|