I've spent these last two days trying to dig into this issue. My
knowledge of nhibernate is not that huge so it took me
a while to figure out things.
It seems to me that the problem is the fact that UserGroups contains
this collection of Users (the collection is cachable)
but it is not responsible for it. There's no inverse attribute set.
After some debugging (and reading some papers found on the Internet)
I've found out that the only way to fix this is to
evict all the queries in the cache just after the user has been
removed from the group.
I would change this code here:
public void DetachUserFromGroup(IUser user, string usersGroupName)
{
UsersGroup group = GetUsersGroupByName(usersGroupName);
Guard.Against(group == null, "There is no users group named: " +
usersGroupName);
group.Users.Remove(user);
session.SessionFactory.EvictQueries();
}
and, probably, the same associating the user to a group.
I've tried different kind of eviction (on collections and entities)
but nothing really changes.
The only way is to evict all the query in the cache.
On Mar 26, 12:38 am, Nathan Stott <[email protected]> wrote:
> I'm home. My use of rhino security is in projects that are in the
> maintenance phase, not the new development phase. I will be happy to
> apply any patches you create; however, if you're waiting on me to dig
> into an issue that doesn't directly involve maintaining one of my
> existing sites using rhino security, you're going to be waiting for
> quite a while.
>
> Good luck and if you dig into the issue and resolve it, I'll be happy
> to apply your commit.
>
>
>
>
>
>
>
> On Fri, Mar 25, 2011 at 5:37 PM, RickB <[email protected]> wrote:
> > Hello? Is anyone home?
>
> > On Mar 11, 5:23 pm, RickB <[email protected]> wrote:
> >> It looks like group.Users.Remove(user) (Services
> >> \AuthorizationRepository.cs line 525) is not actually removing the
> >> user from the group. I don't know enough about how the system works
> >> under the hood to come up with a fix.
>
> >> Do you think you could please dig into it a bit? I bet it's an easy
> >> fix for someone who is familiar with how it works.
>
> >> Thank you!
>
> >> Rick
>
> >> On Mar 10, 8:09 am, Nathan Stott <[email protected]> wrote:
>
> >> > It has yet to be fixed. If you'd like to submit a patch and a pull
> >> > request I will happily merge it.
>
> >> > On Mon, Mar 7, 2011 at 5:44 PM, RickB <[email protected]> wrote:
> >> > > Does anyone know if this issue has been fixed?
>
> >> > > Thank you,
>
> >> > > Rick
>
> >> > > On Feb 25, 12:14 am, vandalo <[email protected]> wrote:
> >> > >> Thanks David,
>
> >> > >> Alberto
>
> >> > >> On Feb 23, 11:58 pm, David Archer <[email protected]> wrote:
>
> >> > >> > It's a known issue -- Google it and you'll see others are having the
> >> > >> > same problem. I'm not experienced enough with NH to know what the
> >> > >> > root
> >> > >> > cause is here. :(
>
> >> > >> > I have however just submitted a pull request on Github to Ayende
> >> > >> > with
> >> > >> > a failing unit test illustrating the problem.
>
> >> > >> >https://github.com/ayende/rhino-security/pull/8
>
> >> > >> > -- David Archer
>
> >> > >> > On Feb 15, 11:14 am, vandalo <[email protected]> wrote:
>
> >> > >> > > I am pretty sure that this question has been asked many times but
> >> > >> > > I
> >> > >> > > haven't been able to find an answer yet.
> >> > >> > > DetachUserFromGroup and/or AssociateUserWith members of
> >> > >> > > AuthorizationRepository don't seem to invalidate the second-level
> >> > >> > > cache.
> >> > >> > > I've tried to investigate more but my knowledge of Nhibernate is
> >> > >> > > too
> >> > >> > > poor at the moment to find a proper solution.
> >> > >> > > I've downloaded Rhino-Security from
> >> > >> > > here:https://github.com/ayende/rhino-security
> >> > >> > > and extended AuthorizationServiceWithSecondLevelCacheFixture.
>
> >> > >> > > The DatabaseFixture basically creates a user, 3 groups and
> >> > >> > > associate
> >> > >> > > the user with all the groups:
>
> >> > >> > > user = new User { Name = "Ayende" };
>
> >> > >> > > session.Save(user);
>
> >> > >> > > authorizationService =
> >> > >> > > ServiceLocator.Current.GetInstance<IAuthorizationService>();
> >> > >> > > permissionService =
> >> > >> > > ServiceLocator.Current.GetInstance<IPermissionsService>();
> >> > >> > > permissionsBuilderService =
> >> > >> > > ServiceLocator.Current.GetInstance<IPermissionsBuilderService>();
> >> > >> > > authorizationRepository =
> >> > >> > > ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
>
> >> > >> > > authorizationRepository.CreateUsersGroup("Administrators");
> >> > >> > > authorizationRepository.CreateUsersGroup("Users");
> >> > >> > > authorizationRepository.CreateUsersGroup("Guests");
>
> >> > >> > > authorizationRepository.AssociateUserWith(user, "Administrators");
> >> > >> > > authorizationRepository.AssociateUserWith(user, "Users");
> >> > >> > > authorizationRepository.AssociateUserWith(user, "Guests");
>
> >> > >> > > I've added this fixture
>
> >> > >> > > [Fact]
> >> > >> > > public void Test_Associated_Users_Group_For()
> >> > >> > > {
>
> >> > >> > > session.Flush();
> >> > >> > > session.Transaction.Commit();
> >> > >> > > session.Dispose();
>
> >> > >> > > using (var s2 = factory.OpenSession())
> >> > >> > > {
> >> > >> > > using (var tx = s2.BeginTransaction())
> >> > >> > > {
> >> > >> > > SillyContainer.SessionProvider = () => s2;
>
> >> > >> > > var User = s2.CreateCriteria<User>()
> >> > >> > > .Add(Restrictions.Eq("Name", "Ayende"))
> >> > >> > > .UniqueResult<User>();
>
> >> > >> > > var anotherAuthorizationRepository =
> >> > >> > > ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
>
> >> > >> > > var Groups =
> >> > >> > > anotherAuthorizationRepository.GetAssociatedUsersGroupFor(User);
>
> >> > >> > >
> >> > >> > > anotherAuthorizationRepository.DetachUserFromGroup(User,
> >> > >> > > "Guests");
>
> >> > >> > > s2.Flush();
> >> > >> > > tx.Commit();
> >> > >> > > }
> >> > >> > > }
> >> > >> > > using (var s3 = factory.OpenSession())
> >> > >> > > {
> >> > >> > > using (var tx = s3.BeginTransaction())
> >> > >> > > {
> >> > >> > > SillyContainer.SessionProvider = () => s3;
>
> >> > >> > > var User = s3.CreateCriteria<User>()
> >> > >> > > .Add(Restrictions.Eq("Name", "Ayende"))
> >> > >> > > .UniqueResult<User>();
>
> >> > >> > > var anotherAuthorizationRepository =
> >> > >> > > ServiceLocator.Current.GetInstance<IAuthorizationRepository>();
> >> > >> > > var Groups =
> >> > >> > > anotherAuthorizationRepository.GetAssociatedUsersGroupFor(User);
>
> >> > >> > > tx.Commit();
> >> > >> > > }
> >> > >> > > }
>
> >> > >> > > }
>
> >> > >> > > The 2nd session detaches the user from the group Guests but the
> >> > >> > > 3rd
> >> > >> > > session still fetches 3 groups associated with the user.
> >> > >> > > It seems that the second-level cache can't be invalidated.
> >> > >> > > Is there anyone who can help me?- Hide quoted text -
>
> >> > >> - Show quoted text -
>
> >> > > --
> >> > > You received this message because you are subscribed to the Google
> >> > > Groups "Rhino Tools Dev" group.
> >> > > To post to this group, send email to [email protected].
> >> > > To unsubscribe from this group, send email to
> >> > > [email protected].
> >> > > For more options, visit this group
> >> > > athttp://groups.google.com/group/rhino-tools-dev?hl=en.-Hidequoted
> >> > > text -
>
> >> > - Show quoted text -- Hide quoted text -
>
> >> - Show quoted text -
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Rhino Tools Dev" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group
> > athttp://groups.google.com/group/rhino-tools-dev?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en.