HI END


一种永不妥协,追求极致与完美的精神与态度。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

XMPP 之Openfire的用户数据库整合(转)

Posted on 2012-08-28 08:20  HI END  阅读(239)  评论(0编辑  收藏  举报

来源:http://bbs.chinaunix.net/thread-3630163-1-1.html

openfire\documentation下的文档有比较详细的信息

如果手动一步步设置

删除默认,
首先停止正常运行的Openfire服务器

默认的库ofProperty的如下记录删除

provider.auth.classname

provider.user.classname

provider.group.classname

建立一个第三方的表

  1. CREATE TABLE myUser (
  2. username NVARCHAR(64) NOT NULL,
  3. plainPassword NVARCHAR(32),
  4. encryptedPassword NVARCHAR(255),
  5. name NVARCHAR(100),
  6. email VARCHAR(100),
  7. creationDate CHAR(15) NOT NULL,
  8. modificationDate CHAR(15) NOT NULL,
  9. CONSTRAINT ofUser_pk PRIMARY KEY (username)
  10. );
  11. CREATE INDEX ofUser_cDate_idx ON myUser (creationDate ASC);
  12. CREATE TABLE myGroupUser (
  13. groupName NVARCHAR(50) NOT NULL,
  14. username NVARCHAR(100) NOT NULL,
  15. administrator INTEGER NOT NULL,
  16. CONSTRAINT ofGroupUser_pk PRIMARY KEY (groupName, username, administrator)
  17. );
  18. CREATE TABLE myGroup (
  19. groupName NVARCHAR(50) NOT NULL,
  20. description NVARCHAR(255),
  21. CONSTRAINT ofGroup_pk PRIMARY KEY (groupName)
  22. );
复制代码

密码加密方式:

plain md5 sha1 sha256 sha512

密码采用明文:

<passwordSQL>SELECT plainPassword FROM myUser WHERE username=?</passwordSQL>

<passwordType>palin</passwordType>

密码采用HASH:

<passwordSQL>SELECT encryptedPassword FROM myUser WHERE username=?</passwordSQL>

<passwordType>sha256</passwordType>

如下是一个myUser 中admin数据[myUser 插入admin/**数据,必须有一个,否则再次启动时使用这个验证时就没法登录] admin
admin
8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
admin
Admin@demo.com
2011-1-1      
2011-1-1      



配置文件
openfire.xml 加入如下内容

  1. <!-- Use Custome Database for user/group
  2.   openfire_src/documentation/docs :: db-integration-guide.html database.html database-guide.html
  3. -->
  4.   <jdbcProvider>
  5.     <!--
  6.     <driver>com.mysql.jdbc.Driver</driver>  
  7.     <connectionString>jdbc:mysql://localhost:3306/of?user=root&amp;password=</connectionString>
  8. -->
  9.     <![CDATA[ SQL SERVER驱动 jtds.sourceforge.net/faq.html ]]>
  10.     <driver>net.sourceforge.jtds.jdbc.Driver</driver>
  11.     <connectionString>jdbc:jtds:sqlserver://localhost/cust;appName=cust;user=of;password=of</connectionString>
  12.   </jdbcProvider>
  13.   <admin/>
  14.   <provider>
  15.     <auth>
  16.       <className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className>
  17.     </auth>
  18.     <user>
  19.       <className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
  20.     </user>
  21.     <group>
  22.       <className>org.jivesoftware.openfire.group.JDBCGroupProvider</className>
  23.     </group>
  24.   </provider>
  25.   <jdbcAuthProvider>
  26.     <passwordSQL>SELECT plainPassword FROM myUser WHERE username=?</passwordSQL>
  27.     <passwordType>palin</passwordType>
  28.   </jdbcAuthProvider>
  29.   <jdbcUserProvider>
  30.     <loadUserSQL>SELECT name,email FROM myUser WHERE username=?</loadUserSQL>
  31.     <userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
  32.     <allUsersSQL>SELECT username FROM myUser</allUsersSQL>
  33.     <searchSQL>SELECT username FROM myUser WHERE</searchSQL>
  34.     <usernameField>username</usernameField>
  35.     <nameField>name</nameField>
  36.     <emailField>email</emailField>
  37.   </jdbcUserProvider>
  38.   <jdbcGroupProvider>
  39.     <groupCountSQL>SELECT count(*) FROM myGroup</groupCountSQL>
  40.     <allGroupsSQL>SELECT groupName FROM myGroup</allGroupsSQL>
  41.     <descriptionSQL>SELECT groupDescription FROM myGroup WHERE groupName=?</descriptionSQL>
  42.     <userGroupsSQL>SELECT groupName FROM myGroupUser WHERE username=?</userGroupsSQL>
  43.     <loadMembersSQL>SELECT username FROM myGroupUser WHERE groupName=? AND isAdmin='N'</loadMembersSQL>
  44.     <loadAdminsSQL>SELECT username FROM myGroupUser WHERE groupName=? AND isAdmin='Y'</loadAdminsSQL>
  45.   </jdbcGroupProvider>
复制代码

启动
再次启动后,使用admin可以登录进去

默认的数据库的[ofProperty]内容从配置文件导入了,openfire.xml恢复原来的形式,查看ofProperty name
propValue

   
jdbcAuthProvider.passwordSQL
SELECT plainPassword FROM myUser WHERE username=?

jdbcAuthProvider.passwordType
plain

jdbcGroupProvider.allGroupsSQL
SELECT groupName FROM myGroup

jdbcGroupProvider.descriptionSQL
SELECT groupDescription FROM myGroup WHERE groupName=?

jdbcGroupProvider.groupCountSQL
SELECT count(*) FROM myGroup

jdbcGroupProvider.loadAdminsSQL
SELECT username FROM myGroupUser WHERE groupName=? AND isAdmin='Y'

jdbcGroupProvider.loadMembersSQL
SELECT username FROM myGroupUser WHERE groupName=? AND isAdmin='N'

jdbcGroupProvider.userGroupsSQL
SELECT groupName FROM myGroupUser WHERE username=?

jdbcProvider.connectionString
jdbc:jtds:sqlserver://localhost/cust;appName=cust;user=of;password=of

jdbcProvider.driver
net.sourceforge.jtds.jdbc.Driver

jdbcUserProvider.allUsersSQL
SELECT username FROM myUser

jdbcUserProvider.emailField
email

jdbcUserProvider.loadUserSQL
SELECT name,email FROM myUser WHERE username=?

jdbcUserProvider.nameField
name

jdbcUserProvider.searchSQL
SELECT username FROM myUser WHERE

jdbcUserProvider.userCountSQL
SELECT COUNT(*) FROM myUser

jdbcUserProvider.usernameField
username

provider.auth.className
org.jivesoftware.openfire.auth.JDBCAuthProvider

provider.group.className
org.jivesoftware.openfire.group.JDBCGroupProvider

provider.user.className
org.jivesoftware.openfire.user.JDBCUserProvider