Example usage for com.amazonaws.services.securitytoken.model Credentials getSessionToken

List of usage examples for com.amazonaws.services.securitytoken.model Credentials getSessionToken

Introduction

In this page you can find the example usage for com.amazonaws.services.securitytoken.model Credentials getSessionToken.

Prototype


public String getSessionToken() 

Source Link

Document

The token that users must pass to the service API to use the temporary credentials.

Usage

From source file:org.finra.herd.service.impl.UploadDownloadServiceImpl.java

License:Apache License

@NamespacePermission(fields = "#downloadBusinessObjectDataStorageFileSingleInitiationRequest.businessObjectDataStorageFileKey.namespace", permissions = NamespacePermissionEnum.READ)
@Override// www  . j  a  v a  2 s  . c o  m
public DownloadBusinessObjectDataStorageFileSingleInitiationResponse initiateDownloadSingleBusinessObjectDataStorageFile(
        DownloadBusinessObjectDataStorageFileSingleInitiationRequest downloadBusinessObjectDataStorageFileSingleInitiationRequest) {
    // Validate and trim the request.
    uploadDownloadHelper.validateAndTrimDownloadBusinessObjectDataStorageFileSingleInitiationRequest(
            downloadBusinessObjectDataStorageFileSingleInitiationRequest);

    // Get the business object data storage file key.
    BusinessObjectDataStorageFileKey businessObjectDataStorageFileKey = downloadBusinessObjectDataStorageFileSingleInitiationRequest
            .getBusinessObjectDataStorageFileKey();

    // Retrieve and validate that the business object data exists.
    BusinessObjectDataKey businessObjectDataKey = getBusinessObjectDataKeyFromBusinessObjectDataStorageFileKey(
            businessObjectDataStorageFileKey);
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper
            .getBusinessObjectDataEntity(businessObjectDataKey);

    // Retrieve and validate that the storage unit exists
    StorageUnitEntity storageUnitEntity = storageUnitDaoHelper
            .getStorageUnitEntity(businessObjectDataStorageFileKey.getStorageName(), businessObjectDataEntity);

    // Get the storage file entity and ensure it exists.
    StorageFileEntity storageFileEntity = storageFileDaoHelper.getStorageFileEntity(storageUnitEntity,
            businessObjectDataStorageFileKey.getFilePath(), businessObjectDataKey);

    // Get S3 bucket access parameters.
    StorageEntity storageEntity = storageFileEntity.getStorageUnit().getStorage();

    // Retrieve the storage related information.
    String s3BucketName = storageHelper.getStorageBucketName(storageEntity);
    String s3ObjectKey = businessObjectDataStorageFileKey.getFilePath();

    // Create an AWS policy builder.
    AwsPolicyBuilder awsPolicyBuilder = new AwsPolicyBuilder().withS3(s3BucketName, s3ObjectKey,
            S3Actions.GetObject);

    // Get the storage kms key id.
    String storageKmsKeyId = storageHelper.getStorageAttributeValueByName(
            configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KMS_KEY_ID), storageEntity,
            false, true);

    /*
     * Only add KMS policies if the storage specifies a KMS ID
     */
    if (storageKmsKeyId != null) {
        awsPolicyBuilder.withKms(storageKmsKeyId.trim(), KmsActions.DECRYPT);
    }

    // Create a sessionId.
    String sessionId = UUID.randomUUID().toString();

    // Get the temporary credentials.
    Credentials downloaderCredentials = getDownloaderCredentials(storageEntity, sessionId, awsPolicyBuilder);

    // Generate a pre-signed URL.
    Date expiration = downloaderCredentials.getExpiration();
    S3FileTransferRequestParamsDto s3BucketAccessParams = storageHelper.getS3BucketAccessParams(storageEntity);
    String preSignedUrl = s3Dao.generateGetObjectPresignedUrl(s3BucketName, s3ObjectKey, expiration,
            s3BucketAccessParams);

    // Convert the business object format entity to the business object format model object
    BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper
            .createBusinessObjectFormatFromEntity(businessObjectDataEntity.getBusinessObjectFormat());

    // Create a business object data storage file key for the download business object data storage file single initiation response.
    BusinessObjectDataStorageFileKey businessObjectDataStorageFileKeyForResponse = new BusinessObjectDataStorageFileKey(
            businessObjectFormat.getNamespace(), businessObjectFormat.getBusinessObjectDefinitionName(),
            businessObjectFormat.getBusinessObjectFormatUsage(),
            businessObjectFormat.getBusinessObjectFormatFileType(),
            businessObjectFormat.getBusinessObjectFormatVersion(), businessObjectDataEntity.getPartitionValue(),
            businessObjectDataHelper.getSubPartitionValues(businessObjectDataEntity),
            businessObjectDataEntity.getVersion(), storageUnitEntity.getStorageName(),
            storageFileEntity.getPath());

    // Create the download business object data storage file single initiation response.
    DownloadBusinessObjectDataStorageFileSingleInitiationResponse downloadBusinessObjectDataStorageFileSingleInitiationResponse = new DownloadBusinessObjectDataStorageFileSingleInitiationResponse();
    downloadBusinessObjectDataStorageFileSingleInitiationResponse
            .setBusinessObjectDataStorageFileKey(businessObjectDataStorageFileKeyForResponse);
    downloadBusinessObjectDataStorageFileSingleInitiationResponse.setAwsS3BucketName(s3BucketName);
    downloadBusinessObjectDataStorageFileSingleInitiationResponse
            .setAwsAccessKey(downloaderCredentials.getAccessKeyId());
    downloadBusinessObjectDataStorageFileSingleInitiationResponse
            .setAwsSecretKey(downloaderCredentials.getSecretAccessKey());
    downloadBusinessObjectDataStorageFileSingleInitiationResponse
            .setAwsSessionToken(downloaderCredentials.getSessionToken());
    downloadBusinessObjectDataStorageFileSingleInitiationResponse
            .setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(expiration));
    downloadBusinessObjectDataStorageFileSingleInitiationResponse.setPreSignedUrl(preSignedUrl);

    // Return the download business object data storage file single initiation response.
    return downloadBusinessObjectDataStorageFileSingleInitiationResponse;
}