Grant[] grants = acl.getGrant();
if (grants != null)
{
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);
} else if(permissionValue.equalsIgnoreCase("WRITE")) {
engineGrant.setPermission(SAcl.PERMISSION_WRITE);
} else if(permissionValue.equalsIgnoreCase("READ_ACP")) {
engineGrant.setPermission(SAcl.PERMISSION_READ_ACL);
} else if(permissionValue.equalsIgnoreCase("WRITE_ACP")) {
engineGrant.setPermission(SAcl.PERMISSION_WRITE_ACL);
} else if(permissionValue.equalsIgnoreCase("FULL_CONTROL")) {
engineGrant.setPermission(SAcl.PERMISSION_FULL);
} else {
throw new UnsupportedOperationException("Unsupported permission: " + permissionValue);
}
engineAcl.addGrant(engineGrant);
}