public class InstanceProfileCredentialsProvider extends java.lang.Object implements AWSCredentialsProvider
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ACCESS_KEY_ID
The name of the Json Object that contains the access key.
|
private static int |
ASYNC_REFRESH_INTERVAL_TIME_MINUTES
The wait time, after which the background thread initiates a refresh to
load latest credentials if needed.
|
protected AWSCredentials |
credentials
The current instance profile credentials
|
protected java.util.Date |
credentialsExpiration
The expiration for the current instance profile credentials
|
private java.util.concurrent.ScheduledExecutorService |
executor
The executor service used for refreshing the credentials in the
background.
|
private static int |
EXPIRATION_THRESHOLD
The threshold before credentials expire (in milliseconds) at which
this class will attempt to load new credentials.
|
protected java.util.Date |
lastInstanceProfileCheck
The time of the last attempt to check for new credentials
|
private static org.apache.commons.logging.Log |
LOG |
private static int |
REFRESH_THRESHOLD
The threshold after the last attempt to load credentials (in
milliseconds) at which credentials are attempted to be refreshed.
|
private static java.lang.String |
SECRET_ACCESS_KEY
The name of the Json Object that contains the secret access key.
|
private static java.lang.String |
TOKEN
The name of the Json Object that contains the token.
|
Constructor and Description |
---|
InstanceProfileCredentialsProvider() |
InstanceProfileCredentialsProvider(boolean refreshCredentialsAsync)
Spins up a new thread to refresh the credentials asynchronously if
refreshCredentialsAsync is set to true, otherwise the credentials will be
refreshed from the instance metadata service synchronously,
|
Modifier and Type | Method and Description |
---|---|
private boolean |
expired() |
protected void |
finalize() |
AWSCredentials |
getCredentials()
Returns AWSCredentials which the caller can use to authorize an AWS request.
|
private void |
handleError(java.lang.String errorMessage,
java.lang.Exception e)
Handles reporting or throwing an error encountered while requesting
credentials from the Amazon EC2 Instance Metadata Service.
|
private void |
handleError(java.lang.Throwable t) |
private boolean |
isPastRefreshThreshold()
Returns true if the last attempt to refresh credentials is beyond the
refresh threshold, and therefore the credentials should attempt to be
refreshed.
|
private boolean |
isWithinExpirationThreshold()
Returns true if the current credentials are within the expiration
threshold, and therefore, should be refreshed.
|
private void |
loadCredentials() |
protected boolean |
needsToLoadCredentials() |
void |
refresh()
Forces this credentials provider to refresh its credentials.
|
java.lang.String |
toString() |
private static final org.apache.commons.logging.Log LOG
private static final int REFRESH_THRESHOLD
private static final int EXPIRATION_THRESHOLD
private static final java.lang.String ACCESS_KEY_ID
private static final java.lang.String SECRET_ACCESS_KEY
private static final java.lang.String TOKEN
private static final int ASYNC_REFRESH_INTERVAL_TIME_MINUTES
protected volatile AWSCredentials credentials
protected volatile java.util.Date credentialsExpiration
protected volatile java.util.Date lastInstanceProfileCheck
private volatile java.util.concurrent.ScheduledExecutorService executor
public InstanceProfileCredentialsProvider()
public InstanceProfileCredentialsProvider(boolean refreshCredentialsAsync)
refreshCredentialsAsync
- true if credentials needs to be refreshed asynchronously else
false.private void handleError(java.lang.Throwable t)
public AWSCredentials getCredentials()
AWSCredentialsProvider
getCredentials
in interface AWSCredentialsProvider
public void refresh()
AWSCredentialsProvider
refresh
in interface AWSCredentialsProvider
protected boolean needsToLoadCredentials()
private boolean isWithinExpirationThreshold()
private boolean isPastRefreshThreshold()
private boolean expired()
private void loadCredentials()
private void handleError(java.lang.String errorMessage, java.lang.Exception e)
errorMessage
- A human readable description of the error.e
- The error that occurred.public java.lang.String toString()
toString
in class java.lang.Object
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable