cogImports LDAP users into XWiki's database
Developed by

Vincent Massol

0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents


This snippet is based on the old deprecated LDAP authenticator (LDAPAuthServiceImpl) and will produce bad results if you use it with the new one (XWikiLDAPAuthServiceImpl). The xwiki.ldap plugin need to be refactored first.

Due to a bug in the LDAPPlugin, the line below that says xwiki.ldap.createUserFromLDAP(username, res.get('cn'), null, null) has to be replaced by xwiki.ldap.getPlugin().createUserFromLDAP(username, res.get('cn'), null, null, context.getContext()) or the script will never finish.


if (request.get("go") == "1")
  results ="objectclass=*")
  for (res in results.values())
    if (res.get("cn") == null)
    username = res.get("cn").toLowerCase()
    username = context.getContext().getWiki().convertUsername(username, context.getContext())
    def created = "created"
    udoc = xwiki.getDocument("XWiki." + username)
    if (!udoc.isNew())
      created = "updated"
    xwiki.ldap.createUserFromLDAP(username, res.get("cn"), null, null)
    print("*" + created + "*" + " ")
    print ("" + res.get("cn") + " [XWiki." + username + "]")

#if("$!request.go" != '1')
[Import and/or Update Users>${doc.fullName}?go=1]
Tags: users groovy

Get Connected