开发者

Rhino Security and POCO class

it seems if I want to use Rhino Security on an entity , that entity need to have a SecurityKey field of Guid type. I saw an example where the constructor of the entity's class has a statement that assign the SecurityKey

public class Document
{
  public Document() { SecurityKey = Guid.NewGuid(); } 
  public virtual int Id {get; set;}开发者_运维技巧
  public virtual string Name { get; set;}
  public virtual Guid SecurityKey { get; set;}
}
public class DocumentInformationExtractor : IEntityInformationExtractor
{ .... }

The constructor assgined a new Guid SecurityKey everytimes. I don't understand why this works. Should it not assgined a new Guid only for new entity that has not been persisted ?


That's right. You have to do that otherwise the Guid saved would be {00000000-0000-0000-0000-000000000000}, but you need a proper, non-empty guid. This field will be used when you call:

permissionsBuilderService
    .Allow("/Document/Edit")
    .For(user1)
    .On(MyDocument)
    .Level(20)
    .Save();

This is just used so you do not save an empty SecurityKey Guid, cause you might use in the future (you do not need to assign permissions if you don't need them). Rhino-Security will look after the load of the graph and populate SecurityKey with the one saved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜