Skip to content Skip to sidebar Skip to footer

Cloudbackend.setcredential Not Setting Createdby/updatedby/owner Properties Of Cloudentity

I am using mobile backend starter and I am trying to update an entity when using the secured by id setting. I keep getting the error com.google.api.client.googleapis.json.GoogleJso

Solution 1:

I faced similar problem while playing with the mobile backend starter source.And even though I followed the answers provided in this link,I wasn't able to resolve the issue.However,what I did was to grab the mobile backend source code and make some modifications.Grab the code and in the CrudOperations.java file,you will see this method

privateMap<String, Entity> findAndUpdateExistingEntities(EntityListDto cdl, User user)
 throws UnauthorizedException{

// create a list of CEs with existing IdEntityListDto entitiesWithIds = newEntityListDto();
Map<String, EntityDto> entitiesWithIdMap = newHashMap<String, EntityDto>();
for (EntityDto cd : cdl.getEntries()) {
  if (cd.getId() != null) {
    entitiesWithIds.add(cd);
    entitiesWithIdMap.put(cd.getId(), cd);
  }
}

// try to get existing CEsMap<String, Entity> existingEntities = getAllEntitiesByKeyList(entitiesWithIds
    .readKeyList(user));

// update existing entitiesfor (String id : existingEntities.keySet()) {

  // check ACLEntity e = existingEntities.get(id);
  SecurityChecker.getInstance().checkAclForWrite(e, user);

  // update metadataEntityDto cd1 = entitiesWithIdMap.get(id);
  cd1.setUpdatedAt(newDate());
  if (user != null) {
    cd1.setUpdatedBy(user.getEmail());
  }

  // update the entity
  cd1.copyPropValuesToEntity(e);
}
return existingEntities;

}

From the above code,comment out SecurityChecker.getInstance().checkAclForWrite(e, user); and the throws UnAuthorizedException lines and redeploy your backend.Doing so will make all users of your app able to make updates to the concerned entity.This could be risky if you are strictly concerned about ownership.So,consider your security concerns before taking this approach.Haven done that,you can now freely update the concerned cloud entity.Remember to make as default your newly deployed backend on the server side.

Post a Comment for "Cloudbackend.setcredential Not Setting Createdby/updatedby/owner Properties Of Cloudentity"