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

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

Introduction

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

Prototype

public void setOwner(Owner owner) 

Source Link

Document

Sets the owner of the AccessControlList .

Usage

From source file:com.emc.ecs.sync.util.AwsS3Util.java

License:Open Source License

public static AccessControlList s3AclFromSyncAcl(SyncAcl syncAcl, boolean ignoreInvalid) {
    AccessControlList s3Acl = new AccessControlList();

    s3Acl.setOwner(new Owner(syncAcl.getOwner(), syncAcl.getOwner()));

    for (String user : syncAcl.getUserGrants().keySet()) {
        Grantee grantee = new CanonicalGrantee(user);
        for (String permission : syncAcl.getUserGrants().get(user)) {
            Permission perm = getS3Permission(permission, ignoreInvalid);
            if (perm != null)
                s3Acl.grantPermission(grantee, perm);
        }/*  w  ww . ja  v a  2  s . c om*/
    }

    for (String group : syncAcl.getGroupGrants().keySet()) {
        Grantee grantee = GroupGrantee.parseGroupGrantee(group);
        if (grantee == null) {
            if (ignoreInvalid)
                log.warn("{} is not a valid S3 group", group);
            else
                throw new RuntimeException(group + " is not a valid S3 group");
        }
        for (String permission : syncAcl.getGroupGrants().get(group)) {
            Permission perm = getS3Permission(permission, ignoreInvalid);
            if (perm != null)
                s3Acl.grantPermission(grantee, perm);
        }
    }

    return s3Acl;
}

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);/*from  w ww. ja va  2s  .c  o  m*/
        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:com.upplication.s3fs.util.AmazonS3ClientMock.java

License:Open Source License

private AccessControlList createAllPermission() {
    AccessControlList res = new AccessControlList();
    res.setOwner(getS3AccountOwner());
    Grantee grant = new Grantee() {

        @Override/*from ww w  . ja v  a  2  s  .c  o m*/
        public void setIdentifier(String id) {
        }

        @Override
        public String getTypeIdentifier() {
            return getS3AccountOwner().getId();
        }

        @Override
        public String getIdentifier() {
            return getS3AccountOwner().getId();
        }
    };

    res.grantPermission(grant, Permission.FullControl);
    res.grantPermission(grant, Permission.Read);
    res.grantPermission(grant, Permission.Write);
    return res;
}

From source file:org.apache.nifi.processors.aws.s3.AbstractS3Processor.java

License:Apache License

/**
 * Create AccessControlList if appropriate properties are configured.
 *
 * @param context ProcessContext//from  ww  w .j  ava  2  s  . co  m
 * @param flowFile FlowFile
 * @return AccessControlList or null if no ACL properties were specified
 */
protected final AccessControlList createACL(final ProcessContext context, final FlowFile flowFile) {
    // lazy-initialize ACL, as it should not be used if no properties were specified
    AccessControlList acl = null;

    final String ownerId = context.getProperty(OWNER).evaluateAttributeExpressions(flowFile).getValue();
    if (!StringUtils.isEmpty(ownerId)) {
        final Owner owner = new Owner();
        owner.setId(ownerId);
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.setOwner(owner);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(FULL_CONTROL_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.FullControl);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(READ_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.Read);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(WRITE_USER_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.Write);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(READ_ACL_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.ReadAcp);
    }

    for (final Grantee grantee : createGrantees(
            context.getProperty(WRITE_ACL_LIST).evaluateAttributeExpressions(flowFile).getValue())) {
        if (acl == null) {
            acl = new AccessControlList();
        }
        acl.grantPermission(grantee, Permission.WriteAcp);
    }

    return acl;
}

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   ww w.ja  v  a  2s. co 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");
}