|
@@ -3,16 +3,20 @@ package edu.math.diagnosis.config;
|
|
|
import edu.math.diagnosis.file.FileService;
|
|
|
import edu.math.diagnosis.file.MinioFileService;
|
|
|
import io.minio.MinioClient;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.Protocol;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import javax.net.ssl.*;
|
|
|
+import java.security.GeneralSecurityException;
|
|
|
+import java.security.SecureRandom;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import static com.aliyun.oss.ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT;
|
|
|
|
|
|
@Configuration
|
|
|
public class MinioConfig {
|
|
@@ -29,10 +33,45 @@ public class MinioConfig {
|
|
|
return new MinioFileService();
|
|
|
}
|
|
|
|
|
|
+ @Bean
|
|
|
+ OkHttpClient okHttpClient() {
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+ X509TrustManager trustManager;
|
|
|
+ SSLSocketFactory sslSocketFactory;
|
|
|
+ trustManager = new AnyTrustManager();
|
|
|
+
|
|
|
+ try {
|
|
|
+ SSLContext sslContext;
|
|
|
+ sslContext = SSLContext.getInstance("SSL");
|
|
|
+ sslContext.init(null, new X509TrustManager[]{trustManager}, new SecureRandom());
|
|
|
+ sslSocketFactory = sslContext.getSocketFactory();
|
|
|
+ } catch (GeneralSecurityException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ HostnameVerifier DO_NOT_VERIFY = (hostname, session) -> true;
|
|
|
+
|
|
|
+ List<Protocol> protocol = new LinkedList<>();
|
|
|
+ protocol.add(Protocol.HTTP_1_1);
|
|
|
+ return okHttpClient.newBuilder()
|
|
|
+ .connectTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
|
|
+ .protocols(protocol)
|
|
|
+ .hostnameVerifier(DO_NOT_VERIFY)
|
|
|
+ .sslSocketFactory(sslSocketFactory, trustManager)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
@Bean
|
|
|
MinioClient minioClient(MinioProperties properties) throws Exception {
|
|
|
logger.info("init MinioClient,url is {} , accessKey is {} , secretKey is {}", properties.getUrl(), properties.getAccessKey(), properties.getSecretKey());
|
|
|
- MinioClient client = new MinioClient(properties.getUrl(), properties.getAccessKey(), properties.getSecretKey());
|
|
|
+ MinioClient client = null;
|
|
|
+ if (properties.isSecure()) {
|
|
|
+ client = new MinioClient(properties.getUrl(), properties.getSecurePort(), properties.getAccessKey(), properties.getSecretKey(), null, true, okHttpClient());
|
|
|
+ }else {
|
|
|
+ client = new MinioClient(properties.getUrl(),properties.getAccessKey(),properties.getSecretKey());
|
|
|
+ }
|
|
|
Set<String> buckets = new HashSet<>(Arrays.asList(properties.getBuckets()));
|
|
|
buckets.add(properties.getDefaultBucket());
|
|
|
for (String bucket : buckets) {
|