result.getCredentials().getSessionToken());
}
private BasicSessionCredentials getCachedCredentials(AwsCredential awsCredential) {
long dateNow = new Date().getTime();
TemporaryAwsCredentials temporaryAwsCredentials = awsCredential.getTemporaryAwsCredentials();
if (temporaryAwsCredentials != null) {
if (temporaryAwsCredentials.getValidUntil() > dateNow + FIVE_MINUTES) {
return new BasicSessionCredentials(
temporaryAwsCredentials.getAccessKeyId(),
temporaryAwsCredentials.getSecretAccessKey(),
temporaryAwsCredentials.getSessionToken());
} else {
awsCredential.setTemporaryAwsCredentials(null);
credentialRepository.save(awsCredential);
credentialsRepository.delete(temporaryAwsCredentials);
}