Search in sources :

Example 1 with Permission

use of com.amazonaws.services.s3.model.Permission in project alluxio by Alluxio.

the class S3AUtils method translateBucketAcl.

/**
   * Translates S3 bucket ACL to Alluxio owner mode.
   *
   * @param acl the acl of S3 bucket
   * @param userId the S3 user id of the Alluxio owner
   * @return the translated posix mode in short format
   */
public static short translateBucketAcl(AccessControlList acl, String userId) {
    short mode = (short) 0;
    for (Grant grant : acl.getGrantsAsList()) {
        Permission perm = grant.getPermission();
        Grantee grantee = grant.getGrantee();
        if (perm.equals(Permission.Read)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is readable by the user, add r and x to the owner mode.
                mode |= (short) 0500;
            }
        } else if (perm.equals(Permission.Write)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the bucket is writable by the user, +w to the owner mode.
                mode |= (short) 0200;
            }
        } else if (perm.equals(Permission.FullControl)) {
            if (isUserIdInGrantee(grantee, userId)) {
                // If the user has full control to the bucket, +rwx to the owner mode.
                mode |= (short) 0700;
            }
        }
    }
    return mode;
}
Also used : Grant(com.amazonaws.services.s3.model.Grant) GroupGrantee(com.amazonaws.services.s3.model.GroupGrantee) Grantee(com.amazonaws.services.s3.model.Grantee) Permission(com.amazonaws.services.s3.model.Permission)

Example 2 with Permission

use of com.amazonaws.services.s3.model.Permission in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method setBucketAcl.

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 {
        // 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);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) EmailAddressGrantee(com.amazonaws.services.s3.model.EmailAddressGrantee) Permission(com.amazonaws.services.s3.model.Permission) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 3 with Permission

use of com.amazonaws.services.s3.model.Permission in project aws-doc-sdk-examples by awsdocs.

the class SetAcl method setObjectAcl.

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 {
        // 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);
    }
}
Also used : AccessControlList(com.amazonaws.services.s3.model.AccessControlList) AmazonS3(com.amazonaws.services.s3.AmazonS3) EmailAddressGrantee(com.amazonaws.services.s3.model.EmailAddressGrantee) Permission(com.amazonaws.services.s3.model.Permission) AmazonServiceException(com.amazonaws.AmazonServiceException)

Aggregations

Permission (com.amazonaws.services.s3.model.Permission)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)2 EmailAddressGrantee (com.amazonaws.services.s3.model.EmailAddressGrantee)2 Grant (com.amazonaws.services.s3.model.Grant)1 Grantee (com.amazonaws.services.s3.model.Grantee)1 GroupGrantee (com.amazonaws.services.s3.model.GroupGrantee)1