CA cert or client cert-key pair could be optional
This commit is contained in:
parent
9c3fae2f8e
commit
de7e25f731
@ -16,7 +16,6 @@
|
|||||||
package org.thingsboard.rule.engine.credentials;
|
package org.thingsboard.rule.engine.credentials;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import io.netty.handler.ssl.ClientAuth;
|
|
||||||
import io.netty.handler.ssl.SslContext;
|
import io.netty.handler.ssl.SslContext;
|
||||||
import io.netty.handler.ssl.SslContextBuilder;
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -66,11 +65,14 @@ public class CertPemCredentials {
|
|||||||
public Optional<SslContext> initSslContext() {
|
public Optional<SslContext> initSslContext() {
|
||||||
try {
|
try {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
return Optional.of(SslContextBuilder.forClient()
|
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||||
.keyManager(createAndInitKeyManagerFactory())
|
if (StringUtils.hasLength(caCert)) {
|
||||||
.trustManager(createAndInitTrustManagerFactory())
|
builder.trustManager(createAndInitTrustManagerFactory());
|
||||||
.clientAuth(ClientAuth.REQUIRE)
|
}
|
||||||
.build());
|
if (StringUtils.hasLength(cert) && StringUtils.hasLength(privateKey)) {
|
||||||
|
builder.keyManager(createAndInitKeyManagerFactory());
|
||||||
|
}
|
||||||
|
return Optional.of(builder.build());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[{}:{}] Creating TLS factory failed!", caCert, cert, e);
|
log.error("[{}:{}] Creating TLS factory failed!", caCert, cert, e);
|
||||||
throw new RuntimeException("Creating TLS factory failed!", e);
|
throw new RuntimeException("Creating TLS factory failed!", e);
|
||||||
|
|||||||
@ -17,7 +17,6 @@ package org.thingsboard.rule.engine.rest;
|
|||||||
|
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.handler.ssl.SslContext;
|
|
||||||
import io.netty.handler.ssl.SslContextBuilder;
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -134,7 +133,7 @@ public class TbHttpClient {
|
|||||||
} else {
|
} else {
|
||||||
this.eventLoopGroup = new NioEventLoopGroup();
|
this.eventLoopGroup = new NioEventLoopGroup();
|
||||||
Netty4ClientHttpRequestFactory nettyFactory = new Netty4ClientHttpRequestFactory(this.eventLoopGroup);
|
Netty4ClientHttpRequestFactory nettyFactory = new Netty4ClientHttpRequestFactory(this.eventLoopGroup);
|
||||||
nettyFactory.setSslContext(initSslContext());
|
nettyFactory.setSslContext(config.getCredentials().initSslContext().orElse(SslContextBuilder.forClient().build()));
|
||||||
nettyFactory.setReadTimeout(config.getReadTimeoutMs());
|
nettyFactory.setReadTimeout(config.getReadTimeoutMs());
|
||||||
httpClient = new AsyncRestTemplate(nettyFactory);
|
httpClient = new AsyncRestTemplate(nettyFactory);
|
||||||
}
|
}
|
||||||
@ -143,11 +142,6 @@ public class TbHttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SslContext initSslContext() throws SSLException {
|
|
||||||
return this.config.getCredentials().initSslContext()
|
|
||||||
.orElse(SslContextBuilder.forClient().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkSystemProxyProperties() throws TbNodeException {
|
private void checkSystemProxyProperties() throws TbNodeException {
|
||||||
boolean useHttpProxy = !StringUtils.isEmpty(System.getProperty("http.proxyHost")) && !StringUtils.isEmpty(System.getProperty("http.proxyPort"));
|
boolean useHttpProxy = !StringUtils.isEmpty(System.getProperty("http.proxyHost")) && !StringUtils.isEmpty(System.getProperty("http.proxyPort"));
|
||||||
boolean useHttpsProxy = !StringUtils.isEmpty(System.getProperty("https.proxyHost")) && !StringUtils.isEmpty(System.getProperty("https.proxyPort"));
|
boolean useHttpsProxy = !StringUtils.isEmpty(System.getProperty("https.proxyHost")) && !StringUtils.isEmpty(System.getProperty("https.proxyPort"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user