Package com.google.auth.oauth2
Class DefaultCredentialsProvider
- java.lang.Object
-
- com.google.auth.oauth2.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 Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
APP_ENGINE_SIGNAL_CLASS
private GoogleCredentials
cachedCredentials
private boolean
checkedAppEngine
private boolean
checkedComputeEngine
(package private) static java.lang.String
CLOUD_SHELL_ENV_VAR
(package private) static java.lang.String
CLOUDSDK_CLIENT_ID
(package private) static java.lang.String
CLOUDSDK_CONFIG_DIRECTORY
(package private) static java.lang.String
CLOUDSDK_CREDENTIALS_WARNING
(package private) static java.lang.String
CLOUDSDK_MISSING_CREDENTIALS
(package private) static java.lang.String
CREDENTIAL_ENV_VAR
(package private) static DefaultCredentialsProvider
DEFAULT
(package private) static java.lang.String
GAE_RUNTIME_VERSION
(package private) static java.lang.String
GCE_METADATA_HOST_ENV_VAR
(package private) static java.util.logging.Logger
LOGGER
(package private) static java.lang.String
NO_GCE_CHECK_ENV_VAR
(package private) static java.lang.String
QUOTA_PROJECT_ENV_VAR
(package private) static java.lang.String
RUNTIME_JETTY_LOGGER
(package private) static java.lang.String
SKIP_APP_ENGINE_ENV_VAR
(package private) static java.lang.String
SPECIFICATION_VERSION
static java.lang.String
SUPPRESS_GCLOUD_CREDS_WARNING_ENV_VAR
(package private) static java.lang.String
WELL_KNOWN_CREDENTIALS_FILE
-
Constructor Summary
Constructors Constructor Description DefaultCredentialsProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Class<?>
forName(java.lang.String className)
(package private) GoogleCredentials
getDefaultCredentials(HttpTransportFactory transportFactory)
Returns the Application Default Credentials.private GoogleCredentials
getDefaultCredentialsUnsynchronized(HttpTransportFactory transportFactory)
(package private) java.lang.String
getEnv(java.lang.String name)
(package private) java.lang.String
getOsName()
(package private) java.lang.String
getProperty(java.lang.String property, java.lang.String def)
private java.io.File
getWellKnownCredentialsFile()
(package private) boolean
isFile(java.io.File file)
protected boolean
isOnGAEStandard7()
(package private) java.io.InputStream
readStream(java.io.File file)
private boolean
runningOnAppEngine()
private boolean
skipAppEngineCredentialsCheck()
private GoogleCredentials
tryGetAppEngineCredential()
private GoogleCredentials
tryGetCloudShellCredentials()
private GoogleCredentials
tryGetComputeCredentials(HttpTransportFactory transportFactory)
private void
warnAboutProblematicCredentials(GoogleCredentials credentials)
-
-
-
Field Detail
-
DEFAULT
static final DefaultCredentialsProvider DEFAULT
-
CREDENTIAL_ENV_VAR
static final java.lang.String CREDENTIAL_ENV_VAR
- See Also:
- Constant Field Values
-
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
-
CLOUD_SHELL_ENV_VAR
static final java.lang.String CLOUD_SHELL_ENV_VAR
- 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_CLIENT_ID
static final java.lang.String CLOUDSDK_CLIENT_ID
- 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
-
cachedCredentials
private GoogleCredentials cachedCredentials
-
checkedAppEngine
private boolean checkedAppEngine
-
checkedComputeEngine
private boolean checkedComputeEngine
-
-
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:
- Credentials file pointed to by the
GOOGLE_APPLICATION_CREDENTIALS
environment variable - Credentials provided by the Google Cloud SDK
gcloud auth application-default login
command - Google App Engine built-in credentials
- Google Cloud Shell built-in credentials
- 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.
- Credentials file pointed to by the
-
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
-
tryGetComputeCredentials
private final GoogleCredentials tryGetComputeCredentials(HttpTransportFactory transportFactory)
-
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
-
-