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

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

 更新時(shí)間:2023年04月01日 09:12:54   作者:樂蘭特  
SSL是為網(wǎng)絡(luò)通信提供安全以及保證數(shù)據(jù)完整性的的一種安全協(xié)議,SSL在網(wǎng)絡(luò)傳輸層對(duì)網(wǎng)絡(luò)連接進(jìn)行加密,這篇文章主要介紹了springboot配置http跳轉(zhuǎn)https的過程,需要的朋友可以參考下

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、訪問地址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ān)springboot http跳轉(zhuǎn)https內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

浦城县| 瓦房店市| 甘德县| 朝阳市| 泸西县| 延寿县| 周口市| 三门峡市| 德钦县| 高唐县| 江川县| 黎平县| 高平市| 汉阴县| 合山市| 宣恩县| 清流县| 涞水县| 仁化县| 衡水市| 浠水县| 大化| 武夷山市| 正镶白旗| 濮阳县| 马公市| 宿迁市| 彭泽县| 雅江县| 康乐县| 屏东市| 杭锦旗| 东山县| 汕尾市| 德惠市| 边坝县| 清水县| 桂林市| 蕲春县| 大厂| 镇江市|