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

歡迎訪問 生活随笔!

生活随笔

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

javascript

SpringBoot https访问控制

發布時間:2024/4/13 javascript 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot https访问控制 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發中如果現在是進行了 http 訪問,則應該讓請求跳轉到 https 的 443 端口上的程序處理類如果 要想實現這樣的處理需要追加一個配置程序類: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.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration; @Configuration public class HttpConnectorConfig { // 此類專門負責HTTP的連接的相關配置public Connector initConnector() {Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol") ;connector.setScheme("http"); // 如果現在用戶使用普通的http的方式進行訪問connector.setPort(80); // 用戶訪問的是80端口connector.setSecure(false); // 如果該連接為跳轉則表示不是一個新的連接對象connector.setRedirectPort(443); // 設置轉發操作端口return connector;}@Beanpublic TomcatEmbeddedServletContainerFactory servletContainerFactory() {TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory() {protected void postProcessContext(org.apache.catalina.Context context) {// 該方法主要進行請求處理的上下文配置SecurityConstraint securityConstraint = new SecurityConstraint(); // 定義新的安全訪問策略securityConstraint.setUserConstraint("CONFIDENTIAL"); // 定義用戶的訪問約束要求SecurityCollection collection = new SecurityCollection() ;collection.addPattern("/*"); // 匹配所有的訪問映射路徑securityConstraint.addCollection(collection); // 追加路徑映射訪問配置context.addConstraint(securityConstraint);};};factory.addAdditionalTomcatConnectors(this.initConnector());return factory;} }如果以后用戶要訪問 80 端口,則會將其自動跳轉到 443 端口。

?

總結

以上是生活随笔為你收集整理的SpringBoot https访问控制的全部內容,希望文章能夠幫你解決所遇到的問題。

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