0

I'm using S#arp Architecture 1.6 and have implemented the Rhino Security integration as per

Rhino Security - S#arp Architecture

I'm using the latest build from Rhino.Commons

My Application_EndRequest method contains

ISession session = NHibernateSession.Current;

My ComponentRegister.cs contains

        container.Kernel.Register(

            Component.For<IAuthorizationService>()
                .ImplementedBy<AuthorizationService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IAuthorizationRepository>()
                .ImplementedBy<AuthorizationRepository>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IPermissionsBuilderService>()
                .ImplementedBy<PermissionsBuilderService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IPermissionsService>()
                .ImplementedBy<PermissionsService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IUnitOfWorkFactory>()
                .ImplementedBy<NHibernateUnitOfWorkFactory>()
                .LifeStyle.Is(LifestyleType.Singleton),
            Component.For<Rhino.Commons.IRepository<User>>()
                .ImplementedBy<NHRepository<User>>()
                .LifeStyle.Is(LifestyleType.Transient)
            );


        container.AddFacility<FactorySupportFacility>()
            .Register(Component.For<ISession>()
            .UsingFactoryMethod(() => NHibernateSession.Current)
            .LifeStyle.Is(LifestyleType.Transient)); 

I have also added RhinoSecurityPersistenceConfigurer() as per instructions.

The error I'm recieving on calling

UnitOfWork.Start() 

is

An association from the table Permissions refers to an unmapped class: Rhino.Security.IUser

Does anyone know what the cause of this error may be?

Has anyone successfully integrated Rhino.Security with S#arp Architecture?

Any help would be great.

Thanks

Rich

-- Additional Details --

Thanks for all the replies so far.

I've still not been able to resolve this, so thought I'd add more details.

In my Global.asax.cs I have

private void InitializeNHibernateSession()
{
  NHibernateSession.Init(
    webSessionStorage,
    new string[] { Server.MapPath("~/bin/SwitchSnapshot.Data.dll") },
    new AutoPersistenceModelGenerator().Generate(),
    Server.MapPath("~/NHibernate.config"),
    null, null, new RhinoSecurityPersistenceConfigurer());
 }

RhinoSecurityPersistenceConfigurer :

public Configuration ConfigureProperties(Configuration nhibernateConfig)
{
  Security.Configure<User>(nhibernateConfig, SecurityTableStructure.Prefix);
  return nhibernateConfig;
}

I have an AuthorizationAttribute which calls

using (UnitOfWork.Start())

The error is occuring in NHibernateUnitOfWorkFactory.cs as

sessionFactory = cfg.BuildSessionFactory();
RichG
  • 11
  • 6
  • You have to call `Security.Configure` after `ConfigureNHibernate` but before `BuildSessionFactory`. You'll have to make a small change to S#arpArch's `NHibernateSession` source file to do that. – David Perlman Oct 14 '10 at 07:21

3 Answers3

0

You need an NHibernate mapping for your User class (i.e. the class that implements the IUser interface). You also need a table in the database with the correct fields for your User class.

Dan
  • 802
  • 1
  • 9
  • 19
  • Thanks Dan, I have the user class mapped in user.hbm.xml and the user class implementing IUser, they are all correctly mapped to the database fields also. – RichG Oct 11 '10 at 22:28
  • Should not you have the IUser interface mapped? That was the error said. Just guessing never worked with Rhino but that error is normally that the class/interface is not mapped correctly – Homer1980ar Oct 14 '10 at 02:36
0

You have to let RS do some configuration work before the SessionFactory is created. Look at the second issue here http://groups.google.com/group/sharp-architecture/browse_frm/thread/4093c52596f54d23/194f19cd08c8fdd7?q=#194f19cd08c8fdd7. It should get you in the right direction.

David Perlman
  • 1,460
  • 1
  • 12
  • 32
0

Thanks to all who helped out.

In the end it was my own fault.

All I needed to do was to follow the S#arp Architecture Instructions a little better.

From an old version of S#arp I had 2 config files hibernate.cfg.xml and NHibernate.config. I thought I still needed both, but all I needed was hibernate.cfg.xml for S#arp version 1.6 and mapped User.cs using Fluent NHibernate.

Other changes I did was in ComponentRegister.cs

        container.Kernel.Register( 
            Component.For<IAuthorizationService>()
                .ImplementedBy<AuthorizationService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IAuthorizationRepository>()
                .ImplementedBy<AuthorizationRepository>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IPermissionsBuilderService>()
                .ImplementedBy<PermissionsBuilderService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IPermissionsService>()
                .ImplementedBy<PermissionsService>()
                .LifeStyle.Is(LifestyleType.Transient),
            Component.For<IUnitOfWorkFactory>()
                .ImplementedBy<NHibernateUnitOfWorkFactory>()
                .LifeStyle.Is(LifestyleType.Singleton),
            Component.For<Rhino.Commons.IRepository<User>>()
                .ImplementedBy<NHRepository<User>>()
                .LifeStyle.Is(LifestyleType.Transient)
        );

        container.Kernel.AddFacility<FactorySupportFacility>()
            .Register(Component.For<ISession>()
            .UsingFactoryMethod(() => NHibernateSession.Current)
            .LifeStyle.Is(LifestyleType.Transient)
        ); 

Then use the following in my code.

        var authorizationService = IoC.Resolve<IAuthorizationService>();

        using (UnitOfWork.Start())
        {
        }
RichG
  • 11
  • 6
  • In what nsamespace I can find the class IoC you have used in IoC.Resolve<>() – K.A.D. Jan 06 '11 at 23:12
  • Hi, the link http://wiki.sharparchitecture.net/RhinoSecurity.ashx you provided above no longer points to Rhino.Security instructions. Do you know another source for these instructions? Thanks – Forer Aug 24 '11 at 09:55