Search in sources :

Example 1 with AwsCredential

use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.

the class AutoRefreshCredentialProviderTest method testAssertCredentialCachingBehavior.

/**
 * The getAwsCredential method should return the cached credential if the session hasn't expired. If the session expired, a new credential should be
 * generated.
 *
 * @throws Exception
 */
@Test
public void testAssertCredentialCachingBehavior() throws Exception {
    AutoRefreshCredentialProvider autoRefreshCredentialProvider = new AutoRefreshCredentialProvider() {

        @Override
        public AwsCredential getNewAwsCredential() throws Exception {
            AwsCredential awsCredential = new AwsCredential();
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTimeInMillis(System.currentTimeMillis() + 1000);
            awsCredential.setAwsSessionExpirationTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
            return awsCredential;
        }
    };
    AwsCredential firstAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    AwsCredential secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    assertEquals(firstAwsCredential, secondAwsCredential);
    Thread.sleep(1000);
    secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
    assertNotEquals(firstAwsCredential, secondAwsCredential);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) AwsCredential(org.finra.herd.model.api.xml.AwsCredential) AbstractCoreTest(org.finra.herd.core.AbstractCoreTest) Test(org.junit.Test)

Example 2 with AwsCredential

use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.

the class MockHttpClientOperationsImpl method getStorageUnitDownloadCredentialResponse.

private void getStorageUnitDownloadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException {
    StorageUnitDownloadCredential storageUnitDownloadCredential = new StorageUnitDownloadCredential();
    AwsCredential awsCredential = new AwsCredential();
    awsCredential.setAwsAccessKey(uri.toString());
    storageUnitDownloadCredential.setAwsCredential(awsCredential);
    response.setEntity(getHttpEntity(storageUnitDownloadCredential));
}
Also used : StorageUnitDownloadCredential(org.finra.herd.model.api.xml.StorageUnitDownloadCredential) AwsCredential(org.finra.herd.model.api.xml.AwsCredential)

Example 3 with AwsCredential

use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.

the class UploaderWebClientTest method testGetBusinessObjectDataUploadCredential1.

@Test
public void testGetBusinessObjectDataUploadCredential1() throws Exception {
    DataBridgeBaseManifestDto manifest = new DataBridgeBaseManifestDto();
    manifest.setNamespace("test1");
    manifest.setBusinessObjectDefinitionName("test2");
    manifest.setBusinessObjectFormatUsage("test3");
    manifest.setBusinessObjectFormatFileType("test4");
    manifest.setBusinessObjectFormatVersion("test5");
    manifest.setPartitionValue("test6");
    manifest.setSubPartitionValues(Arrays.asList("test7", "test8"));
    String storageName = "test8";
    Integer businessObjectDataVersion = 1234;
    Boolean createNewVersion = false;
    uploaderWebClient.getRegServerAccessParamsDto().setUseSsl(false);
    BusinessObjectDataUploadCredential businessObjectDataUploadCredential = uploaderWebClient.getBusinessObjectDataUploadCredential(manifest, storageName, businessObjectDataVersion, createNewVersion);
    Assert.assertNotNull(businessObjectDataUploadCredential);
    AwsCredential awsCredential = businessObjectDataUploadCredential.getAwsCredential();
    Assert.assertNotNull(awsCredential);
    Assert.assertEquals("http://testWebServiceHostname:1234/herd-app/rest/businessObjectData/upload/credential/namespaces/test1" + "/businessObjectDefinitionNames/test2/businessObjectFormatUsages/test3/businessObjectFormatFileTypes/test4/businessObjectFormatVersions/test5" + "/partitionValues/test6?storageName=test8&subPartitionValues=test7%7Ctest8&businessObjectDataVersion=1234&createNewVersion=false", awsCredential.getAwsAccessKey());
}
Also used : BusinessObjectDataUploadCredential(org.finra.herd.model.api.xml.BusinessObjectDataUploadCredential) DataBridgeBaseManifestDto(org.finra.herd.model.dto.DataBridgeBaseManifestDto) AwsCredential(org.finra.herd.model.api.xml.AwsCredential) Test(org.junit.Test)

Example 4 with AwsCredential

use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.

the class S3DaoTest method testGetAWSCredentialsProviderAssertAdditionalProviderIsSet.

/**
 * A case where additional credentials provider is given in the request params. The credentials returned should be an AWS session credential where the
 * values are from the provided custom credentials provider.
 */
@Test
public void testGetAWSCredentialsProviderAssertAdditionalProviderIsSet() throws Exception {
    S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
    S3Operations mockS3Operations = mock(S3Operations.class);
    ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
    try {
        String s3BucketName = "s3BucketName";
        String s3KeyPrefix = "s3KeyPrefix";
        String awsAccessKey = "awsAccessKey";
        String awsSecretKey = "awsSecretKey";
        String awsSessionToken = "awsSessionToken";
        S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
        s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
        s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
        s3FileTransferRequestParamsDto.setAdditionalAwsCredentialsProviders(Arrays.asList(new HerdAWSCredentialsProvider() {

            @Override
            public AwsCredential getAwsCredential() {
                return new AwsCredential(awsAccessKey, awsSecretKey, awsSessionToken, null);
            }
        }));
        when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {

            @SuppressWarnings("unchecked")
            @Override
            public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
                AmazonS3Client amazonS3Client = invocation.getArgument(1);
                AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
                List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
                assertEquals(2, credentialsProviders.size());
                // refresh() does nothing, but gives code coverage
                credentialsProviders.get(0).refresh();
                /*
                     * We can't inspect the field directly since the class definition is private.
                     * Instead we call the getCredentials() and verify that it returns the credentials staged as part of this test.
                     */
                AWSCredentials credentials = awsCredentialsProviderChain.getCredentials();
                assertEquals(BasicSessionCredentials.class, credentials.getClass());
                BasicSessionCredentials basicSessionCredentials = (BasicSessionCredentials) credentials;
                assertEquals(awsAccessKey, basicSessionCredentials.getAWSAccessKeyId());
                assertEquals(awsSecretKey, basicSessionCredentials.getAWSSecretKey());
                assertEquals(awsSessionToken, basicSessionCredentials.getSessionToken());
                return new PutObjectResult();
            }
        });
        s3Dao.createDirectory(s3FileTransferRequestParamsDto);
    } finally {
        ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
    }
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) AWSCredentials(com.amazonaws.auth.AWSCredentials) DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSCredentialsProviderChain(com.amazonaws.auth.AWSCredentialsProviderChain) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) AwsCredential(org.finra.herd.model.api.xml.AwsCredential) HerdAWSCredentialsProvider(org.finra.herd.model.dto.HerdAWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 5 with AwsCredential

use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.

the class MockHttpClientOperationsImpl method getBusinessObjectDataUploadCredentialResponse.

private void getBusinessObjectDataUploadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException {
    BusinessObjectDataUploadCredential businessObjectDataUploadCredential = new BusinessObjectDataUploadCredential();
    AwsCredential awsCredential = new AwsCredential();
    awsCredential.setAwsAccessKey(uri.toString());
    businessObjectDataUploadCredential.setAwsCredential(awsCredential);
    response.setEntity(getHttpEntity(businessObjectDataUploadCredential));
}
Also used : BusinessObjectDataUploadCredential(org.finra.herd.model.api.xml.BusinessObjectDataUploadCredential) AwsCredential(org.finra.herd.model.api.xml.AwsCredential)

Aggregations

AwsCredential (org.finra.herd.model.api.xml.AwsCredential)15 Test (org.junit.Test)10 BusinessObjectDataUploadCredential (org.finra.herd.model.api.xml.BusinessObjectDataUploadCredential)5 StorageUnitDownloadCredential (org.finra.herd.model.api.xml.StorageUnitDownloadCredential)5 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)4 File (java.io.File)3 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)3 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)3 Storage (org.finra.herd.model.api.xml.Storage)3 DataBridgeBaseManifestDto (org.finra.herd.model.dto.DataBridgeBaseManifestDto)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JAXBException (javax.xml.bind.JAXBException)2 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)2 HerdAWSCredentialsProvider (org.finra.herd.model.dto.HerdAWSCredentialsProvider)2 ManifestFile (org.finra.herd.model.dto.ManifestFile)2