'Feign client SSL Config with jks
I tried the below code to setup my SSL Config for feign client. But somehow keep getting this error. Could you please help? 400 Bad Request No required SSL certificate was sent
@Configuration
public class FeignClientConfig {
@Value("${keystore.path}")
private String keystorePath;
@Value("${keystore.type}")
private String keystoreType;
@Value("${keystore.password}")
private String keystorePassword;
@Bean
public void Config() {
System.setProperty("javax.net.ssl.keyStoreType", keystoreType);
System.setProperty("javax.net.ssl.keyStore", keystorePath);
System.setProperty("javax.net.ssl.keyStorePassword", keystorePassword);
}
@Bean
public Client feignClient() {
Client trustSSLSockets = new Client.Default(getSSLSocketFactory(), new NoopHostnameVerifier());
System.out.print("feignClient called");
return trustSSLSockets;
}
@Bean
@ConditionalOnMissingBean
public Feign.Builder feignBuilder(Retryer retryer) {
return Feign.builder().retryer(retryer);
}
@Bean
public Feign.Builder feignBuilder() {
return Feign.builder()
.retryer(Retryer.NEVER_RETRY)
.client(new Client.Default(getSSLSocketFactory(), null));
}
private SSLSocketFactory getSSLSocketFactory() {
char[] allPassword = keystorePassword.toCharArray();
SSLContext sslContext = null;
try {
sslContext = SSLContextBuilder
.create()
.setKeyStoreType(keystoreType)
.loadKeyMaterial(ResourceUtils.getFile(keystorePath), allPassword,allPassword)
.build();
} catch (Exception e) {
}
return sslContext.getSocketFactory();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
