@@ -89,7 +89,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
89
89
super .channelRead (ctx , msg );
90
90
} else if (msg instanceof BookieProtocol .AuthRequest ) { // pre-PB-client
91
91
BookieProtocol .AuthRequest req = (BookieProtocol .AuthRequest ) msg ;
92
- assert (req .getOpCode () == BookieProtocol .AUTH );
92
+ if (BookieProtocol .AUTH != req .getOpCode ()) {
93
+ throw new IllegalStateException ("Received message other than auth message" );
94
+ }
93
95
if (checkAuthPlugin (req .getAuthMessage (), ctx .channel ())) {
94
96
byte [] payload = req
95
97
.getAuthMessage ()
@@ -270,45 +272,44 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
270
272
271
273
@ Override
272
274
public void channelRead (ChannelHandlerContext ctx , Object msg ) throws Exception {
273
- assert (authProvider != null );
275
+ if (authProvider == null ) {
276
+ throw new IllegalStateException ("Auth provider is not initialized" );
277
+ }
274
278
275
279
if (authenticated ) {
276
280
super .channelRead (ctx , msg );
277
281
} else if (msg instanceof BookkeeperProtocol .Response ) {
278
282
BookkeeperProtocol .Response resp = (BookkeeperProtocol .Response ) msg ;
279
- if (null == resp .getHeader ().getOperation ()) {
280
- LOG .info ("dropping received malformed message {} from bookie {}" , msg , ctx .channel ());
281
- // drop the message without header
282
- } else {
283
- switch (resp .getHeader ().getOperation ()) {
284
- case START_TLS :
285
- super .channelRead (ctx , msg );
286
- break ;
287
- case AUTH :
288
- if (resp .getStatus () != BookkeeperProtocol .StatusCode .EOK ) {
289
- authenticationError (ctx , resp .getStatus ().getNumber ());
290
- } else {
291
- assert (resp .hasAuthResponse ());
292
- BookkeeperProtocol .AuthMessage am = resp .getAuthResponse ();
293
- if (AUTHENTICATION_DISABLED_PLUGIN_NAME .equals (am .getAuthPluginName ())){
294
- SocketAddress remote = ctx .channel ().remoteAddress ();
295
- LOG .info ("Authentication is not enabled."
283
+ switch (resp .getHeader ().getOperation ()) {
284
+ case START_TLS :
285
+ super .channelRead (ctx , msg );
286
+ break ;
287
+ case AUTH :
288
+ if (resp .getStatus () != BookkeeperProtocol .StatusCode .EOK ) {
289
+ authenticationError (ctx , resp .getStatus ().getNumber ());
290
+ } else {
291
+ if (!resp .hasAuthResponse ()) {
292
+ throw new IllegalStateException ("Auth response is missing in the message" );
293
+ }
294
+ AuthMessage am = resp .getAuthResponse ();
295
+ if (AUTHENTICATION_DISABLED_PLUGIN_NAME .equals (am .getAuthPluginName ())) {
296
+ SocketAddress remote = ctx .channel ().remoteAddress ();
297
+ LOG .info ("Authentication is not enabled."
296
298
+ "Considering this client {} authenticated" , remote );
297
- AuthHandshakeCompleteCallback cb = new AuthHandshakeCompleteCallback (ctx );
298
- cb .operationComplete (BKException .Code .OK , null );
299
- return ;
300
- }
301
- byte [] payload = am .getPayload ().toByteArray ();
302
- authProvider .process (AuthToken .wrap (payload ), new AuthRequestCallback (ctx ,
303
- authProviderFactory .getPluginName ()));
299
+ AuthHandshakeCompleteCallback cb = new AuthHandshakeCompleteCallback (ctx );
300
+ cb .operationComplete (BKException .Code .OK , null );
301
+ return ;
304
302
}
305
- break ;
306
- default :
307
- LOG .warn ("dropping received message {} from bookie {}" , msg , ctx .channel ());
308
- // else just drop the message,
309
- // we're not authenticated so nothing should be coming through
310
- break ;
303
+ byte [] payload = am .getPayload ().toByteArray ();
304
+ authProvider .process (AuthToken .wrap (payload ), new AuthRequestCallback (ctx ,
305
+ authProviderFactory .getPluginName ()));
311
306
}
307
+ break ;
308
+ default :
309
+ LOG .warn ("dropping received message {} from bookie {}" , msg , ctx .channel ());
310
+ // else just drop the message,
311
+ // we're not authenticated so nothing should be coming through
312
+ break ;
312
313
}
313
314
} else if (msg instanceof BookieProtocol .Response ) {
314
315
BookieProtocol .Response resp = (BookieProtocol .Response ) msg ;
0 commit comments