BrokerAuthenticator implements IAuthenticator { @Override public boolean checkValid(String clientId, String username, byte[] password) { if (StringUtils.isBlank(username) || password == null) { return false; } try { IAuthorizer authorizer = BasicAuthorizer.getInstance(); return authorizer.login(username, new String(password)); } catch (AuthException e) { LOG.info("meet error while logging in.", e); return false; } }  @Override boolean checkValid(String clientId, String username, byte[] password);  }
@Test public void checkValid() { BrokerAuthenticator authenticator = new BrokerAuthenticator(); assertTrue(authenticator.checkValid(null, "root", "root".getBytes())); assertFalse(authenticator.checkValid(null, "", "foo".getBytes())); assertFalse(authenticator.checkValid(null, "root", null)); assertFalse(authenticator.checkValid(null, "foo", "foo".getBytes())); }