Example usage for com.amazonaws.services.s3.model AccessControlList grantAllPermissions

List of usage examples for com.amazonaws.services.s3.model AccessControlList grantAllPermissions

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model AccessControlList grantAllPermissions.

Prototype

public void grantAllPermissions(Grant... grantsVarArg) 

Source Link

Document

Adds a set of grantee/permission pairs to the access control list (ACL), where each item in the set is a Grant object.

Usage

From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java

License:Open Source License

private PutObjectResult putObject(AmazonS3 client, String bucketName, String key, File file, Grantee grantee,
        Permission permission, Grant... grantsVarArg) {
    if (client == null) {
        return null;
    } else if (StringUtil.isEmpty(bucketName)) {
        return null;
    } else if (StringUtil.isEmpty(key)) {
        return null;
    } else if (file == null) {
        return null;
    } else if ((grantee == null || permission == null) && (grantsVarArg == null || grantsVarArg.length < 1)) {
        return null;
    }/* w  ww. java 2  s.c  om*/
    PutObjectResult result = null;
    AccessControlList accessControlList = new AccessControlList();
    if (grantee != null && permission != null) {
        accessControlList.grantPermission(grantee, permission);
    }
    if (grantsVarArg != null && grantsVarArg.length > 0) {
        accessControlList.grantAllPermissions(grantsVarArg);
    }
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file)
            .withAccessControlList(accessControlList);
    result = client.putObject(putObjectRequest);
    return result;
}

From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java

License:Open Source License

private PutObjectResult putObject(AmazonS3 client, String bucketName, String key, InputStream input,
        ObjectMetadata metadata, Grantee grantee, Permission permission, Grant... grantsVarArg) {
    if (client == null) {
        return null;
    } else if (StringUtil.isEmpty(bucketName)) {
        return null;
    } else if (StringUtil.isEmpty(key)) {
        return null;
    } else if (input == null) {
        return null;
    } else if (metadata == null) {
        return null;
    } else if ((grantee == null || permission == null) && (grantsVarArg == null || grantsVarArg.length < 1)) {
        return null;
    }//from  w  w w .  j a  va  2  s.  c o m
    PutObjectResult result = null;
    AccessControlList accessControlList = new AccessControlList();
    if (grantee != null && permission != null) {
        accessControlList.grantPermission(grantee, permission);
    }
    if (grantsVarArg != null && grantsVarArg.length > 0) {
        accessControlList.grantAllPermissions(grantsVarArg);
    }
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, input, metadata)
            .withAccessControlList(accessControlList);
    result = client.putObject(putObjectRequest);
    return result;
}

From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java

License:Open Source License

@Override
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName,
        String destinationKey) throws AmazonClientException {

    S3Element element = find(sourceBucketName, sourceKey);

    if (element != null) {

        S3Object objectSource = element.getS3Object();
        // copy object with
        S3Object resObj = new S3Object();
        resObj.setBucketName(destinationBucketName);
        resObj.setKey(destinationKey);/* w ww.ja v a  2  s  .  c om*/
        resObj.setObjectContent(objectSource.getObjectContent());
        resObj.setObjectMetadata(objectSource.getObjectMetadata());
        resObj.setRedirectLocation(objectSource.getRedirectLocation());
        // copy permission
        AccessControlList permission = new AccessControlList();
        permission.setOwner(element.getPermission().getOwner());
        permission.grantAllPermissions(element.getPermission().getGrants().toArray(new Grant[0]));
        S3Element elementResult = new S3Element(resObj, permission, sourceKey.endsWith("/"));
        // TODO: add should replace existing
        objects.get(find(destinationBucketName)).remove(elementResult);
        objects.get(find(destinationBucketName)).add(elementResult);

        return new CopyObjectResult();
    }

    throw new AmazonServiceException("object source not found");
}

From source file:io.druid.storage.s3.S3Utils.java

License:Apache License

static AccessControlList grantFullControlToBucketOwner(AmazonS3 s3Client, String bucket) {
    final AccessControlList acl = s3Client.getBucketAcl(bucket);
    acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl));
    return acl;//  w  w w  . j  a v  a2 s .  co m
}

From source file:org.apache.druid.storage.s3.S3Utils.java

License:Apache License

static AccessControlList grantFullControlToBucketOwner(ServerSideEncryptingAmazonS3 s3Client, String bucket) {
    final AccessControlList acl = s3Client.getBucketAcl(bucket);
    acl.grantAllPermissions(new Grant(new CanonicalGrantee(acl.getOwner().getId()), Permission.FullControl));
    return acl;/*  w  w w. j a  v  a 2 s  .  c  o m*/
}

From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java

License:Apache License

@Override
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName,
        String destinationKey) throws AmazonClientException, AmazonServiceException {

    S3Element element = find(sourceBucketName, sourceKey);

    if (element != null) {

        S3Object objectSource = element.getS3Object();
        // copy object with
        S3Object resObj = new S3Object();
        resObj.setBucketName(destinationBucketName);
        resObj.setKey(destinationKey);//from w  ww  .  ja  va2  s  . c  o m
        resObj.setObjectContent(objectSource.getObjectContent());
        resObj.setObjectMetadata(objectSource.getObjectMetadata());
        resObj.setRedirectLocation(objectSource.getRedirectLocation());
        // copy perission
        AccessControlList permission = new AccessControlList();
        permission.setOwner(element.getPermission().getOwner());
        permission.grantAllPermissions(element.getPermission().getGrants().toArray(new Grant[0]));
        // maybe not exists key TODO
        objects.get(find(destinationBucketName))
                .add(new S3Element(resObj, permission, sourceKey.endsWith("/")));

        return new CopyObjectResult();
    }

    throw new AmazonServiceException("object source not found");
}