Rhino Security and POCO class

240 views Asked by At

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 ?

1

There are 1 answers

0
LeftyX On

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.