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.
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.
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?
- --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 ');
- Insert into Ofproperty (NAME, PropValue)
- Values (' Jdbcuserprovider.emailfield ', ' email ');
- Insert into Ofproperty (NAME, PropValue)
- Values (' jdbcuserprovider.usercountsql ', 'select Count(*) from
- T_sys_user t ');
- 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;
--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