Skip to content

Commit

Permalink
[Fix][e2e] remote loading driver ignores the certificate to avoid cer…
Browse files Browse the repository at this point in the history
…tificate address expiration (#7547)
  • Loading branch information
hawk9821 committed Sep 2, 2024
1 parent e224bda commit c46e16a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public abstract class AbstractJdbcIT extends TestSuiteBase implements TestResour
protected URLClassLoader getUrlClassLoader() throws MalformedURLException {
if (urlClassLoader == null) {
urlClassLoader =
new URLClassLoader(
new InsecureURLClassLoader(
new URL[] {new URL(driverUrl())},
AbstractJdbcIT.class.getClassLoader());
Thread.currentThread().setContextClassLoader(urlClassLoader);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.jdbc;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;

public class InsecureURLClassLoader extends URLClassLoader {
public InsecureURLClassLoader(URL[] urls, ClassLoader parent) throws MalformedURLException {
super(urls, parent);
disableCertificateValidation();
}

private static void disableCertificateValidation() {
TrustManager[] trustAllCerts =
new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {}

public void checkServerTrusted(X509Certificate[] certs, String authType) {}
}
};

try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit c46e16a

Please sign in to comment.