{
for (Grant grant: grants)
{
S3Grant engineGrant = new S3Grant();
Grantee grantee = grant.getGrantee();
if (grantee instanceof CanonicalUser)
{
engineGrant.setGrantee(SAcl.GRANTEE_USER);
engineGrant.setCanonicalUserID(((CanonicalUser)grantee).getID());
}
else if (grantee instanceof Group)
{
Group temp = (Group)grantee;
String uri = temp.getURI();
if ( uri.equalsIgnoreCase( "http://acs.amazonaws.com/groups/global/AllUsers" )) {
// -> this allows all public unauthenticated access based on permission given
engineGrant.setGrantee(SAcl.GRANTEE_ALLUSERS);
engineGrant.setCanonicalUserID( "*" );
}
else if (uri.equalsIgnoreCase( "http://acs.amazonaws.com/groups/global/Authenticated" )) {
// -> this allows any authenticated user access based on permission given
engineGrant.setGrantee(SAcl.GRANTEE_AUTHENTICATED);
engineGrant.setCanonicalUserID( "A" );
}
else throw new UnsupportedOperationException("Unsupported grantee group URI: " + uri );
}
else throw new UnsupportedOperationException("Unsupported grantee type: " + grantee.getClass().getCanonicalName());
Permission permission = grant.getPermission();
String permissionValue = permission.getValue();
if(permissionValue.equalsIgnoreCase("READ")) {
engineGrant.setPermission(SAcl.PERMISSION_READ);