class AutoRefreshCredentialProvider implements HerdAWSCredentialsProvider {

    @Override
    public AwsCredential getAwsCredential()
    {
        if (sessionExpirationTime == null || System.currentTimeMillis() >= sessionExpirationTime)
        {
            try
            {
                currentAwsCredentials = getNewAwsCredential();
            }
            catch (Exception e)
            {
                LOGGER.warn("Error retrieving new credentials. {}", e.toString(), e);
                throw new IllegalStateException(e);
            }
            sessionExpirationTime = currentAwsCredentials.getAwsSessionExpirationTime().toGregorianCalendar().getTimeInMillis();
        }
        return currentAwsCredentials;
    }

}