获取对象访问权限

您可以使用 getObjectAcl 接口获取对象访问的权限。以下代码展示如何获取对象的访问权限:

String bucketName = "<your-bucket-name>";
String objectKey = "<your-object-key>";
try {
    AccessControlList acl = s3.getObjectAcl(bucketName, objectKey);
    List<Grant> grants = acl.getGrantsAsList();
    for (Grant grant : grants) {
        System.out.format( " %s: %s\n", grant.getGrantee().getIdentifier(), grant.getPermission().toString());
    }
} catch (AmazonServiceException e) {
    System.err.println(e.getErrorMessage());
}