OpenFire using the Custom user table

Source: Internet
Author: User

OpenFire using custom user tables-Nomousewch's column-Blog channel-csdn.net

In recent projects using OpenFire server to implement message push function, if you use the OpenFire comes with the user table, need to maintain two user tables, not very convenient, if OpenFire can directly use the existing System User table is more convenient, In fact OpenFire has taken this into account for us, and we just need to do some configuration.

    • Principle
Research the source of the next openfire, found that the key to achieve this point is the application of data provider, in short, it is necessary in the program to use persistent data (such as user name, department name, which can be stored in the database, can also be stored in the XML file or LDAP directory service, a provider as a unified interface to obtain data, for different data sources (can be different tables of the database, but also can be NoSQL, XML and other data sources) corresponding implementation, such as the Authprovider interface (responsible for user authentication), it has two different implementations Defaultauthprovider and Jdbcauthprovider
, the former is the default OpenFire table, while the latter is based on our custom data table, we configure the default Defaultauthprovider to Jdbcauthprovider, and add some configuration text, you can switch the data source.
    • Specific configuration

Go to OpenFire Management Console-server-Service Manager-System Properties

Add the following key-value pairs, or update the data table directly in the database

[SQL]View Plaincopyprint?
  1. --Set the JDBC Connection mode
  2. Insert  into Ofproperty (NAME, PropValue)
  3. Values (' jdbcprovider.connectionstring ',
  4. ' JDBC:ORACLE:THIN:@10.35.246.178:1521:ORCL ');
  5. Insert  into Ofproperty (NAME, PropValue)
  6. Values (' Jdbcprovider.driver ', ' Oracle.jdbc.driver.OracleDriver ');
  7. --Set Administrator account
  8. Insert  into Ofproperty (NAME, PropValue)
  9. Values (' Admin.authorizedjids ', ' [email protected] ');
  10. --Custom user authentication
  11. Insert  into Ofproperty (NAME, PropValue)
  12. Values (' Jdbcauthprovider.useconnectionprovider ', ' true ');
  13. Insert  into Ofproperty (NAME, PropValue)
  14. Values (' Jdbcauthprovider.passwordsql ', ' select ''123456 'as pwd from
  15. T_sys_user T where t.code=? ');
  16. Insert  into Ofproperty (NAME, PropValue)
  17. Values (' Jdbcauthprovider.passwordtype ', ' Plain ');
  18. --Custom user management
  19. Insert  into Ofproperty (NAME, PropValue)
  20. Values (' jdbcuserprovider.alluserssql ', 'select code from T_sys_user
  21. T ');
  22. Insert  into Ofproperty (NAME, PropValue)
  23. Values (' Jdbcuserprovider.namefield ', ' name ');
  24. Insert  into Ofproperty (NAME, PropValue)
  25. Values (' jdbcuserprovider.searchsql ', 'select code from T_sys_user t
  26. where code=? ');
  27. Insert  into Ofproperty (NAME, PropValue)
  28. Values (' Jdbcuserprovider.useconnectionprovider ', ' true ');
  29. Insert  into Ofproperty (NAME, PropValue)
  30. Values (' Jdbcuserprovider.emailfield ', ' email ');
  31. Insert  into Ofproperty (NAME, PropValue)
  32. Values (' jdbcuserprovider.usercountsql ', 'select Count(*) from
  33. T_sys_user t ');
  34. Insert  into Ofproperty (NAME, PropValue)
  35. Values (' jdbcuserprovider.loadusersql ', 'select T.name, T.email,t.code
  36. from T_sys_user t where t.code=? ');
  37. Insert  into Ofproperty (NAME, PropValue)
  38. Values (' Jdbcuserprovider.usernamefield ', ' Code ');
  39. --Use a different data source
  40. Update Ofproperty Set
  41. propvalue=' Org.jivesoftware.openfire.user.JDBCUserProvider '
  42. where NAME=' Provider.user.className ';
  43. Update Ofproperty Set
  44. propvalue=' Org.jivesoftware.openfire.auth.JDBCAuthProvider '
  45. where NAME=' Provider.auth.className ';
  46. commit;
--Set the JDBC Connection mode insert into Ofproperty (NAME, PropValue) VALUES (' jdbcprovider.connectionstring ', ' jdbc:oracle:thin:@ 10.35.246.178:1521:orcl '); insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcprovider.driver ', ' Oracle.jdbc.driver.OracleDriver ');--Set Administrator account insert into Ofproperty (NAME, PropValue) VALUES (' Admin.authorizedjids ', ' [email protected] ');--Custom user authentication insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcauthprovider.useconnectionprovider ', ' true '); insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcauthprovider.passwordsql ', ' select ' 123456 ' as pwd from T_sys_user t where t.code=? '); Insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcauthprovider.passwordtype ', ' Plain ');--Custom user management insert INTO Ofproperty (NAME, PropValue) VALUES (' Jdbcuserprovider.alluserssql ', ' Select code from T_sys_user t '); INSERT into Ofproperty (name, PropValue) VALUES (' Jdbcuserprovider.namefield ', ' name '); insert into Ofproperty (name, PropValue) VALUES (' Jdbcuserprovider.searchsql ', ' Select code from T_sys_uSer t where code=? '); Insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcuserprovider.useconnectionprovider ', ' true '); Ofproperty (name, PropValue) VALUES (' Jdbcuserprovider.emailfield ', ' email '); insert into Ofproperty (name, PropValue) VALUES (' Jdbcuserprovider.usercountsql ', ' SELECT count (*) from T_sys_user t ') and insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcuserprovider.loadusersql ', ' select T.name,t.email,t.code from T_sys_user t where t.code=? '); Insert into Ofproperty (NAME, PropValue) VALUES (' Jdbcuserprovider.usernamefield ', ' Code ');--use a different data source update Ofproperty Set propvalue= ' Org.jivesoftware.openfire.user.JDBCUserProvider ' where name= ' provider.user.className '; update Ofproperty set propvalue= ' Org.jivesoftware.openfire.auth.JDBCAuthProvider ' where name= ' provider.auth.className '; Commit





Only partial authentication and user management related configurations are used here, more configuration is required to view the source code to obtain

OpenFire using the Custom user table

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.