Im two openfire integrate existing system users

Source: Internet
Author: User
Tags md5 hash sha1

Hefei Programmer Group: 49313181. Hefei Real-name programmer Group: 128131462 (do not want to disclose names and information to join)
Q q:408365330 E-mail:[email protected]

Review:

Daily use of noon time to update this knowledge point of the blog if you are interested in the update slow also don't mind (other time or work-based, learning work two not wrong, haha ...) )。 I briefly explained the XMPP protocol on a purely theoretical basis, but now the more XMPP protocol servers used are of course openfire most popular (I feel). As for how to build oprenfire two times the development environment and the code to run, this article does not introduce, the next introduction, may be a bit of a disorderly feeling, but mainly I recently two days to engage in IM integration of existing system users. So this is a record is also issued to share with you (after all, many blogs online is not verified theory), I here are through the actual environment and passed the test, otherwise I will not record. Here we need two source code, because in the configuration we will do source debugging, on the one hand we want to read OpenFire source, on the other hand we want a client login XMPP server chat authentication, First, there are two of the source code in eclipse structure (the following will be recorded how to build the source environment and the source code to run up)

Figure 1

First of all, the OpenFire source uses the latest version 3.10.2, client Spark is a PC client, using the latest version of 2.7.2, as shown in.

First describe the business scenario, the company has an existing OA system that is developed under the. NET (C # language) platform, using SQL Server database. Let post to OA plus instant chat function, originally is intended to maintain two user data, later learned that the existing OA user is the password is MD5 encryption, and OpenFire default is Blowfish encryption, this time if the new user is OK, But what about the MD5 encrypted users in the OA system used in the past? If the direct import into the IM user table is definitely not available, this time need to consolidate the existing user tables, OpenFire user table obsolete, only use the existing System User table, OA system and OpenFire are through the OA System User table login, so need to integrate. Then it is inevitable to analyze OpenFire source code, only the following text, according to OpenFire source code let you know its why. Otherwise only know this configuration, and do not know why this configuration, it is not good, everything clear (Program Ape spirit).

OpenFire integration of existing system users

First clear my existing system is a SQL Server database, IM is also SQL Server (of course, mixed database is also possible, has done so im is mysql, there is a system is SQL Server).

I. Configuration Provider.auth.className

Private Static voidInitprovider () {//Convert XML based provider Setup to Database basedJiveglobals.migrateproperty ("Provider.auth.className"); String ClassName= Jiveglobals.getproperty ("Provider.auth.className",                "Org.jivesoftware.openfire.auth.DefaultAuthProvider"); //Check If we need to reset the Auth provider class        if(Authprovider = =NULL|| !classname.equals (Authprovider.getclass (). GetName ())) {            Try{Class C=Classutils.forname (className); Authprovider=(Authprovider) c.newinstance (); }            Catch(Exception e) {log.error ("Error Loading Auth provider:" +ClassName, E); Authprovider=NewDefaultauthprovider (); }        }    }

By the OpenFire source in the Authfactory class we know that its static function calls this initprovider () This static function initializes some configuration, and then constructs a authprovider through this configuration. The key for this configuration is Provider.auth.className, the default is to use the Org.jivesoftware.openfire.auth.DefaultAuthProvider class, if we configure Provider.auth.className then Using the configured class, then we can

OpenFire Source to find Defaultauthprovider class inherit from Jdbcauthprovider, inherit from Authprovider class fully meet the requirements, modify the Ofproperty table corresponding values in the database, such as:

Figure 2

In this way, user authentication is done by Org.jivesoftware.openfire.auth.JDBCAuthProvider to verify the row. We continue to follow OpenFire Java source code, into the Jdbcauthprovider class, its constructor codes are as follows:

Figure 3

It is easy to know from Figure 3 that we are going to configure various parameters as follows:

Drive: Jdbcprovider.driver

Connection string: jdbcprovider.connectionstring

SQL statement for query password: jdbcauthprovider.passwordsql

Encryption type of password: jdbcauthprovider.passwordtype

SQL statement to set password: jdbcauthprovider.setpasswordsql

Whether to allow changes to the password (by the latter source know true or false): AllowUpdate

Then we now come to a tracking source to explain the integration of users.

1. Configure the driver jdbcprovider.driver here is the SQL Server database so use Net.sourceforge.jtds.jdbc.Driver.

2. Configure the connection string jdbcprovider.connectionstring: Jdbc:jtds:sqlserver://192.168.11.21:1433/oa_frame;appname=jive;user=sa ;p assword=mm replace it with your own

3. Configure the query password string jdbcauthprovider.passwordsql to: Select Userpwd from Bt_user where username=? Here username is the user login name, userpwd is the password field, Bt_user is the user table. Why is this so please look at the following source code to understand:

Figure 5

4. Configure the password encryption type Jdbcauthprovider.passwordtype to MD5, but be sure to note that the string "MD5" if asked why, that is because OpenFire source does not know "MD5" this capitalization. Which encryption method does this support?? It is easy to have the following enumeration know: Plain does not encrypt, md5,sha1,sha256,sha512 these encryption methods

1   Public enumPasswordtype {2 3         /**4 * The password is stored as plain text.5          */6 Plain,7 8         /**9 * The password is stored as a hex-encoded MD5 hash.Ten          */ One MD5, A  -         /** - * The password is stored as a hex-encoded SHA-1 hash. the          */ - SHA1, -          -         /** + * The password is stored as a hex-encoded SHA-256 hash. -          */ + sha256, A                at         /** - * The password is stored as a hex-encoded SHA-512 hash. -           */ - sha512; -}

5. Set the Change password SQL script Jdbcauthprovider.setpasswordsql according to their own needs to set the change password script, according to the source can be known that it is also the user login as a conditional query modification, that is, modify the user's password to make the login name.

6. Configure whether to allow password change allowupdate If JDBCAUTHPROVIDER.SETPASSWORDSQL is configured, insert True. Otherwise the Jdbcauthprovider.setpasswordsql configuration is useless, see the code why

Figure 6

Figure 6 out why?? :)

Two. Configure Provider.user.className

We configure Provider.user.className for org.jivesoftware.openfire.user.JDBCUserProvider See Figure 2 above. This configuration is good, then we will configure the relevant properties. Look at the code:

Figure 7

It's easy to see what properties we want to configure here:

1.jdbcprovider.driver (already configured above)

2.jdbcprovider.connectionstring (already configured above)

3.jdbcuserprovider.loadusersql

4.jdbcuserprovider.usercountsql

5.jdbcuserprovider.alluserssql

6.jdbcuserprovider.searchsql

7.jdbcuserprovider.usernamefield

8.jdbcuserprovider.namefield

9.jdbcuserprovider.emailfield

1. Configure the Load user information SQL script Jdbcuserprovider.loadusersql is a string that queries the user information based on the login select Realname,email from Bt_user where username=? Let's look at the source code again:

Figure 8

From the above Figure 8 know, we query only need to query the user name (not login), the mailbox is OK, other queries come out also no use, and the field order is correct oh (see the source know that the user is loaded into the cache after the first time).

2. Configure the number of query users script jdbcuserprovider.usercountsql: SELECT COUNT (*) from Bt_user This is nothing to explain.

3. Configure User Login Name field Jdbcuserprovider.usernamefield We're username here.

4. Configure user name Jdbcuserprovider.namefield: realname Here is the nickname or the real name, this depends on your specific business because this is to show the user to see

5. Configure the Mailbox field Jdbcuserprovider.emailfield: Email is user mailbox nothing to say

End:

Above the configuration Jdbcauthprovider and Jdbcuserprovider here to complete, restart OpenFire and then re-login at this time the user found that the user is now used in the old system of users, User integration is complete (or at least user data consolidation is complete). more configuration: If you have a user department or something in your system, and if you want to openfire support integration after the user has more operations then also need to configure other things, I do not explain, but follow this source tracking ideas enough to cope with the various configurations, has been configured to appear in the problem.

Integrated configuration points:

A):p Rovider.auth.className

Drive: Jdbcprovider.driver

Connection string: jdbcprovider.connectionstring

SQL statement for query password: jdbcauthprovider.passwordsql

Encryption type of password: jdbcauthprovider.passwordtype

SQL statement to set password: jdbcauthprovider.setpasswordsql

Whether to allow changes to the password (by the latter source know true or false): AllowUpdate

II): Provider.auth.className

Jdbcprovider.driver (already configured above)

Jdbcprovider.connectionstring (already configured above)

Jdbcuserprovider.loadusersql

Jdbcuserprovider.usercountsql

Jdbcuserprovider.alluserssql

Jdbcuserprovider.searchsql

Jdbcuserprovider.usernamefield

Jdbcuserprovider.namefield

Jdbcuserprovider.emailfield

Postscript:

Interested or have questions can add the QQ group above to discuss what the problem of consultation welcome to disturb. Business cooperation is certainly more welcome

Im two openfire integrate existing system users

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.