正在显示
2 个修改的文件
包含
35 行增加
和
0 行删除
| 1 | package com.zhonglai.luhui.admin; | 1 | package com.zhonglai.luhui.admin; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.admin.util.SSLUtil; | ||
| 3 | import org.springframework.boot.SpringApplication; | 4 | import org.springframework.boot.SpringApplication; |
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| @@ -29,5 +30,7 @@ public class AdminApplication { | @@ -29,5 +30,7 @@ public class AdminApplication { | ||
| 29 | public static void main(String[] args) { | 30 | public static void main(String[] args) { |
| 30 | SpringApplication.run(AdminApplication.class,args); | 31 | SpringApplication.run(AdminApplication.class,args); |
| 31 | System.out.println("启动成功"); | 32 | System.out.println("启动成功"); |
| 33 | + //Jsoup 全局忽略 SSL 校验 | ||
| 34 | + SSLUtil.disableSSLVerification(); | ||
| 32 | } | 35 | } |
| 33 | } | 36 | } |
| 1 | +package com.zhonglai.luhui.admin.util; | ||
| 2 | + | ||
| 3 | +import javax.net.ssl.*; | ||
| 4 | +import java.security.cert.X509Certificate; | ||
| 5 | + | ||
| 6 | +public class SSLUtil { | ||
| 7 | + | ||
| 8 | + public static void disableSSLVerification() { | ||
| 9 | + try { | ||
| 10 | + TrustManager[] trustAllCerts = new TrustManager[]{ | ||
| 11 | + new X509TrustManager() { | ||
| 12 | + public X509Certificate[] getAcceptedIssuers() { | ||
| 13 | + return null; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public void checkClientTrusted(X509Certificate[] certs, String authType) { | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void checkServerTrusted(X509Certificate[] certs, String authType) { | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + }; | ||
| 23 | + | ||
| 24 | + SSLContext sc = SSLContext.getInstance("TLS"); | ||
| 25 | + sc.init(null, trustAllCerts, new java.security.SecureRandom()); | ||
| 26 | + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | ||
| 27 | + HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); | ||
| 28 | + } catch (Exception e) { | ||
| 29 | + throw new RuntimeException(e); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | +} |
-
请 注册 或 登录 后发表评论