Thank you for looking at this. Your two changes work great for
removing a user from a group. However, adding users has the same issue
as you suggested.

Calling GetAssociatedUsersGroupFor after adding a user to the group
does not return the newly associated group.

The analogous change probably needs to be made to the association
code. I am a bit reluctant to try it myself not fully understanding
the ramifications of the change. My first attempt did not work.

Perhaps you can finish off the change? I’d be happy to test it for
you.

Thank you again!



On Apr 12, 8:17 am, vandalo <alberto.bas...@gmail.com> wrote:
> 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 thecachejust 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 thecache.
>
> On Mar 26, 12:38 am, Nathan Stott <nrst...@gmail.com> 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 <m6gamingj...@gmail.com> wrote:
> > > Hello? Is anyone home?
>
> > > On Mar 11, 5:23 pm, RickB <m6gamingj...@gmail.com> 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 <nrst...@gmail.com> 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 <m6gamingj...@gmail.com> wrote:
> > >> > > Does anyone know if this issue has been fixed?
>
> > >> > > Thank you,
>
> > >> > > Rick
>
> > >> > > On Feb 25, 12:14 am, vandalo <alberto.bas...@gmail.com> wrote:
> > >> > >> Thanks David,
>
> > >> > >> Alberto
>
> > >> > >> On Feb 23, 11:58 pm, David Archer <darc...@gmail.com> 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 <alberto.bas...@gmail.com> 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 thesecond-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 thesecond-levelcachecan'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 
> > >> > > rhino-tools-dev@googlegroups.com.
> > >> > > To unsubscribe from this group, send email to 
> > >> > > rhino-tools-dev+unsubscr...@googlegroups.com.
> > >> > > For more options, visit this group 
> > >> > > athttp://groups.google.com/group/rhino-tools-dev?hl=en.-Hidequotedtext
> > >> > >  -
>
> > >> > - 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 rhino-tools-dev@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > rhino-tools-dev+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/rhino-tools-dev?hl=en.- 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 rhino-tools-dev@googlegroups.com.
To unsubscribe from this group, send email to 
rhino-tools-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en.

Reply via email to