C # obtain openfire users, including add, delete, and modify users,

Source: Internet
Author: User

C # obtain openfire users, including add, delete, and modify users,

Currently, the simple method is to use the openfire Plug-In User Service. We use the C # http request to obtain the User list and return an xml file.

Plug-in address: http://www.igniterealtime.org/projects/openfire/plugins.jsp

There are two ways to install the plug-in:

1. Download The userservice. jar file directly from the official website, and then upload the plug-in through the management and control platform.

2. Install this plug-in directly on the management and control platform. There is a "valid plug-in" menu on the plug-in tab, which contains many plug-ins.


I. First, you need to install the openfire Server, including configuring the database to test whether the Server can run. Take win7 as an example. In the Start Menu, find "Openfire Server" and click Run, click "Star" to start the server, and then click "Laumch Admin" to go to the management and control platform, and enter the administrator password to log on. For example:


2. Find the "ins" tab on the management and control platform. There is a User Service plug-in that we need to install. If you have installed the plug-in, it will show which plug-ins have been installed and are not installed, you need to click "valid plug-ins" in the left-side menu and find this plug-in the list for installation. It may be a little slow. Just wait. If you do not find many INS in the valid ins list, you need to reinstall the openfire server or upgrade the latest version.



3. On the "server" tab, find "Server Settings". There is a menu "User Service", which indicates that the plug-in is successfully installed, but you still need to set it to access through the port, otherwise, you cannot access the service or report an error, such as 401 being unauthorized. Set: Enabled-User service requests will be processed. enable and check HTTP basic auth-User service REST authentication with Openfire admin account. if Secret key auth is selected, it is too troublesome to write C #. You need to pass the Secret key value through the access interface. Otherwise, the error 401 is returned.

You can also add an interface in system properties to set whether the interface is enabled. You need to set two values, for example:



Access through the C # code is as follows:

string url = "http://127.0.0.1:9090/plugins/userService/users";            WebRequest req = WebRequest.Create(url);            string username = "admin";            string password = "admin";            string usernamePassword = username + ":" + password;            CredentialCache mycache = new CredentialCache();            mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));            req.Credentials = mycache;            req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));            WebResponse result = null;            try            {                result = req.GetResponse();                Stream ReceiveStream = result.GetResponseStream();                //read the stream into a string                StreamReader sr = new StreamReader(ReceiveStream);                string resultstring = sr.ReadToEnd();            }            catch (Exception exp)            {                Console.WriteLine(exp.Message);            }            finally            {                if (result != null)                {                    result.Close();                }            }

Finally, an xml file containing information of all users is returned.

As for the new, delete interface will not be in the case, you can find the demo through the Management Control Platform, there is an introduction to the interface, view address: http: // 127.0.0.1: 9090/plugin-admin.jsp? Plugin = userservice & showReadme = true & decorator = none

Click the icon to view the demo of this plug-in:




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.