Changes for page XML-RPC Java Examples

Last modified by Thomas Mortagne on 2023/10/10 14:31

From version 3.3
edited by dilipkumarj
on 2010/03/14 20:15
Change comment: Added code snippet for Creating New User through XML-RPC
To version 4.1
edited by dilipkumarj
on 2010/03/14 20:19
Change comment: Added code snippet for Adding User to Groups through XML-RPC

Summary

Details

Page properties
Tags
... ... @@ -1,1 +1,1 @@
1 -xmlrpc|java|example|page|space|authentication|create|delete|update|attachment
1 +xmlrpc|java|example|page|space|authentication|create|delete|update|attachment|user|groups|associate|association
Content
... ... @@ -627,3 +627,54 @@
627 627  }
628 628  
629 629  {{code}}
630 +
631 += User: Add User To Groups =
632 +
633 +Adding User to Groups is a very simple task. This requires us to add the desired user to the properties of the Group in question. The example below details all the steps needed to complete this task:
634 +
635 +{{code langauge="java"}}
636 +
637 +import java.net.MalformedURLException;
638 +import java.security.NoSuchAlgorithmException;
639 +import org.apache.xmlrpc.XmlRpcException;
640 +import org.codehaus.swizzle.confluence.Page;
641 +import org.xwiki.xmlrpc.XWikiXmlRpcClient;
642 +import org.xwiki.xmlrpc.model.XWikiObject;
643 +
644 +
645 +public class AddUserToGroup {
646 +public static void main(String[] args) throws MalformedURLException, XmlRpcException, NoSuchAlgorithmException {
647 +
648 + //URL of the xwiki instance
649 + String url = "http://localhost:8080/xwiki/xmlrpc/confluence";
650 +
651 + //Replace user & pass with desired xwiki username & password
652 + String user = "Admin";
653 + String pass = "admin";
654 +
655 +
656 + XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
657 + try {
658 + //Perform Login & Authentication
659 + rpc.login(user, pass);
660 +
661 + //Associate an existing user to the XWikiAllGroup
662 + //We simply associate the XWiki.testuser Page to the XWiki.XWikiAllGroup Page
663 + //Set the "member" property to the desired XWiki UserName
664 + //You may associate the member to any custom Group you may have created
665 +
666 + XWikiObject xobjgrp = new XWikiObject();
667 + xobjgrp.setClassName("XWiki.XWikiGroups");
668 + xobjgrp.setPageId("XWiki.XWikiAllGroup");
669 + xobjgrp.setProperty("member","XWiki.testuser");
670 + rpc.storeObject(xobjgrp);
671 +
672 + } catch (XmlRpcException e) {
673 + System.out.println(e);
674 + } finally {
675 + rpc.logout();
676 + }
677 + }
678 +}
679 +
680 +{{code}}

Get Connected