Openfire 提供了一套 JDBC的用户整合方案,使用这个方案可以整合现有系统用户信息;
所有的配置信息都可以Openfire的控制台完成配置,不过作为屌丝程序员,还是习惯了直接通过sql修改配置的方式完成;
修改的配置信息如下:
delete from ofProperty; Insert into ofProperty (name,propValue) values ('adminConsole.port','9090'); Insert into ofProperty (name,propValue) values ('adminConsole.securePort','9091'); Insert into ofProperty (name,propValue) values ('connectionProvider.className','org.jivesoftware.database.DefaultConnectionProvider'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.connectionTimeout','1.0'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.driver','com.mysql.jdbc.Driver'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.maxConnections','25'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.minConnections','5'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.password','cb0f3ccb874f50cbc9967bb547ba7911458731ad8aaa06b3'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.serverURL','jdbc:mysql://10.1.19.244:3306/openfire5?rewriteBatchedStatements=true'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.testAfterUse','false'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.testBeforeUse','false'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.testSQL','select 1'); Insert into ofProperty (name,propValue) values ('database.defaultProvider.username','b5f168b82d709ae7dc49db3df43857b75f5b577c4a446fbb6813eb2da8e1de37'); Insert into ofProperty (name,propValue) values ('locale','en'); Insert into ofProperty (name,propValue) values ('passwordKey','2H98aR1Mr4Bvs4y'); Insert into ofProperty (name,propValue) values ('provider.admin.className','org.jivesoftware.openfire.admin.DefaultAdminProvider'); Insert into ofProperty (name,propValue) values ('provider.lockout.className','org.jivesoftware.openfire.lockout.DefaultLockOutProvider'); Insert into ofProperty (name,propValue) values ('provider.securityAudit.className','org.jivesoftware.openfire.security.DefaultSecurityAuditProvider'); Insert into ofProperty (name,propValue) values ('provider.vcard.className','org.jivesoftware.openfire.vcard.DefaultVCardProvider'); Insert into ofProperty (name,propValue) values ('setup','true'); Insert into ofProperty (name,propValue) values ('update.lastCheck','1450424871909'); Insert into ofProperty (name,propValue) values ('xmpp.auth.anonymous','true'); Insert into ofProperty (name,propValue) values ('xmpp.domain','openfire03'); Insert into ofProperty (name,propValue) values ('xmpp.session.conflict-limit','0'); Insert into ofProperty (name,propValue) values ('xmpp.socket.ssl.active','true'); --整合用户系统使用 --查询密码 Insert into ofProperty (name,propValue) values ('jdbcAuthProvider.passwordSQL','select pwd from bs_mbopt where userid=?'); --密码加密方式 Insert into ofProperty (name,propValue) values ('jdbcAuthProvider.passwordType','md5 '); --数据库连接字符串 Insert into ofProperty (name,propValue) values ('jdbcProvider.connectionString','jdbc:oracle:thin:@10.67.2.6:1521/dzsw'); --数据库驱动 Insert into ofProperty (name,propValue) values ('jdbcProvider.driver','oracle.jdbc.driver.OracleDriver'); --所有用户 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.allUsersSQL','select userid from bs_mbopt'); --email字段 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.emailField','email'); --查询用户信息 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.loadUserSQL','select username,email from bs_mbopt where userid=?'); --用户名字段 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.nameField','username'); --检索使用 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.searchSQL','select userid from bs_mbopt where '); --统计用户数量 Insert into ofProperty (name,propValue) values ('jdbcUserProvider.userCountSQL','select count(1) from bs_mbopt'); --用户id Insert into ofProperty (name,propValue) values ('jdbcUserProvider.usernameField','userid'); --密码认证 Insert into ofProperty (name,propValue) values ('provider.auth.className','com.jl.openfire.plugin.usermanager.JDBCAuthProvider'); --用户分组使用 Insert into ofProperty (name,propValue) values ('provider.group.className','com.jl.openfire.plugin.usermanager.JDBCGroupProvider'); --用户信息查询 Insert into ofProperty (name,propValue) values ('provider.user.className','com.jl.openfire.plugin.usermanager.JDBCUserProvider'); -- 自定义字段,用户来保存jdbc用户名及密码 Insert into ofProperty (name,propValue) values ('jdbcAuthProvider.jdbcPassword','fsbsdb_1'); Insert into ofProperty (name,propValue) values ('jdbcAuthProvider.jdbcUserName','fsbsdb_1'); -- 所有分组信息 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.allGroupsSQL','select nkname from bs_menber'); -- 分组描述信息 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.descriptionSQL','select Mbname from bs_menber where nkname=?'); -- 所有分组 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.groupCountSQL','select count(1) from bs_menber'); --根据分组查询管理员 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.loadAdminsSQL','select opt.userid from bs_mbopt opt inner join bs_menber mb on opt.hydm = mb.hydm where mb.nkname=? and opt.isadmin = 0'); --查询分组下的所有成员 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.loadMembersSQL','select opt.userid from bs_mbopt opt inner join bs_menber mb on opt.hydm = mb.hydm where mb.nkname=? and opt.isadmin = 1'); --查询某个成员归属的分组名称 Insert into ofProperty (name,propValue) values ('jdbcGroupProvider.userGroupsSQL','select mb.nkname from bs_mbopt opt inner join bs_menber mb on opt.hydm = mb.hydm where opt.userid=?');
修改管理员
Insert into ofProperty (name,propValue) values ('admin.authorizedJIDs','guochen@domain');
完成以上配置后发现一个很严重的问题,登录没有成功过!
比较之后发现,现有系统中的密码加密方式是MD5,而且md5加密时给了几个种子;看了一下Openfire的源码(org.jivesoftware.openfire.auth.JDBCAuthProvider), 没有发现可以通过配置实现这样验证的方式。。。没办法,自己实现一个JDBCAuthProvider,Openfire不建议修改源码,提倡使用插件方式来实现自定义业务需求,所以我也是通过插件来实现的; 将开发完成的jar 包含:JDBCAuthProvider、 JDBCUserProvider、JDBCGroupProvider上传到openfire服务器中;
重启服务,通过Spark登录成功!