I'm afraid Rhino Security depends on Nhibernate to work.
I have been evaluating Rhino Security for several months, and in the end I decided to use it because it is a really really good product.
You can find useful information about the Ayende blog or here . I stumbled a bit to integrate it with StructureMap (instead of Castle Windsor). Here you can find information.
To do what you are trying to achieve, you need to define a class that implements the IEntityInformationExtractor interface.
First of all, you should add the following links (I recompiled Rhino Security with NH 3.0):
- Microsoft.Practices.ServiceLocation
- NHibernate
- NHibernate.ByteCode.Castle
- Structuremap
- Rhino.Security
- StructureMapAdapter
Then you define the bootloader:
public static class Bootstrapper { public static void Initialize() { ObjectFactory.Initialize(cfg => { cfg.UseDefaultStructureMapConfigFile = false; cfg.IgnoreStructureMapConfig = true; cfg.AddRegistry<StructureMapRegistry>(); }); ServiceLocator.SetLocatorProvider(() => new StructureMapServiceLocator(ObjectFactory.Container)); } }
Then you define the StructureMap registry class:
public class StructureMapRegistry : Registry { public StructureMapRegistry() { string ConnDb = "Data Source=(local); Initial Catalog=RhinoSecurity_Test; Trusted_Connection=true;"; For<ISessionFactory>() .Singleton() .TheDefault.Is.ConstructedBy(() => new NHSessionFactory(ConnDb, false).SessionFactory); For<ISession>() .Singleton() .TheDefault.Is.ConstructedBy(x => x.GetInstance<ISessionFactory>().OpenSession()); For<IAuthorizationRepository>() .Use<AuthorizationRepository>(); For<IPermissionsService>() .Use<PermissionsService>(); For<IAuthorizationService>() .Use<AuthorizationService>(); For<IPermissionsBuilderService>() .Use<PermissionsBuilderService>(); For<IEntityInformationExtractor<Model.Task>>() .Use(p => { return (new TaskInfromationExtractor(p.GetInstance<ISession>())); }); } }
NHSessionFactory basically create an NH factory session.
I created a class ( TaskInfromationExtractor ) that implements IEntityInformationExtractor. This will allow you to define permissions for the task object. Now your application is ready. You just need to create a "bootstrap" structure structure:
- Bootstrapper.Initialize ();
You will do this when your application starts. Now you can use the Rhino repository and security services to create users, groups, relationships, etc. As the links that I offer you. You can find the sample that I prepared here.
source share