Search in sources :

Example 1 with SaslAuthenticationCompletedEvent

use of com.couchbase.client.core.cnc.events.io.SaslAuthenticationCompletedEvent in project couchbase-jvm-clients by couchbase.

the class SaslAuthenticationHandler method completeAuth.

/**
 * Helper method to complete the SASL auth successfully.
 */
private void completeAuth(final ChannelHandlerContext ctx, ByteBuf msg) throws SaslException {
    if (!saslClient.isComplete()) {
        // validate final server response
        ByteBuf responseBody = body(msg).orElse(Unpooled.EMPTY_BUFFER);
        byte[] payload = ByteBufUtil.getBytes(responseBody);
        saslClient.evaluateChallenge(payload);
        if (!saslClient.isComplete()) {
            throw new SaslException("Incomplete SASL exchange");
        }
    }
    Optional<Duration> latency = ConnectTimings.stop(ctx.channel(), this.getClass(), false);
    endpointContext.environment().eventBus().publish(new SaslAuthenticationCompletedEvent(latency.orElse(Duration.ZERO), ioContext));
    interceptedConnectPromise.trySuccess();
    ctx.pipeline().remove(this);
}
Also used : SaslAuthenticationCompletedEvent(com.couchbase.client.core.cnc.events.io.SaslAuthenticationCompletedEvent) Duration(java.time.Duration) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) SaslException(javax.security.sasl.SaslException)

Aggregations

SaslAuthenticationCompletedEvent (com.couchbase.client.core.cnc.events.io.SaslAuthenticationCompletedEvent)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 Duration (java.time.Duration)1 SaslException (javax.security.sasl.SaslException)1