Class DefaultCredentialsProvider


  • class DefaultCredentialsProvider
    extends java.lang.Object
    Provides the Application Default Credential from the environment.

    An instance represents the per-process state used to get and cache the credential and allows overriding the state and environment for testing purposes.

    • Field Detail

      • QUOTA_PROJECT_ENV_VAR

        static final java.lang.String QUOTA_PROJECT_ENV_VAR
        See Also:
        Constant Field Values
      • WELL_KNOWN_CREDENTIALS_FILE

        static final java.lang.String WELL_KNOWN_CREDENTIALS_FILE
        See Also:
        Constant Field Values
      • CLOUDSDK_CONFIG_DIRECTORY

        static final java.lang.String CLOUDSDK_CONFIG_DIRECTORY
        See Also:
        Constant Field Values
      • APP_ENGINE_SIGNAL_CLASS

        static final java.lang.String APP_ENGINE_SIGNAL_CLASS
        See Also:
        Constant Field Values
      • SKIP_APP_ENGINE_ENV_VAR

        static final java.lang.String SKIP_APP_ENGINE_ENV_VAR
        See Also:
        Constant Field Values
      • SPECIFICATION_VERSION

        static final java.lang.String SPECIFICATION_VERSION
      • GAE_RUNTIME_VERSION

        static final java.lang.String GAE_RUNTIME_VERSION
      • RUNTIME_JETTY_LOGGER

        static final java.lang.String RUNTIME_JETTY_LOGGER
      • LOGGER

        static final java.util.logging.Logger LOGGER
      • NO_GCE_CHECK_ENV_VAR

        static final java.lang.String NO_GCE_CHECK_ENV_VAR
        See Also:
        Constant Field Values
      • GCE_METADATA_HOST_ENV_VAR

        static final java.lang.String GCE_METADATA_HOST_ENV_VAR
        See Also:
        Constant Field Values
      • CLOUDSDK_CREDENTIALS_WARNING

        static final java.lang.String CLOUDSDK_CREDENTIALS_WARNING
        See Also:
        Constant Field Values
      • CLOUDSDK_MISSING_CREDENTIALS

        static final java.lang.String CLOUDSDK_MISSING_CREDENTIALS
        See Also:
        Constant Field Values
      • SUPPRESS_GCLOUD_CREDS_WARNING_ENV_VAR

        public static final java.lang.String SUPPRESS_GCLOUD_CREDS_WARNING_ENV_VAR
        See Also:
        Constant Field Values
      • checkedAppEngine

        private boolean checkedAppEngine
      • checkedComputeEngine

        private boolean checkedComputeEngine
    • Constructor Detail

      • DefaultCredentialsProvider

        DefaultCredentialsProvider()
    • Method Detail

      • getDefaultCredentials

        final GoogleCredentials getDefaultCredentials​(HttpTransportFactory transportFactory)
                                               throws java.io.IOException
        Returns the Application Default Credentials.

        Returns the Application Default Credentials which are used to identify and authorize the whole application. The following are searched (in order) to find the Application Default Credentials:

        1. Credentials file pointed to by the GOOGLE_APPLICATION_CREDENTIALS environment variable
        2. Credentials provided by the Google Cloud SDK gcloud auth application-default login command
        3. Google App Engine built-in credentials
        4. Google Cloud Shell built-in credentials
        5. Google Compute Engine built-in credentials
        Parameters:
        transportFactory - HTTP transport factory, creates the transport used to get access tokens.
        Returns:
        the credentials instance.
        Throws:
        java.io.IOException - if the credentials cannot be created in the current environment.
      • getDefaultCredentialsUnsynchronized

        private final GoogleCredentials getDefaultCredentialsUnsynchronized​(HttpTransportFactory transportFactory)
                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getWellKnownCredentialsFile

        private final java.io.File getWellKnownCredentialsFile()
      • warnAboutProblematicCredentials

        private void warnAboutProblematicCredentials​(GoogleCredentials credentials)
      • runningOnAppEngine

        private boolean runningOnAppEngine()
      • tryGetCloudShellCredentials

        private GoogleCredentials tryGetCloudShellCredentials()
      • tryGetAppEngineCredential

        private GoogleCredentials tryGetAppEngineCredential()
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • skipAppEngineCredentialsCheck

        private boolean skipAppEngineCredentialsCheck()
      • isOnGAEStandard7

        protected boolean isOnGAEStandard7()
      • getOsName

        java.lang.String getOsName()
      • forName

        java.lang.Class<?> forName​(java.lang.String className)
                            throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • getEnv

        java.lang.String getEnv​(java.lang.String name)
      • getProperty

        java.lang.String getProperty​(java.lang.String property,
                                     java.lang.String def)
      • isFile

        boolean isFile​(java.io.File file)
      • readStream

        java.io.InputStream readStream​(java.io.File file)
                                throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException