Log User Group after CMS login

Hi everybody,
I’m trying to access the user group of a user who logs into the cms. I tried to write my own custom Authentication Provider and just log the user group but until now I had no success.
I only managed to write a custom login class which extends the DefaultLoginPlugin and now I’m able to log the username in the loginSuccess method of every user that logs in.

Is there a not to complicated way to also get the user group of that user?
Thanks in regards!

To retrieve the groups of a user, use the user’s session to perform a simple jcr query for hipposys:group nodes. Because of security, and unless this user is an admin, your results will contain only the groups this user can see, which are the ones he belongs in.

hth!

Thanks for the answer!
I’m really new to hippo, could you look over my query and tell me if that’s the right approach?

Session session = UserSession.get();
Query userGroupQuery = ((UserSession) session).getQueryManager().createQuery("Select * from hipposys:group", Query.SQL);
QueryResult result = userGroupQuery.execute();