cogImports LDAP users into XWiki's database
Developed by

Vincent Massol

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

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.

Code

<%
if (request.get("go") == "1")
{
  results = xwiki.ldap.search("objectclass=*")
  for (res in results.values())
  {
    if (res.get("cn") == null)
      continue;
    username = res.get("cn").toLowerCase()
    username = context.getContext().getWiki().convertUsername(username, context.getContext())
    def created = "created"
    udoc = xwiki.getDocument("XWiki." + username)
    if (!udoc.isNew())
    {
      udoc.delete()
      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]
#end

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags: users groovy
Created by VincentMassol on 2007/09/14 13:32
     

Get Connected