Hi, from the hints I managed to cobble together a piece of code that works. Another problem was presented by the multithreading that happened when a user opened several iFrames containing XWiki pages at the same time. This led to the weird behaviour of stuff changing while I was processing the user.
Thanks, J.L.Simon On 03.02.2009, at 19:41, Thomas Mortagne wrote: > On Tue, Feb 3, 2009 at 5:17 PM, Juergen Lorenz Simon <[email protected] > > wrote: >> >> On 03.02.2009, at 16:08, Thomas Mortagne wrote: >> >>> Hi, >>> >>> The best documentation right now is to look at existing >>> authenticators >>> like XWikiLDAPAuthServiceImpl which create/update users and add/ >>> remove >>> users from groups. >> >> Unfortunately, the existing authenticator implementations do not seem >> to create groups and >> assign users to them. The current code works somewhat, but it has one > > LDAP authenticator does not create groups but it assign users to them, > and when I say it does not create groups it just means it specifically > avoid adding users to not existing groups since technically an empty > group does not really exists. A groups is a wiki page containg objects > of class XWiki.XWikiGroups each object representing a member (a user > or a sub-group). > > Look at XWikiLDAPAuthServiceImpl#addUserToXWikiGroup to see exactly > what means adding a user in a group. If you want to check if a user is > in a group simply look if this group's document contains the member > object for this user object. > >> big problem! The >> following methods produce flaky results at best: >> >> XWikiGroupService gService = >> context.getWiki().getGroupService(context); >> boolean groupHasUser = gService.getAllGroupsNamesForMember(user, 100, >> 0, context).contains("XWiki."+PORTAL_GROUP_NAME); >> boolean userInGroup = >> gService >> .getAllMatchedMembersNamesForGroup("XWiki."+PORTAL_GROUP_NAME, >> null, 1000000, 0, true, context).contains(user); >> >> many times, both calls suggest that the user is not in the group! >> Even >> if he is! Which means >> that the user is added to the group many, many times! The first call >> to gService is the most >> unreliable, but I would prefer it to the second call, since we're >> talking a potential 10.000 >> users or more. I don't want to lug around collections with 10k+ >> objects just to check if the >> user is in the group? >> >> Help! >> >>> On Tue, Feb 3, 2009 at 3:25 PM, Juergen Lorenz Simon <[email protected] >>>> wrote: >>>> Hi, >>>> >>>> sorry for being thick, but I can't find any documentation at all >>>> how >>>> to do this in Java and I still >>>> need some help with this. >>>> >>>> In our authenticator I'd like to check if users coming from a >>>> certain >>>> angle (i can check on that >>>> through cookies) are in a special group. If they are not, I'd >>>> like to >>>> add the to this group. >>>> >>>> Furthermore this group needs to asserted of, so I need to be able >>>> to >>>> reliably find out if it >>>> does exist and if not, create it. >>>> >>>> So far I've been frustrated by failure by attempting to use the >>>> XWikiGroupService to achieve this. >>>> Also I don't seem to be able to find a clean documentation on how >>>> users and groups and done >>>> in XWikI (in java, especially). Is there such documentation? >>>> >>>> The following code, to much bewilderment, creates a USER?! >>>> >>>> public void checkPortalGroup(XWikiContext context) { >>>> if (!_portalGroupChecked) { >>>> try { >>>> boolean groupExists = false; >>>> List<String> groupList = >>>> context.getWiki().getGroupService(context).listAllGroups(context); >>>> for (ListIterator<String> groups = groupList.listIterator(); >>>> groups.hasNext() && !groupExists;) { >>>> groupExists = groups.next().equals(PORTAL_GROUP_NAME); >>>> } >>>> if (!groupExists) { >>>> log.info("Group "+PORTAL_GROUP_NAME+" does not exist and >>>> will be created."); >>>> BaseCollection portalGroup = >>>> context.getWiki().getGroupClass(context).newObject(context); >>>> portalGroup.setName(PORTAL_GROUP_NAME); >>>> >>>> context.getWiki().getHibernateStore().saveXWikiObject((BaseObject) >>>> portalGroup, context, true); >>>> } >>>> } catch (XWikiException e) { >>>> log.error("Exception while locating or creating group >>>> "+PORTAL_GROUP_NAME+" : "+e.getMessage()); >>>> e.printStackTrace(); >>>> } >>>> _portalGroupChecked=true; >>>> } >>>> } >>>> >>>> I need some serious pointers on how the xwiki objects/classes thing >>>> is >>>> supposed to work >>>> for users/groups. >>>> >>>> Thanks a lot, >>>> J.L.Simon >>>> _______________________________________________ >>>> devs mailing list >>>> [email protected] >>>> http://lists.xwiki.org/mailman/listinfo/devs >>>> >>> >>> >>> >>> -- >>> Thomas Mortagne >>> _______________________________________________ >>> devs mailing list >>> [email protected] >>> http://lists.xwiki.org/mailman/listinfo/devs >>> >> >> _______________________________________________ >> devs mailing list >> [email protected] >> http://lists.xwiki.org/mailman/listinfo/devs >> > > > > -- > Thomas Mortagne > _______________________________________________ > devs mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/devs > _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

