修改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>
代码语言:javascript复制里面的用户名和密码之间要加入&不能忘记,同时配置成功后,在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>
代码语言:javascript复制注意点:这个时候网页登陆的用户已经不再是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>
代码语言:javascript复制注意点: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 }
代码语言:javascript复制代码走到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>
代码语言:javascript复制注意点:不要轻易增删select后面的字段,根据自己的业务表进行修改即可。sql不要写错,否则就无法显示出自己的用户以及群组。
当出现不明错误的时候,进入logs目录查看error.log进行调整测试。