how to secure add or delete entities with breezejs

扶醉桌前 提交于 2019-12-13 02:59:25

问题


how can I secure SaveChanges after I added or deleted an entity to breezejs?

  var newTodo = todoType.createEntity(initialValues);
  manager.addEntity(newTodo);

I want only to add/delete entities to a logged in user. Other users shouldn't be able to add an entity to another user via javascript hack.

Querying only allowed entites is possible via editing EFContextProvider on the server. But how does it work with delete or add?


回答1:


You can Prevent save Change on server side using

overriding BeforeSaveEntitiesDelegate method of contexProvider.

E.g

_contextProvider.BeforeSaveEntitiesDelegate = BeforeSaveEntities;

private Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> arg)
        {
            var resultToReturn = new Dictionary<Type, List<EntityInfo>>();
            foreach (var type in arg.Keys)
            {
                var entityName = type.FullName;
                var list = arg[type];
                if (entityName == "xyz" && list[0].EntityState!="Added")
                {
                    resultToReturn.Add(type, list);
                }
            }
            return arg;
        }

This will not save new added entity name "xyz".



来源:https://stackoverflow.com/questions/31621718/how-to-secure-add-or-delete-entities-with-breezejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!