Search in sources :

Example 1 with SaslAuthenticationHandler

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));
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) SaslListMechanismsHandler(com.couchbase.client.core.io.netty.kv.SaslListMechanismsHandler)

Example 2 with SaslAuthenticationHandler

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());
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 3 with SaslAuthenticationHandler

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());
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 4 with SaslAuthenticationHandler

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();
    }
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 5 with SaslAuthenticationHandler

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));
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Aggregations

SaslAuthenticationHandler (com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler)5 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)4 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)4 Test (org.junit.jupiter.api.Test)4 SaslListMechanismsHandler (com.couchbase.client.core.io.netty.kv.SaslListMechanismsHandler)1