private void handleListMechsResponse ( final ChannelHandlerContext ctx , final ByteBuf msg ) throws Exception { String remote = ctx . channel ( ) . remoteAddress ( ) . toString ( ) ; String [ ] supportedMechanisms = SaslListMechsResponse . supportedMechs ( msg ) ; if ( supportedMechanisms . length == 0 ) { throw new AuthenticationException ( "Received empty SASL mechanisms list from server: " + remote ) ; } saslClient = Sasl . createSaslClient ( supportedMechanisms , null , "couchbase" , remote , null , this ) ; selectedMechanism = saslClient . getMechanismName ( ) ; byte [ ] bytePayload = saslClient . hasInitialResponse ( ) ? saslClient . evaluateChallenge ( new byte [ ] { } ) : null ; ByteBuf payload = bytePayload != null ? ctx . alloc ( ) . buffer ( ) . writeBytes ( bytePayload ) : Unpooled . EMPTY_BUFFER ; ByteBuf request = ctx . alloc ( ) . buffer ( ) ; SaslAuthRequest . init ( request ) ; SaslAuthRequest . mechanism ( selectedMechanism , request ) ; SaslAuthRequest . challengeResponse ( payload , request ) ; payload . release ( ) ; ChannelFuture future = ctx . writeAndFlush ( request ) ; future . addListener ( new GenericFutureListener < Future < Void > > ( ) { @ Override public void operationComplete ( Future < Void > future ) throws Exception { if ( ! future . isSuccess ( ) ) { LOGGER . warn ( "Error during SASL Auth negotiation phase." , future ) ; originalPromise ( ) . setFailure ( future . cause ( ) ) ; } } } ) ; }
Helper method to parse the list of supported SASL mechs and dispatch the initial auth request following .