@Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("bytebufList", ByteBufList.ENCODER_WITH_SIZE); pipeline.addLast("lengthbasedframedecoder", new LengthFieldBasedFrameDecoder(maxFrameSize, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("bookieProtoEncoder", new BookieProtoEncoding.RequestEncoder(extRegistry)); pipeline.addLast( "bookieProtoDecoder", new BookieProtoEncoding.ResponseDecoder(extRegistry, useV2WireProtocol)); pipeline.addLast("authHandler", new AuthHandler.ClientSideHandler(authProviderFactory, txnIdGenerator, connectionPeer, useV2WireProtocol)); pipeline.addLast("mainhandler", PerChannelBookieClient.this); } });
@Override public void operationComplete(int rc, Void v) { if (rc == BKException.Code.OK) { synchronized (this) { authenticated = true; Object msg = waitingForAuth.poll(); while (msg != null) { ctx.writeAndFlush(msg); msg = waitingForAuth.poll(); } } } else { LOG.warn("Client authentication failed"); authenticationError(ctx, rc); } } }
case AUTH: if (resp.getStatus() != BookkeeperProtocol.StatusCode.EOK) { authenticationError(ctx, resp.getStatus().getNumber()); } else { assert (resp.hasAuthResponse()); case BookieProtocol.AUTH: if (resp.errorCode != BookieProtocol.EOK) { authenticationError(ctx, resp.errorCode); } else { BookkeeperProtocol.AuthMessage am = ((BookieProtocol.AuthResponse) resp).authMessage;
public void operationComplete(int rc, AuthToken newam) { if (rc != BKException.Code.OK) { authenticationError(ctx, rc); return; } AuthMessage message = AuthMessage.newBuilder().setAuthPluginName(pluginName) .setPayload(ByteString.copyFrom(newam.getData())).build(); if (isUsingV2Protocol) { channel.writeAndFlush( new BookieProtocol.AuthRequest(BookieProtocol.CURRENT_PROTOCOL_VERSION, message), channel.voidPromise()); } else { // V3 protocol BookkeeperProtocol.BKPacketHeader header = BookkeeperProtocol.BKPacketHeader.newBuilder() .setVersion(BookkeeperProtocol.ProtocolVersion.VERSION_THREE) .setOperation(BookkeeperProtocol.OperationType.AUTH).setTxnId(newTxnId()).build(); BookkeeperProtocol.Request.Builder builder = BookkeeperProtocol.Request.newBuilder() .setHeader(header) .setAuthRequest(message); channel.writeAndFlush(builder.build()); } } }