private void doBearerAuth(boolean readOnlyBearerAuth, RegistryAuthenticator authenticator)
      throws RegistryException {
    initialBearerAuthenticator.set(authenticator);
    if (readOnlyBearerAuth) {
      authorization.set(authenticator.authenticatePull(credential));
    } else {
      authorization.set(authenticator.authenticatePush(credential));
    }
    this.readOnlyBearerAuth = readOnlyBearerAuth;

    eventHandlers.dispatch(
        LogEvent.debug(
            "bearer auth succeeded for "
                + registryEndpointRequestProperties.getServerUrl()
                + "/"
                + registryEndpointRequestProperties.getImageName()));
  }
Attempts bearer authentication for pull and push.

@return true if bearer authentication succeeded; false if the server expects basic
    authentication (and thus bearer authentication was not attempted)
@throws IOException if communicating with the endpoint fails
@throws RegistryException if communicating with the endpoint fails
@throws RegistryAuthenticationFailedException if authentication fails
@throws RegistryCredentialsNotSentException if authentication failed and credentials were not
    sent over plain HTTP
jib-core/src/main/java/com/google/cloud/tools/jib/registry/RegistryClient.java