Hi Raff, I have enabled LDAP authentication and it works fine. Now I would want to add the LDAP user on first logon, don't want a bulk LDAP import. I am groovy illiterate, so trying to modify what you have written, and referring to java code...Also, where do I put the following script for it to run? I am supposing you have to put it in the wiki main home page itself.. Something like - <%if (request.get("go") == "1") { username = request.getUserPrincipal() username = context.getContext().getWiki().convertUsername(username, context.getContext()) def created = "created" udoc = xwiki.getDocument("XWiki." + username) if (!udoc.isNew()) { udoc.delete() created = "updated" } xwiki.createEmptyUser(username,null,context.getContext()) print("*" + created + "*" + " ") print (" [XWiki." + username + "]") } } %> #if(!$request.get("go") || $request.get("go") != "1") [Import and/or Update Users>$doc.name?go=1] #end Thanks Praveen -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Raffaello Pelagalli Sent: Friday, September 14, 2007 2:22 PM To: XWiki Users Subject: Re: [xwiki-users] LDAP - importing users Raffaello Pelagalli <[email protected]> writes:
<[email protected]> writes:
Is there any way I can import users into XWiki from an LDAP source. I am currently authenticating users against LDAP, but am unable to create groups, or set specific rights to these LDAP users.
Thanks and Regards
Praveen Koduganty.
Hi,
I think you are looking for a script like this one :
----------------------START--------------------- <% 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 ("{pre}" + res.get("cn") + "{/pre} [XWiki." + username + "]<br/>") } } %>
#if(!$request.get("go") || $request.get("go") != "1") [Import and/or Update Users>$doc.name?go=1] #end ----------------------END-----------------------
Perhaps you will need to modify it to fit your needs.
You should take a look at the ldap plugin API (exactly this file :
http://svnmirror.xwiki.org/svn/mirror/xwiki/xwiki-platform/core/trunk/xw iki-core/src/main/java/com/xpn/xwiki/plugin/ldap/LDAPPluginApi.java)
Best regards,
Due to a bug in the LDAPPlugin, the line 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. Best regards, -- Raffaello Pelagalli XPertNet - XWiki.com _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly prohibited and may be unlawful.