Skip to content

Commit

Permalink
Client configuration build accepts TrustContextFactory (#2611)
Browse files Browse the repository at this point in the history
Overload client config creation method to allow a TrustContextFactory to be passed as well.
  • Loading branch information
jpcorreia99 authored Apr 25, 2023
1 parent f1e0ddb commit 9d1418f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-2611.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: Overload client config creation method to allow a TrustContextFactory
to be passed as well.
links:
- https://github.com/palantir/conjure-java-runtime/pull/2611
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.palantir.conjure.java.api.config.service.ProxyConfiguration;
import com.palantir.conjure.java.api.config.service.ServiceConfiguration;
import com.palantir.conjure.java.api.config.service.UserAgent;
import com.palantir.conjure.java.api.config.ssl.SslConfiguration;
import com.palantir.conjure.java.config.ssl.SslSocketFactories;
import com.palantir.conjure.java.config.ssl.TrustContext;
import com.palantir.logsafe.UnsafeArg;
Expand Down Expand Up @@ -76,7 +77,16 @@ private ClientConfigurations() {}
* empty/absent configuration with the defaults specified as constants in this class.
*/
public static ClientConfiguration of(ServiceConfiguration config) {
TrustContext trustContext = SslSocketFactories.createTrustContext(config.security());
return ClientConfigurations.of(config, SslSocketFactories::createTrustContext);
}

/**
* Creates a new {@link ClientConfiguration} instance from the given {@link ServiceConfiguration} and
* {@link TrustContextFactory}, filling in empty/absent configuration with the defaults specified as constants
* in this class.
*/
public static ClientConfiguration of(ServiceConfiguration config, TrustContextFactory factory) {
TrustContext trustContext = factory.create(config.security());
return ClientConfiguration.builder()
.sslSocketFactory(trustContext.sslSocketFactory())
.trustManager(trustContext.x509TrustManager())
Expand Down Expand Up @@ -248,4 +258,12 @@ public String toString() {
return "FixedProxySelector{proxy=" + proxy + '}';
}
}

/**
* A factory for {@link TrustContext} which allows to define how one will be created,
* based on implementer defined security configurations. See {@link SslConfiguration}.
*/
public interface TrustContextFactory {
TrustContext create(SslConfiguration configuration);
}
}

0 comments on commit 9d1418f

Please sign in to comment.