Extend AuthenticationBuilder to support SSLContext for mTLS authentication#1907
Conversation
…ation Adds addSslContext(SSLContext) method to AuthenticationBuilder so that client certificate / mTLS credentials can be set via AuthenticationContext.SSL_CONTEXT, consistent with how transporters already consume it. Fixes apache#1851
| * | ||
| * @param sslContext the SSL context, may be {@code null} | ||
| * @return this builder for chaining, never {@code null} | ||
| */ |
There was a problem hiding this comment.
Please add @since
| */ | |
| * @since 2.0.19 | |
| */ |
| * this assumption, use {@link #addCustom(Authentication)} with a suitable implementation instead. | ||
| * | ||
| * @param sslContext the SSL context, may be {@code null} | ||
| * @return this builder for chaining, never {@code null} |
There was a problem hiding this comment.
Minor Javadoc suggestion: consider adding a @see cross-reference to AuthenticationContext.SSL_CONTEXT for discoverability, similar to how the constant's own Javadoc references javax.net.ssl.SSLContext:
| * @return this builder for chaining, never {@code null} | |
| * Adds an SSL context for SSL/TLS connections. <strong>Note:</strong> This method assumes that all possible | |
| * instances of the SSL context's runtime type exhibit the exact same behavior, i.e. the behavior of the SSL | |
| * context depends solely on the runtime type and not on any configuration. For SSL contexts that do not fit | |
| * this assumption, use {@link #addCustom(Authentication)} with a suitable implementation instead. | |
| * | |
| * @param sslContext the SSL context, may be {@code null} | |
| * @return this builder for chaining, never {@code null} | |
| * @see AuthenticationContext#SSL_CONTEXT | |
| */ |
This is purely optional — it helps users navigating the API discover the constant key and the Javadoc on it that describes the expected type.
|
Thanks for this contribution, @jiteshkhatri11! This is a well-motivated addition — What I checked:
One minor Javadoc suggestion (posted as an inline comment): consider adding On tests: I see the PR checklist has "Unit tests written" unchecked. There's no Overall this looks good to me. Clean, minimal, follows the established pattern. — gnodet |
Problem
AuthenticationBuildercurrently has no way to set anSSLContextforclient certificate / mTLS based authentication.
Although HTTP transporters already consume
AuthenticationContext.SSL_CONTEXT,for example in
JdkTransporter:there was no way for callers to actually set it via
AuthenticationBuilder.The only workaround was via system properties as described in
https://maven.apache.org/guides/mini/guide-repository-ssl.html
Closes #1851
Solution
Adds a new
addSslContext(SSLContext)method toAuthenticationBuilder,consistent with the existing
addHostnameVerifier(HostnameVerifier)pattern,so that mTLS credentials can be set and consumed through
AuthenticationContext.SSL_CONTEXT.Usage
Testing
mvn verifypasses locally — 422 tests, 0 failures, 0 errors.addSslContext()can be added if maintainer requests it.Checklist
mvn verifypassed locallyApache License Version 2.0, January 2004