if(!conn.doesBucketExist(cid)){
conn.createBucket(cid, region);
v = true;
}
AccessControlList acl = conn.getBucketAcl(cid);
if(permission.equals("rw")){
acl.grantPermission(new CanonicalGrantee(canonicalId), Permission.FullControl);
f = true;
}else if(permission.equals("r")){
acl.grantPermission(new CanonicalGrantee(canonicalId), Permission.Read);
f = true;
}else if(permission.equals("w")){
acl.grantPermission(new CanonicalGrantee(canonicalId), Permission.Write);
}
if(!v && f){
ObjectListing objectListing = conn.listObjects(cid);
AccessControlList aclKeys = null;
for(S3ObjectSummary elem: objectListing.getObjectSummaries()) {
aclKeys = conn.getObjectAcl(cid, elem.getKey());
aclKeys.grantPermission(new CanonicalGrantee(canonicalId), Permission.Read);
aclKeys.grantPermission(new CanonicalGrantee(canonicalId), Permission.ReadAcp);
conn.setObjectAcl(cid, elem.getKey(), aclKeys);
}
}
conn.setBucketAcl(cid, acl);