Example usage for com.amazonaws.services.s3.model EmailAddressGrantee EmailAddressGrantee

List of usage examples for com.amazonaws.services.s3.model EmailAddressGrantee EmailAddressGrantee

Introduction

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

Prototype

public EmailAddressGrantee(String emailAddress) 

Source Link

Document

Constructs a new EmailAddressGrantee object with the given email address.

Usage

From source file:aws.example.s3.SetAcl.java

License:Open Source License

public static void setBucketAcl(String bucket_name, String email, String access) {
    System.out.format("Setting %s access for %s\n", access, email);
    System.out.println("on bucket: " + bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {//  w ww.j  av  a  2  s  .  c  om
        // get the current ACL
        AccessControlList acl = s3.getBucketAcl(bucket_name);
        // set access for the grantee
        EmailAddressGrantee grantee = new EmailAddressGrantee(email);
        Permission permission = Permission.valueOf(access);
        acl.grantPermission(grantee, permission);
        s3.setBucketAcl(bucket_name, acl);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}

From source file:aws.example.s3.SetAcl.java

License:Open Source License

public static void setObjectAcl(String bucket_name, String object_key, String email, String access) {
    System.out.format("Setting %s access for %s\n", access, email);
    System.out.println("for object: " + object_key);
    System.out.println(" in bucket: " + bucket_name);

    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    try {/*from  w  w w. j  a  v a  2 s .co  m*/
        // get the current ACL
        AccessControlList acl = s3.getObjectAcl(bucket_name, object_key);
        // set access for the grantee
        EmailAddressGrantee grantee = new EmailAddressGrantee(email);
        Permission permission = Permission.valueOf(access);
        acl.grantPermission(grantee, permission);
        s3.setObjectAcl(bucket_name, object_key, acl);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}

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

License:Apache License

protected Grantee createGrantee(final String value) {
    if (StringUtils.isEmpty(value)) {
        return null;
    }/*from  w  w w. ja  v  a  2 s. co m*/

    if (value.contains("@")) {
        return new EmailAddressGrantee(value);
    } else {
        return new CanonicalGrantee(value);
    }
}

From source file:org.springframework.integration.aws.s3.core.AmazonS3OperationsImpl.java

License:Apache License

/**
 * Gets the {@link AccessControlList} from the given {@link AmazonS3ObjectACL} 
 * @param acl//  w w  w .  ja v a 2s  .c  o m
 * @return 
 */
private AccessControlList getAccessControlList(String bucketName, String key, AmazonS3ObjectACL acl) {
    AccessControlList accessControlList = null;
    if (acl != null) {
        if (!acl.getGrants().isEmpty()) {
            accessControlList = client.getObjectAcl(bucketName, key);
            for (ObjectGrant objGrant : acl.getGrants()) {
                Grantee grantee = objGrant.getGrantee();
                com.amazonaws.services.s3.model.Grantee awsGrantee;
                if (grantee.getGranteeType() == GranteeType.CANONICAL_GRANTEE_TYPE) {
                    awsGrantee = new CanonicalGrantee(grantee.getIdentifier());
                } else if (grantee.getGranteeType() == GranteeType.EMAIL_GRANTEE_TYPE) {
                    awsGrantee = new EmailAddressGrantee(grantee.getIdentifier());
                } else {
                    awsGrantee = GroupGrantee.parseGroupGrantee(grantee.getIdentifier());
                    if (awsGrantee == null) {
                        logger.warn("Group grantee with identifier: \"" + grantee.getIdentifier()
                                + "\" not found. skipping this grant");
                        continue;
                    }
                }
                ObjectPermissions perm = objGrant.getPermission();
                Permission permission;
                if (perm == ObjectPermissions.READ) {
                    permission = Permission.Read;
                } else if (perm == ObjectPermissions.READ_ACP) {
                    permission = Permission.ReadAcp;
                } else
                    permission = Permission.WriteAcp;

                accessControlList.grantPermission(awsGrantee, permission);
            }
        }
    }
    return accessControlList;
}