Skip to content

Commit 411cb33

Browse files
committed
Gardening: AuthenticatorWrapper polish
Motivation ---------- Minimize the impact of forthcoming changes to the Authenticator interface. Modifications ------------- Make AuthenticatorWrapper visible outside its package, so it can be extended by Columnar's DynamicAuthenticator and Scala's own PasswordAuthenticator. Change-Id: Idf846a3adcd449d0ca67b01a12b38e12f427f39f Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/233960 Tested-by: Build Bot <[email protected]> Reviewed-by: Michael Reiche <[email protected]>
1 parent 9991dcd commit 411cb33

File tree

4 files changed

+10
-70
lines changed

4 files changed

+10
-70
lines changed

columnar-java-client/src/main/java/com/couchbase/columnar/client/java/internal/DynamicAuthenticator.java

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616

1717
package com.couchbase.columnar.client.java.internal;
1818

19-
import com.couchbase.client.core.deps.io.grpc.CallCredentials;
20-
import com.couchbase.client.core.deps.io.netty.channel.ChannelPipeline;
21-
import com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpRequest;
22-
import com.couchbase.client.core.deps.io.netty.handler.ssl.SslContextBuilder;
23-
import com.couchbase.client.core.endpoint.EndpointContext;
2419
import com.couchbase.client.core.env.Authenticator;
25-
import com.couchbase.client.core.service.ServiceType;
20+
import com.couchbase.client.core.env.AuthenticatorWrapper;
2621
import org.jetbrains.annotations.ApiStatus;
27-
import org.jspecify.annotations.Nullable;
2822

2923
import java.util.function.Supplier;
3024

@@ -35,40 +29,15 @@
3529
* given supplier.
3630
*/
3731
@ApiStatus.Internal
38-
public class DynamicAuthenticator implements Authenticator {
32+
public class DynamicAuthenticator extends AuthenticatorWrapper {
3933
private final Supplier<Authenticator> supplier;
4034

4135
public DynamicAuthenticator(Supplier<Authenticator> supplier) {
4236
this.supplier = requireNonNull(supplier);
4337
}
4438

4539
@Override
46-
public void authKeyValueConnection(final EndpointContext endpointContext, final ChannelPipeline pipeline) {
47-
supplier.get().authKeyValueConnection(endpointContext, pipeline);
48-
}
49-
50-
@Override
51-
public void authHttpRequest(final ServiceType serviceType, final HttpRequest request) {
52-
supplier.get().authHttpRequest(serviceType, request);
53-
}
54-
55-
@Override
56-
public @Nullable CallCredentials protostellarCallCredentials() {
57-
return supplier.get().protostellarCallCredentials();
58-
}
59-
60-
@Override
61-
public void applyTlsProperties(final SslContextBuilder sslContextBuilder) {
62-
supplier.get().applyTlsProperties(sslContextBuilder);
63-
}
64-
65-
@Override
66-
public boolean supportsTls() {
67-
return supplier.get().supportsTls();
68-
}
69-
70-
@Override
71-
public boolean supportsNonTls() {
72-
return supplier.get().supportsNonTls();
40+
protected Authenticator wrapped() {
41+
return supplier.get();
7342
}
7443
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
@NullMarked
3030
@Stability.Internal
31-
abstract class AuthenticatorWrapper implements Authenticator {
31+
public abstract class AuthenticatorWrapper implements Authenticator {
3232

33-
abstract Authenticator wrapped();
33+
protected abstract Authenticator wrapped();
3434

3535
@Override
3636
public void authKeyValueConnection(final EndpointContext endpointContext, final ChannelPipeline pipeline) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setDelegate(Authenticator delegate) {
4949
setDelegate(delegate);
5050
}
5151

52-
Authenticator wrapped() {
52+
protected Authenticator wrapped() {
5353
return delegate;
5454
}
5555

scala-client/src/main/scala/com/couchbase/client/scala/env/PasswordAuthenticator.scala

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,11 @@
1515
*/
1616
package com.couchbase.client.scala.env
1717

18-
import com.couchbase.client.core.deps.io.grpc.CallCredentials
19-
import com.couchbase.client.core.deps.io.netty.channel.ChannelPipeline
20-
import com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpRequest
21-
import com.couchbase.client.core.endpoint.EndpointContext
22-
import com.couchbase.client.core.env.Authenticator
23-
import com.couchbase.client.core.service.ServiceType
18+
import com.couchbase.client.core.env.{Authenticator, AuthenticatorWrapper}
2419

25-
case class PasswordAuthenticator(username: String, password: String) extends Authenticator {
20+
case class PasswordAuthenticator(username: String, password: String) extends AuthenticatorWrapper {
2621

2722
private val inner = com.couchbase.client.core.env.PasswordAuthenticator.create(username, password)
2823

29-
/** Allows the authenticator to add KV handlers during connection bootstrap to perform
30-
* authentication.
31-
*
32-
* @param endpointContext the endpoint context.
33-
* @param pipeline the pipeline when the endpoint is constructed.
34-
*/
35-
override def authKeyValueConnection(
36-
endpointContext: EndpointContext,
37-
pipeline: ChannelPipeline
38-
): Unit = {
39-
inner.authKeyValueConnection(endpointContext, pipeline)
40-
}
41-
42-
/** Allows to add authentication credentials to the http request for the given service.
43-
*
44-
* @param serviceType the service for this request.
45-
* @param request the http request.
46-
*/
47-
override def authHttpRequest(serviceType: ServiceType, request: HttpRequest): Unit = {
48-
inner.authHttpRequest(serviceType, request)
49-
}
50-
51-
override def protostellarCallCredentials(): CallCredentials = {
52-
inner.protostellarCallCredentials()
53-
}
24+
override protected def wrapped(): Authenticator = inner
5425
}

0 commit comments

Comments
 (0)