public Optional<Long> getTokenTimeout(
      final Optional<String> token,
      final KsqlConfig ksqlConfig,
      final Optional<KsqlAuthTokenProvider> authTokenProvider
  ) {
    final long maxTimeout =
        ksqlConfig.getLong(KsqlConfig.KSQL_WEBSOCKET_CONNECTION_MAX_TIMEOUT_MS);
    if (maxTimeout > 0) {
      if (authTokenProvider.isPresent() && token.isPresent()) {
        try {
          final long tokenTimeout = authTokenProvider.get()
              .getLifetimeMs(StringUtils.removeStart(token.get(), BEARER)) - clock.millis();
          return Optional.of(Math.min(tokenTimeout, maxTimeout));
        } catch (final Exception e) {
          log.error(e.getMessage());
        }
      }
      return Optional.of(maxTimeout);
    } else {
      return Optional.empty();
    }
  }
@Test
  public void shouldReturnDefaultWhenNoAuthTokenProviderPresent() {
    assertThat(authenticationUtil.getTokenTimeout(Optional.of(TOKEN), ksqlConfig, Optional.empty()), equalTo(Optional.of(60000L)));
  }