Hi Nithya,
As Sergiu rightly said, an XWiki user is just another document/Page with a
XWiki.XWikiUser object associated to it.
Hope the following example helps you in creating users using XMLRPC.
Please note that I have only been able to create a user. "Setting" the
password is something I did not have much luck with.
Probably, the XMLRPC API method to set the "password" property stores the
password in plain text when in fact XWiki expects passwords which are
"hashed".
I hope someone on the mailing list could help by providing the code snippet
to update password using XMLRPC. Once, that is done, we can save this
example  at
http://platform.xwiki.org/xwiki/bin/view/Features/XMLRPCJavaExamples

========================================================================


import java.net.MalformedURLException;
import org.apache.xmlrpc.XmlRpcException;
import org.codehaus.swizzle.confluence.Page;
import org.xwiki.xmlrpc.XWikiXmlRpcClient;
import org.xwiki.xmlrpc.model.XWikiObject;

public class CreateUser {

    public static void main(String[] args) throws MalformedURLException,
XmlRpcException {

        //URL of the xwiki instance
        String url = "http://localhost:8080/xwiki/xmlrpc/confluence";;

        //Replace user & pass with desired xwiki username & password
        String user = "Admin";
        String pass = "admin";

        XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
        try {
            //Perform Login & Authentication
            rpc.login(user, pass);

            //Create a Page to hold the user profile & set it's three
important attributes viz. Space, Title, Content
                        //Set the space="XWiki" since all XWiki users go to
"XWiki" space by default
                        //Set title to the username of the user. In our
case, username="testuser"
                        //Set content to include the XWikiUserSheet. 
                        //Without this the user Page will come up blank and
no fields will be displayed

            Page page = new Page();
            page.setSpace("XWiki");
            page.setTitle("testuser");
            page.setId("XWiki.testuser");
            page.setContent("{{include
document=\"XWiki.XWikiUserSheet\"/}}");
            rpc.storePage(page);

                        //Create a XWikiObject and set the class to
XWiki.XWikiUsers
                        //Set the "host" Page as XWiki.testuser. This is the
page we created in the steps above
                        //Set the first_name & last_name properties with
values "Test" and "User" respectively
                        //We can access the list of all properties for a
User class at the following link:
        
//http://localhost:8080/xwiki/bin/edit/XWiki/XWikiUsers?editor=class
                        //Finally, save the object using rpc.storeObject
                        
            XWikiObject xobj = new XWikiObject();
            xobj.setClassName("XWiki.XWikiUsers");
            xobj.setPageId("XWiki.testuser");
            xobj.setProperty("first_name", "Test");
            xobj.setProperty("last_name", "User");
            rpc.storeObject(xobj);

        } catch (XmlRpcException e) {
            System.out.println(e);
        } finally {
            rpc.logout();
        }
    }
}
 
========================================================================


Message: 1
Date: Wed, 3 Mar 2010 09:33:05 -0800 (PST)
From: Nithya Vembu <[email protected]>
Subject: [xwiki-users] Creating user using XML RPC....
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


Hi All,

 Is there any sample available to create a user through XML RPC like the
examples in the following link for creation of page, space etc..

http://platform.xwiki.org/xwiki/bin/view/Features/XMLRPCJavaExamples

Please help me out if there any solution.

Thanks,
Nithya.
-- 
View this message in context:
http://n2.nabble.com/Creating-user-using-XML-RPC-tp4669004p4669004.html
Sent from the XWiki- Users mailing list archive at Nabble.com.


------------------------------

Message: 2
Date: Wed, 03 Mar 2010 19:23:44 +0100
From: Sergiu Dumitriu <[email protected]>
Subject: Re: [xwiki-users] Creating user using XML RPC....
To: XWiki Users <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 03/03/2010 06:33 PM, Nithya Vembu wrote:
>
> Hi All,
>
>   Is there any sample available to create a user through XML RPC like the
> examples in the following link for creation of page, space etc..
>
> http://platform.xwiki.org/xwiki/bin/view/Features/XMLRPCJavaExamples
>
> Please help me out if there any solution.

A user is just like any other document+object. Just do what's usually 
done for creating a new document and adding a XWiki.XWikiUsers object.

Don't forget to add the user to the groups you want.

-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/


------------------------------

_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to