日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

java6 disable ssl2.0_SpringBoot2.0如何启用https协议

發布時間:2025/3/12 javascript 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java6 disable ssl2.0_SpringBoot2.0如何启用https协议 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SpringBoot2.0之后,啟用https協議的方式與1.*時有點兒不同,貼一下代碼。

我的代碼能夠根據配置參數中的condition.http2https,確定是否啟用https協議,如果啟用https協議時,會將所有http協議的訪問,自動轉到https協議上。

一、啟動程序

package com.wallimn.iteye.sp.asset;

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.beans.factory.annotation.Value;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;

import org.springframework.context.annotation.Bean;

/**

* SpringBoot2.0啟動程序

* @author wallimn,http://wallimn.iteye.com

*

*/

@SpringBootApplication

public class AssetApplication {

public static void main(String[] args) {

SpringApplication.run(AssetApplication.class, args);

}

//如果沒有使用默認值80

@Value("${http.port:80}")

Integer httpPort;

//正常啟用的https端口 如443

@Value("${server.port}")

Integer httpsPort;

// springboot2 寫法

@Bean

@ConditionalOnProperty(name="condition.http2https",havingValue="true", matchIfMissing=false)

public TomcatServletWebServerFactory servletContainer() {

TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {

@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

@ConditionalOnProperty(name="condition.http2https",havingValue="true", matchIfMissing=false)

public Connector httpConnector() {

System.out.println("啟用http轉https協議,http端口:"+this.httpPort+",https端口:"+this.httpsPort);

Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

connector.setScheme("http");

//Connector監聽的http的端口號

connector.setPort(httpPort);

connector.setSecure(false);

//監聽到http的端口號后轉向到的https的端口號

connector.setRedirectPort(httpsPort);

return connector;

}}

二、配置文件

1.使用http協議時的配置

server.port=80

2.使用https及http協議時的配置

server.port=443

server.ssl.key-store=classpath:keystore.p12

server.ssl.key-store-password=your-password

server.ssl.keyStoreType=PKCS12

server.ssl.keyAlias=your-cert-alias

condition.http2https=true

http.port=80

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的java6 disable ssl2.0_SpringBoot2.0如何启用https协议的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。