/** * Retrieves a fresh set of credentials if there is no current cached credentials, or the session has expired. Otherwise, returns the cached credentials. */ @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; } }
/** * Retrieves a fresh set of credentials if there is no current cached credentials, or the session has expired. Otherwise, returns the cached credentials. */ @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; } }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); strategy.appendField(locator, this, "awsAccessKey", buffer, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); strategy.appendField(locator, this, "awsSecretKey", buffer, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); strategy.appendField(locator, this, "awsSessionToken", buffer, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); strategy.appendField(locator, this, "awsSessionExpirationTime", buffer, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); strategy.appendField(locator, this, "awsAccessKey", buffer, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); strategy.appendField(locator, this, "awsSecretKey", buffer, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); strategy.appendField(locator, this, "awsSessionToken", buffer, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); strategy.appendField(locator, this, "awsSessionExpirationTime", buffer, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return buffer; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); strategy.appendField(locator, this, "awsAccessKey", buffer, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); strategy.appendField(locator, this, "awsSecretKey", buffer, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); strategy.appendField(locator, this, "awsSessionToken", buffer, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); strategy.appendField(locator, this, "awsSessionExpirationTime", buffer, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return buffer; }
lhsAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar rhsAwsSessionExpirationTime; rhsAwsSessionExpirationTime = that.getAwsSessionExpirationTime(); if (!strategy.equals(LocatorUtils.property(thisLocator, "awsSessionExpirationTime", lhsAwsSessionExpirationTime), LocatorUtils.property(thatLocator, "awsSessionExpirationTime", rhsAwsSessionExpirationTime), lhsAwsSessionExpirationTime, rhsAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null), (that.awsSessionExpirationTime!= null))) { return false;
lhsAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar rhsAwsSessionExpirationTime; rhsAwsSessionExpirationTime = that.getAwsSessionExpirationTime(); if (!strategy.equals(LocatorUtils.property(thisLocator, "awsSessionExpirationTime", lhsAwsSessionExpirationTime), LocatorUtils.property(thatLocator, "awsSessionExpirationTime", rhsAwsSessionExpirationTime), lhsAwsSessionExpirationTime, rhsAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null), (that.awsSessionExpirationTime!= null))) { return false;
lhsAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar rhsAwsSessionExpirationTime; rhsAwsSessionExpirationTime = that.getAwsSessionExpirationTime(); if (!strategy.equals(LocatorUtils.property(thisLocator, "awsSessionExpirationTime", lhsAwsSessionExpirationTime), LocatorUtils.property(thatLocator, "awsSessionExpirationTime", rhsAwsSessionExpirationTime), lhsAwsSessionExpirationTime, rhsAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null), (that.awsSessionExpirationTime!= null))) { return false;
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsAccessKey", theAwsAccessKey), currentHashCode, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSecretKey", theAwsSecretKey), currentHashCode, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionToken", theAwsSessionToken), currentHashCode, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionExpirationTime", theAwsSessionExpirationTime), currentHashCode, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsAccessKey", theAwsAccessKey), currentHashCode, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSecretKey", theAwsSecretKey), currentHashCode, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionToken", theAwsSessionToken), currentHashCode, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionExpirationTime", theAwsSessionExpirationTime), currentHashCode, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return currentHashCode; }
public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) { int currentHashCode = 1; { String theAwsAccessKey; theAwsAccessKey = this.getAwsAccessKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsAccessKey", theAwsAccessKey), currentHashCode, theAwsAccessKey, (this.awsAccessKey!= null)); } { String theAwsSecretKey; theAwsSecretKey = this.getAwsSecretKey(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSecretKey", theAwsSecretKey), currentHashCode, theAwsSecretKey, (this.awsSecretKey!= null)); } { String theAwsSessionToken; theAwsSessionToken = this.getAwsSessionToken(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionToken", theAwsSessionToken), currentHashCode, theAwsSessionToken, (this.awsSessionToken!= null)); } { XMLGregorianCalendar theAwsSessionExpirationTime; theAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "awsSessionExpirationTime", theAwsSessionExpirationTime), currentHashCode, theAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null)); } return currentHashCode; }
assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionExpirationTime());
@Test public void getStorageUnitDownloadCredential() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setNamespace(NAMESPACE); businessObjectDataKey.setBusinessObjectDefinitionName(BDEF_NAME); businessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); businessObjectDataKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE); businessObjectDataKey.setBusinessObjectFormatVersion(FORMAT_VERSION); businessObjectDataKey.setPartitionValue(PARTITION_VALUE); businessObjectDataKey.setBusinessObjectDataVersion(DATA_VERSION); String storageName = STORAGE_NAME; createBusinessObjectFormatEntity(businessObjectDataKey); // Create an S3 storage entity. List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_DOWNLOAD_ROLE_ARN), "testRole")); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket")); attributes.add( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE)); storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3, attributes); StorageUnitDownloadCredential storageUnitDownloadCredential = storageUnitService.getStorageUnitDownloadCredential(businessObjectDataKey, storageName); assertNotNull(storageUnitDownloadCredential); assertNotNull(storageUnitDownloadCredential.getAwsCredential()); assertNotNull(storageUnitDownloadCredential.getAwsCredential().getAwsAccessKey()); assertNotNull(storageUnitDownloadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitDownloadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitDownloadCredential.getAwsCredential().getAwsSessionExpirationTime()); }
@Test public void getStorageUnitUploadCredentialAssertStorageNameTrim() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setNamespace(NAMESPACE); businessObjectDataKey.setBusinessObjectDefinitionName(BDEF_NAME); businessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); businessObjectDataKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE); businessObjectDataKey.setBusinessObjectFormatVersion(FORMAT_VERSION); businessObjectDataKey.setPartitionValue(PARTITION_VALUE); Boolean createNewVersion = true; String storageName = STORAGE_NAME; createBusinessObjectFormatEntity(businessObjectDataKey); // Create an S3 storage entity. List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), "testRole")); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket")); attributes.add( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE)); storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3, attributes); StorageUnitUploadCredential storageUnitUploadCredential = storageUnitService.getStorageUnitUploadCredential(businessObjectDataKey, createNewVersion, BLANK_TEXT + storageName + BLANK_TEXT); assertNotNull(storageUnitUploadCredential); assertNotNull(storageUnitUploadCredential.getAwsCredential()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsAccessKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionExpirationTime()); }
assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionExpirationTime()); assertEquals("test", storageUnitUploadCredential.getAwsKmsKeyId());
@Test public void getStorageUnitUploadCredentialWithCreateNewVersion() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setNamespace(NAMESPACE); businessObjectDataKey.setBusinessObjectDefinitionName(BDEF_NAME); businessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); businessObjectDataKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE); businessObjectDataKey.setBusinessObjectFormatVersion(FORMAT_VERSION); businessObjectDataKey.setPartitionValue(PARTITION_VALUE); Boolean createNewVersion = true; String storageName = STORAGE_NAME; createBusinessObjectFormatEntity(businessObjectDataKey); // Create an S3 storage entity. List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), "testRole")); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket")); attributes.add( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE)); storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3, attributes); StorageUnitUploadCredential storageUnitUploadCredential = storageUnitService.getStorageUnitUploadCredential(businessObjectDataKey, createNewVersion, storageName); assertNotNull(storageUnitUploadCredential); assertNotNull(storageUnitUploadCredential.getAwsCredential()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsAccessKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionExpirationTime()); }
@Test public void getStorageUnitUploadCredentialWithBdataVersion() { BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(); businessObjectDataKey.setNamespace(NAMESPACE); businessObjectDataKey.setBusinessObjectDefinitionName(BDEF_NAME); businessObjectDataKey.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE); businessObjectDataKey.setBusinessObjectFormatFileType(FORMAT_FILE_TYPE_CODE); businessObjectDataKey.setBusinessObjectFormatVersion(FORMAT_VERSION); businessObjectDataKey.setPartitionValue(PARTITION_VALUE); businessObjectDataKey.setBusinessObjectDataVersion(DATA_VERSION); Boolean createNewVersion = false; String storageName = STORAGE_NAME; createBusinessObjectFormatEntity(businessObjectDataKey); // Create an S3 storage entity. List<Attribute> attributes = new ArrayList<>(); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_UPLOAD_ROLE_ARN), "testRole")); attributes.add(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), "testBucket")); attributes.add( new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE)); storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3, attributes); StorageUnitUploadCredential storageUnitUploadCredential = storageUnitService.getStorageUnitUploadCredential(businessObjectDataKey, createNewVersion, storageName); assertNotNull(storageUnitUploadCredential); assertNotNull(storageUnitUploadCredential.getAwsCredential()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsAccessKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSecretKey()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionToken()); assertNotNull(storageUnitUploadCredential.getAwsCredential().getAwsSessionExpirationTime()); }
if (awsSessionExpirationTimeShouldBeCopiedAndSet == Boolean.TRUE) { XMLGregorianCalendar sourceAwsSessionExpirationTime; sourceAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar copyAwsSessionExpirationTime = ((XMLGregorianCalendar) strategy.copy(LocatorUtils.property(locator, "awsSessionExpirationTime", sourceAwsSessionExpirationTime), sourceAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null))); copy.setAwsSessionExpirationTime(copyAwsSessionExpirationTime);
if (awsSessionExpirationTimeShouldBeCopiedAndSet == Boolean.TRUE) { XMLGregorianCalendar sourceAwsSessionExpirationTime; sourceAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar copyAwsSessionExpirationTime = ((XMLGregorianCalendar) strategy.copy(LocatorUtils.property(locator, "awsSessionExpirationTime", sourceAwsSessionExpirationTime), sourceAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null))); copy.setAwsSessionExpirationTime(copyAwsSessionExpirationTime);
if (awsSessionExpirationTimeShouldBeCopiedAndSet == Boolean.TRUE) { XMLGregorianCalendar sourceAwsSessionExpirationTime; sourceAwsSessionExpirationTime = this.getAwsSessionExpirationTime(); XMLGregorianCalendar copyAwsSessionExpirationTime = ((XMLGregorianCalendar) strategy.copy(LocatorUtils.property(locator, "awsSessionExpirationTime", sourceAwsSessionExpirationTime), sourceAwsSessionExpirationTime, (this.awsSessionExpirationTime!= null))); copy.setAwsSessionExpirationTime(copyAwsSessionExpirationTime);