@Component
@Data
@Configuration
public class MinioConfig {
@Value("${accessKey}")
private String accessKey;
@Value("${secretKey}")
private String accessSecret;
@Value("${endpoint}")
private String endpoint;
/**
* 桶名称
*/
private String bucketName = "XXXX";
private OkHttpClient okHttpClient;
@Bean(name = {"okHttpClient"})
public OkHttpClient getUnsafeOkHttpClient() throws KeyManagementException {
try {
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
X509TrustManager x509TrustManager = (X509TrustManager) trustAllCerts[0];
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, x509TrustManager);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
return builder.build();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
@Bean(name = {"minioClient"})
public MinioClient minioClient() throws KeyManagementException {
return MinioClient
.builder()
.httpClient(getUnsafeOkHttpClient())
.endpoint(endpoint)
.credentials(accessKey, accessSecret)
.build();
}
}
minioClient 绕过证书访问
最新推荐文章于 2024-05-09 16:13:24 发布