-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1277 from chengyouling/route-gray
spring-cloud框架注册发现实例支持https
- Loading branch information
Showing
49 changed files
with
867 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...n-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.22 KB
...on-demos/spring-common-feign-1.5.x/feign-provider-1.5.x/src/main/resources/private.pkcs12
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...c/main/java/com/huaweicloud/spring/feign/api/configuration/FeignClientConfigSslUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.spring.feign.api.configuration; | ||
|
||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLSocketFactory; | ||
import javax.net.ssl.TrustManager; | ||
import javax.net.ssl.X509TrustManager; | ||
|
||
/** | ||
* 构建feignClient SSL调用的FeignSocketFactory工具类 | ||
* | ||
* @author chengyouling | ||
* @since 2023-02-10 | ||
*/ | ||
public class FeignClientConfigSslUtils { | ||
private FeignClientConfigSslUtils() { | ||
} | ||
|
||
/** | ||
* 构建FeignSslSocketFactory | ||
* | ||
* @return SSLSocketFactory | ||
* @throws NoSuchAlgorithmException NoSuchAlgorithmException | ||
* @throws KeyManagementException KeyManagementException | ||
*/ | ||
public static SSLSocketFactory getFeignSslSocketFactory() throws NoSuchAlgorithmException, KeyManagementException { | ||
TrustManager[] trustManagers = new TrustManager[1]; | ||
TrustManager tm = new FeignClientConfigSslUtils.SslTrustManager(); | ||
trustManagers[0] = tm; | ||
SSLContext sslContext = SSLContext.getInstance("SSL"); | ||
sslContext.init(null, trustManagers, null); | ||
return sslContext.getSocketFactory(); | ||
} | ||
|
||
/** | ||
* 构建SSL Manager | ||
* | ||
* @since 2022-07-29 | ||
*/ | ||
static class SslTrustManager implements TrustManager, X509TrustManager { | ||
@Override | ||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) { | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) { | ||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return new X509Certificate[0]; | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...ud/spring/feign/api/configuration/FeignClientSslConfigurationHighVersion.java.highVersion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.spring.feign.api.configuration; | ||
|
||
import feign.Client; | ||
import feign.Feign; | ||
|
||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; | ||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties; | ||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; | ||
import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.net.ssl.SSLSocketFactory; | ||
|
||
/** | ||
* 针对springCloud 2020.0.0/2021.0.0/2021.0.3高版本FeignClient SSL请求证书认证处理 | ||
* | ||
* @author chengyouling | ||
* @since 2023-02-10 | ||
*/ | ||
@Configuration | ||
public class FeignClientSslConfigurationHighVersion { | ||
private static SSLSocketFactory feignSocketFactory = null; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientSslConfigurationHighVersion.class); | ||
|
||
/** | ||
* 构建Feign Builder | ||
* | ||
* @param loadBalancerClient loadBalancerClient | ||
* @param properties balancerProperties | ||
* @param factory clientFactory | ||
* @return Client | ||
*/ | ||
@Bean | ||
public Feign.Builder feignBuilder(LoadBalancerClient loadBalancerClient, LoadBalancerProperties properties, | ||
LoadBalancerClientFactory factory) { | ||
final Client sslClient = feignClient(loadBalancerClient, properties, factory); | ||
return Feign.builder().client(sslClient); | ||
} | ||
|
||
/** | ||
* 构建Feign client | ||
* | ||
* @param loadBalancerClient loadBalancerClient | ||
* @param properties balancerProperties | ||
* @param factory clientFactory | ||
* @return Client | ||
*/ | ||
@Bean | ||
public Client feignClient(LoadBalancerClient loadBalancerClient, LoadBalancerProperties properties, | ||
LoadBalancerClientFactory factory) { | ||
if (feignSocketFactory == null) { | ||
try { | ||
feignSocketFactory = FeignClientConfigSslUtils.getFeignSslSocketFactory(); | ||
} catch (NoSuchAlgorithmException e) { | ||
LOGGER.error("build ssl feign client failed for NoSuchAlgorithmException"); | ||
} catch (KeyManagementException e) { | ||
LOGGER.error("build ssl feign client failed for KeyManagementException"); | ||
} | ||
} | ||
return new FeignBlockingLoadBalancerClient(new Client.Default(feignSocketFactory, new NoopHostnameVerifier()), | ||
loadBalancerClient, properties, factory); | ||
} | ||
} |
Oops, something went wrong.