Skip to content

Commit 65f1ad3

Browse files
committed
Gardening: Authenticator.requiresTls()
Modifications ------------- Merge supportsTls() and supportsNonTls() into a single method: requiresTls() Having two methods was fussy, and we're unlikely to add an authenticator that strictly requires the _absence_ of TLS. Change-Id: I7afe3ee51b64a7f8b0c9fc2339a8a3c13cb33d45 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/233961 Reviewed-by: Michael Reiche <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 411cb33 commit 65f1ad3

File tree

6 files changed

+12
-28
lines changed

6 files changed

+12
-28
lines changed

core-io/src/main/java/com/couchbase/client/core/Core.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ protected Core(
282282
final Authenticator authenticator,
283283
final ConnectionString connectionString
284284
) {
285-
if (environment.securityConfig().tlsEnabled() && !authenticator.supportsTls()) {
286-
throw new InvalidArgumentException("TLS enabled but the Authenticator does not support TLS!", null, null);
287-
} else if (!environment.securityConfig().tlsEnabled() && !authenticator.supportsNonTls()) {
285+
if (authenticator.requiresTls() && !environment.securityConfig().tlsEnabled()) {
288286
throw new InvalidArgumentException("TLS not enabled but the Authenticator requires TLS!", null, null);
289287
}
290288

core-io/src/main/java/com/couchbase/client/core/env/Authenticator.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,9 @@ default void authHttpRequest(final ServiceType serviceType, final HttpRequest re
7070
@Stability.Internal
7171
default void applyTlsProperties(final SslContextBuilder sslContextBuilder) { }
7272

73-
/**
74-
* If this authenticator supports encrypted connections.
75-
*/
76-
@Stability.Internal
77-
default boolean supportsTls() { return true; }
78-
79-
/**
80-
* If this authenticator supports non-encrypted connections.
81-
*/
8273
@Stability.Internal
83-
default boolean supportsNonTls() { return true; }
74+
default boolean requiresTls() {
75+
return true;
76+
}
8477

8578
}

core-io/src/main/java/com/couchbase/client/core/env/AuthenticatorWrapper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ public void applyTlsProperties(final SslContextBuilder sslContextBuilder) {
5353
}
5454

5555
@Override
56-
public boolean supportsTls() {
57-
return wrapped().supportsTls();
58-
}
59-
60-
@Override
61-
public boolean supportsNonTls() {
62-
return wrapped().supportsNonTls();
56+
public boolean requiresTls() {
57+
return wrapped().requiresTls();
6358
}
6459
}

core-io/src/main/java/com/couchbase/client/core/env/CertificateAuthenticator.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ public void applyTlsProperties(final SslContextBuilder context) {
151151
}
152152
}
153153

154-
@Override
155-
public boolean supportsNonTls() {
156-
return false;
157-
}
158-
159154
@Override
160155
public String toString() {
161156
// Intentionally omit sensitive info like private key.

core-io/src/main/java/com/couchbase/client/core/env/PasswordAuthenticator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public void thisUsesUnstableApi() {
200200
};
201201
}
202202

203+
@Override
204+
public boolean requiresTls() {
205+
return false;
206+
}
207+
203208
/**
204209
* Provides customization to the {@link PasswordAuthenticator}.
205210
*/

core-io/src/main/java/com/couchbase/client/core/protostellar/ProtostellarContext.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ public ProtostellarContext(final CoreEnvironment env, final Authenticator authen
4242
this.authenticator = requireNonNull(authenticator);
4343
this.coreResources = requireNonNull(coreResources);
4444

45-
if (env.securityConfig().tlsEnabled() && !authenticator.supportsTls()) {
46-
throw InvalidArgumentException.fromMessage("TLS enabled but the Authenticator does not support TLS!");
47-
} else if (!env.securityConfig().tlsEnabled() && !authenticator.supportsNonTls()) {
45+
if (authenticator.requiresTls() && !env.securityConfig().tlsEnabled()) {
4846
throw InvalidArgumentException.fromMessage("TLS not enabled but the Authenticator requires TLS!");
4947
}
5048
}

0 commit comments

Comments
 (0)