use of com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticator method authKeyValueConnection.
@Override
public void authKeyValueConnection(final EndpointContext ctx, final ChannelPipeline pipeline) {
boolean tls = ctx.environment().securityConfig().tlsEnabled();
pipeline.addLast(new SaslListMechanismsHandler(ctx));
pipeline.addLast(new SaslAuthenticationHandler(ctx, username.get(), password.get(), tls ? EnumSet.of(SaslMechanism.PLAIN) : allowedSaslMechanisms));
}
use of com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticatorTest method ldapCompatibleOnlyEnablesPlain.
@Test
void ldapCompatibleOnlyEnablesPlain() {
PasswordAuthenticator authenticator = PasswordAuthenticator.ldapCompatible("user", "pass");
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(ENV);
EmbeddedChannel channel = new EmbeddedChannel();
authenticator.authKeyValueConnection(ctx, channel.pipeline());
SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
assertEquals(EnumSet.of(SaslMechanism.PLAIN), handler.allowedMechanisms());
}
use of com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticatorTest method allowsToEnablePlainInAddition.
@Test
void allowsToEnablePlainInAddition() {
PasswordAuthenticator authenticator = PasswordAuthenticator.builder().username("user").password("pass").enablePlainSaslMechanism().build();
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(ENV);
EmbeddedChannel channel = new EmbeddedChannel();
authenticator.authKeyValueConnection(ctx, channel.pipeline());
SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
assertEquals(EnumSet.allOf(SaslMechanism.class), handler.allowedMechanisms());
}
use of com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticatorTest method shouldOnlyNegotiatePlainWhenTlsEnabled.
/**
* Regression test for JVMCBC-890.
*/
@Test
void shouldOnlyNegotiatePlainWhenTlsEnabled() {
PasswordAuthenticator authenticator = PasswordAuthenticator.create("user", "pass");
CoreEnvironment tlsEnvironment = CoreEnvironment.builder().securityConfig(SecurityConfig.enableTls(true).trustManagerFactory(InsecureTrustManagerFactory.INSTANCE)).build();
try {
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(tlsEnvironment);
EmbeddedChannel channel = new EmbeddedChannel();
authenticator.authKeyValueConnection(ctx, channel.pipeline());
SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
assertEquals(EnumSet.of(SaslMechanism.PLAIN), handler.allowedMechanisms());
} finally {
tlsEnvironment.shutdown();
}
}
use of com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticatorTest method shouldNotNegotiatePlainWithNonTlsByDefault.
@Test
void shouldNotNegotiatePlainWithNonTlsByDefault() {
PasswordAuthenticator authenticator = PasswordAuthenticator.create("user", "pass");
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(ENV);
EmbeddedChannel channel = new EmbeddedChannel();
authenticator.authKeyValueConnection(ctx, channel.pipeline());
SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
assertFalse(handler.allowedMechanisms().contains(SaslMechanism.PLAIN));
}
Aggregations