@VisibleForTesting
  void authenticateIfRequired(Connection conn) {
    cancelCriterion.checkCancelInProgress(null);

    if (pool.isUsedByGateway() || pool.getMultiuserAuthentication()) {
      return;
    }

    ServerLocation server = conn.getServer();
    if (!server.getRequiresCredentials()) {
      return;
    }

    // make this block synchronized so that when a AuthenticateUserOp is already in progress,
    // another thread won't try to authenticate again.
    synchronized (server) {
      if (server.getUserId() != -1) {
        return;
      }
      Long uniqueID = AuthenticateUserOp.executeOn(conn, pool);
      // if connection failed, this would return null, instead of throwing a NPE, we should throw
      // this
      if (uniqueID == null) {
        throw new ServerConnectivityException("Connection refused");
      }
      server.setUserId(uniqueID);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("CFI.authenticateIfRequired() Completed authentication on {}", conn);
    }
  }
Test hook for client version support

@since GemFire 5.7
geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionFactoryImpl.java