org.jets3t.service.acl.Permission permission =
org.jets3t.service.acl.Permission.parsePermission(grant.getPermission().toString());
Grantee grantee = grant.getGrantee();
if (grantee instanceof Group) {
GroupGrantee jets3tGrantee = new GroupGrantee();
jets3tGrantee.setIdentifier(((Group)grantee).getURI());
acl.grantPermission(jets3tGrantee, permission);
} else if (grantee instanceof CanonicalUser) {
CanonicalUser canonicalUser = (CanonicalUser) grantee;
CanonicalGrantee jets3tGrantee = new CanonicalGrantee();
jets3tGrantee.setIdentifier(canonicalUser.getID());
jets3tGrantee.setDisplayName(canonicalUser.getDisplayName());
acl.grantPermission(jets3tGrantee, permission);
} else if (grantee instanceof AmazonCustomerByEmail) {
AmazonCustomerByEmail customerByEmail = (AmazonCustomerByEmail) grantee;
EmailAddressGrantee jets3tGrantee = new EmailAddressGrantee();
jets3tGrantee.setIdentifier(customerByEmail.getEmailAddress());
acl.grantPermission(jets3tGrantee, permission);
} else {
throw new S3ServiceException("Unrecognised grantee type: " + grantee.getClass());
}
}