76 lines
2.4 KiB
Java
76 lines
2.4 KiB
Java
package com.hb.config;
|
|
|
|
import okhttp3.OkHttpClient;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import io.minio.MinioClient;
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
import javax.net.ssl.TrustManager;
|
|
import javax.net.ssl.X509TrustManager;
|
|
import java.security.cert.X509Certificate;
|
|
|
|
@Configuration
|
|
public class MinioConfig {
|
|
|
|
@Value("${minio.url}")
|
|
private String url;
|
|
@Value("${minio.accessKey}")
|
|
private String accessKey;
|
|
@Value("${minio.secretKey}")
|
|
private String secretKey;
|
|
|
|
/*@Bean
|
|
public MinioClient getMinioClient() {
|
|
MinioClient minioClient = MinioClient.builder().endpoint(url)
|
|
.credentials(accessKey, secretKey).build();
|
|
return minioClient;
|
|
}*/
|
|
|
|
@Bean
|
|
public MinioClient minioClient(){
|
|
|
|
// Create a trust manager that does not validate certificate chains
|
|
TrustManager[] trustAllCerts = new TrustManager[] {
|
|
new X509TrustManager() {
|
|
public X509Certificate[] getAcceptedIssuers() {
|
|
return new X509Certificate[0];
|
|
}
|
|
|
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
|
// Do nothing (trust any client certificate)
|
|
}
|
|
|
|
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
|
// Do nothing (trust any server certificate)
|
|
}
|
|
}
|
|
};
|
|
|
|
// Install the all-trusting trust manager
|
|
SSLContext sslContext = null;
|
|
try {
|
|
sslContext = SSLContext.getInstance("SSL");
|
|
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// Create a custom OkHttpClient that trusts all certificates
|
|
OkHttpClient customHttpClient = new OkHttpClient.Builder()
|
|
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
|
|
.hostnameVerifier((hostname, session) -> true)
|
|
.build();
|
|
|
|
// Set the custom SSLContext for MinioClient
|
|
return MinioClient.builder()
|
|
.endpoint(url)
|
|
.credentials(accessKey, secretKey)
|
|
.httpClient(customHttpClient)
|
|
.build();
|
|
}
|
|
|
|
}
|