共计 4434 个字符,预计需要花费 12 分钟才能阅读完成。
修改 openfire 的配置有两种途径:
1:修改安装目录 /conf/openfire.xml。
2:直接修改 openfire 数据库的 ofProperty 表。
但是一般都建议修改 openfire.xml 文件,该文件如果配置正确,openfire 重启后会自动将该文件里的属性值写入 ofProperty 表,同时会擦除自己添加的配置,只剩标签(除了默认配置)。如图:
对应 ofProperty 表配置:
官网提供的说明,自己在进行移植的时候有几点需要注意(以下都在 openfire.xml 里面配置)
1:官网提供的关于自己用户以及群所在的数据库配置:
<jive>
<jdbcProvider>
<driver>com.mysql.jdbc.Driver</driver>
<connectionString>jdbc:mysql://localhost/dbname?user=username&password=secret</connectionString>
</jdbcProvider>
</jive>
<jdbcProvider>
<driver>com.mysql.jdbc.Driver</driver>
<connectionString>jdbc:mysql://localhost/dbname?user=username&password=secret</connectionString>
</jdbcProvider>
</jive>
里面的用户名和密码之间要加入 & 不能忘记,同时配置成功后,在 ofProperty 表里面会还原成 &,不要在表里面修改为 &
2:官网提供的关于用户登陆的配置以及 admin 的配置:
<jive>
<admin>
<authorizedUsernames>joe, jane</authorizedUsernames>
</admin>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
</jive>
<admin>
<authorizedUsernames>joe, jane</authorizedUsernames>
</admin>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
</jive>
注意点:这个时候网页登陆的用户已经不再是 openfire 自带的 ofUser 表里面的用户,而是 user_account 表的用户,该表就是自己的用户表,这里注意一点:
不要在 select password 后面再添加字段。
3:官网提供的用户配置:
<jive>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
<user>
<className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
</user>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
<jdbcUserProvider>
<loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
<userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
<allUsersSQL>SELECT username FROM myUser</allUsersSQL>
<searchSQL>SELECT username FROM myUser WHERE</searchSQL>
<usernameField>username</usernameField>
<nameField>name</nameField>
<emailField>email</emailField>
</jdbcUserProvider>
</jive>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
<user>
<className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
</user>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
<jdbcUserProvider>
<loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
<userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
<allUsersSQL>SELECT username FROM myUser</allUsersSQL>
<searchSQL>SELECT username FROM myUser WHERE</searchSQL>
<usernameField>username</usernameField>
<nameField>name</nameField>
<emailField>email</emailField>
</jdbcUserProvider>
</jive>
注意点:select 后面的字段不要随意添加,比如 <loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
我测试的时候去掉 email,只查询 name,结果用户总是无法登陆网页,查看了 op 源码在 JDBCUserProvider 类里有下面这一段:
1 public User loadUser(String username) throws UserNotFoundException {
2 if(username.contains(“@“)) {
3 if (!XMPPServer.getInstance().isLocal(new JID(username))) {
4 thrownew UserNotFoundException(“Cannot load user of remote server: “+ username);
5 }
6 username = username.substring(0,username.lastIndexOf(“@“));
7 }
8 Connection con =null;
9 PreparedStatement pstmt =null;
10 ResultSet rs =null;
11 try {
12 con = getConnection();
13 pstmt = con.prepareStatement(loadUserSQL);
14 pstmt.setString(1, username);
15 rs = pstmt.executeQuery();
16 if (!rs.next()) {
17 thrownew UserNotFoundException();
18 }
19 String name = rs.getString(1);
20 String email = rs.getString(2);
21
22 returnnew User(username, name, email, new Date(), new Date());
23 }
24 catch (Exception e) {
25 thrownew UserNotFoundException(e);
26 }
27 finally {
28 DbConnectionManager.closeConnection(rs, pstmt, con);
29 }
30 }
2 if(username.contains(“@“)) {
3 if (!XMPPServer.getInstance().isLocal(new JID(username))) {
4 thrownew UserNotFoundException(“Cannot load user of remote server: “+ username);
5 }
6 username = username.substring(0,username.lastIndexOf(“@“));
7 }
8 Connection con =null;
9 PreparedStatement pstmt =null;
10 ResultSet rs =null;
11 try {
12 con = getConnection();
13 pstmt = con.prepareStatement(loadUserSQL);
14 pstmt.setString(1, username);
15 rs = pstmt.executeQuery();
16 if (!rs.next()) {
17 thrownew UserNotFoundException();
18 }
19 String name = rs.getString(1);
20 String email = rs.getString(2);
21
22 returnnew User(username, name, email, new Date(), new Date());
23 }
24 catch (Exception e) {
25 thrownew UserNotFoundException(e);
26 }
27 finally {
28 DbConnectionManager.closeConnection(rs, pstmt, con);
29 }
30 }
代码走到 20 行的时候报错,因为查询 sql 不包括 email,结果集里面并无 email 字段,所以 rs.getString(2)的时候出错了。
所以根据经验不要轻易增减 select 后面的字段,如果没有 select 后面的字段,只有两种办法一个是修改 op 源码,一个是修改自己的业务表,增加 op 查询时候需要的字段。
4:官网提供的单用户以及群组配置:
<jive>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
<user>
<className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
</user>
<group>
<className>org.jivesoftware.openfire.group.JDBCGroupProvider</className>
</group>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
<jdbcUserProvider>
<loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
<userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
<allUsersSQL>SELECT username FROM myUser</allUsersSQL>
<searchSQL>SELECT username FROM myUser WHERE</searchSQL>
<usernameField>username</usernameField>
<nameField>name</nameField>
<emailField>email</emailField>
</jdbcUserProvider>
<jdbcGroupProvider>
<groupCountSQL>SELECT count(*) FROM myGroups</groupCountSQL>
<allGroupsSQL>SELECT groupName FROM myGroups</allGroupsSQL>
<userGroupsSQL>SELECT groupName FROM myGroupUsers WHERE username=?</userGroupsSQL>
<descriptionSQL>SELECT groupDescription FROM myGroups WHERE groupName=?</descriptionSQL>
<loadMembersSQL>SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin=‘N‘</loadMembersSQL>
<loadAdminsSQL>SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin=‘Y‘</loadAdminsSQL>
</jdbcGroupProvider>
</jive>
<provider>
<auth>
<className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
</auth>
<user>
<className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
</user>
<group>
<className>org.jivesoftware.openfire.group.JDBCGroupProvider</className>
</group>
</provider>
<jdbcAuthProvider>
<passwordSQL>SELECT password FROM user_account WHERE username=?</passwordSQL>
<passwordType>plain</passwordType>
</jdbcAuthProvider>
<jdbcUserProvider>
<loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
<userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
<allUsersSQL>SELECT username FROM myUser</allUsersSQL>
<searchSQL>SELECT username FROM myUser WHERE</searchSQL>
<usernameField>username</usernameField>
<nameField>name</nameField>
<emailField>email</emailField>
</jdbcUserProvider>
<jdbcGroupProvider>
<groupCountSQL>SELECT count(*) FROM myGroups</groupCountSQL>
<allGroupsSQL>SELECT groupName FROM myGroups</allGroupsSQL>
<userGroupsSQL>SELECT groupName FROM myGroupUsers WHERE username=?</userGroupsSQL>
<descriptionSQL>SELECT groupDescription FROM myGroups WHERE groupName=?</descriptionSQL>
<loadMembersSQL>SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin=‘N‘</loadMembersSQL>
<loadAdminsSQL>SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin=‘Y‘</loadAdminsSQL>
</jdbcGroupProvider>
</jive>
注意点:不要轻易增删 select 后面的字段,根据自己的业务表进行修改即可。sql 不要写错,否则就无法显示出自己的用户以及群组。
当出现不明错误的时候,进入 logs 目录查看 error.log 进行调整测试。
Openfire 的详细介绍:请点这里
Openfire 的下载地址:请点这里
相关阅读:
CentOS 下 Openfire 详细安装过程 http://www.linuxidc.com/Linux/2012-09/69539.htm
CentOS 5.4 下基于 Jabber/XMPP 协议的 Openfire 服务器配置笔记 http://www.linuxidc.com/Linux/2012-02/55497.htm
Ubuntu 12.04 安装 Openfire http://www.linuxidc.com/Linux/2012-07/64945.htm
正文完
星哥玩云-微信公众号