I am afraid, Rhino Security depends on Nhibernate to work.
I have been evaluating Rhino Security for a couple of months and, at the end, I've decided to use it cause it's a really really good product.
You can find good an useful informations on Ayende's blog or here.
I have straggled a bit to integrate it with StructureMap (instead of Castle Windsor). You can find some info here.
To do what you're trying to achieve you have to define a class which implements the IEntityInformationExtractor interface.
First of all you have to add the following references (I've recompiled Rhino Security with NH 3.0) to:
- Microsoft.Practices.ServiceLocation
- NHibernate
- NHibernate.ByteCode.Castle
- StructureMap
- Rhino.Security
- StructureMapAdapter
Then you define a bootstrapper:
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 a a NH session factory.
I've create a class (TaskInfromationExtractor) which implements IEntityInformationExtractor. This will allow you to define permissions for the task entity.
Now your app is ready. You just have to "bootstrap" structuremap:
- Bootstrapper.Initialize();
You would do this when your app starts up.
Now you can use Rhino security repository and services to create users, groups, relations etc etc. as the links I've give you suggest.
You can find a sample I've prepared here