openfire 开源即时消息扩展篇之自定义数据源

       本文档提供了指示为集成Openfire身份验证、用户和组与您的自定义数据库表。这是有用,当您的用户已经有账户在一个外部系统,你不希望重复这些账户在Openfire。简单的集成与定制数据库允许用户身份验证使用他们现有的用户名和密码。您可以加载用户配置文件配置Openfire和组信息从您的自定义数据库。具体的步骤如下:

1:数据源配置

 你需要指定数据源连接驱动和连接url.需要写在openfire/src/conf/openfire.xml

<jive>
  ...
  <jdbcProvider>
    <driver>com.mysql.jdbc.Driver</driver>
    <connectionString>jdbc:mysql://localhost/dbname?user=username&amp;password=secret</connectionString>
  </jdbcProvider>
  ...
</jive>
2:认证集成

 你需要指定认证类,openfire提供了org.jivesoftware.openfire.auth.JDBCAuthProvider类

<jive>
  ...
  <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>
其中jdbcAuthProvider.passwordType 支持以下类型:
  1. plain
  2. md5
  3. sha1
  4. sha256
  5. sha512
3:用户信息整合

 你需要指定用户信息加载类,openfire提供了org.jivesoftware.openfire.user.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>

 

4:用户组信息整合

 你需要指定用户信息加载类,openfire提供了 org.jivesoftware.openfire.group.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>
5:备注:

在openfire/src/conf/openfire.xml文件中配置好后,需要重置设置openfire安装步骤。在设置安装步骤之前,需要对安装值进行更改,打开文件openfire/src/web/setup/setup-profile-settings.jsp找到:

       if ("default".equals(mode)) {
            // Set to default providers by deleting any existing values.
            @SuppressWarnings("unchecked")
            Map<String,String> xmppSettings = (Map<String,String>)session.getAttribute("xmppSettings");
            xmppSettings.put("provider.auth.className",org.jivesoftware.openfire.auth.DefaultAuthProvider.class.getName());
            xmppSettings.put("provider.user.className",org.jivesoftware.openfire.user.DefaultUserProvider.class.getName());
            xmppSettings.put("provider.group.className", org.jivesoftware.openfire.group.DefaultGroupProvider.class.getName());
            xmppSettings.put("provider.vcard.className", org.jivesoftware.openfire.vcard.DefaultVCardProvider.class.getName());
            xmppSettings.put("provider.lockout.className", org.jivesoftware.openfire.lockout.DefaultLockOutProvider.class.getName());
            xmppSettings.put("provider.securityAudit.className", org.jivesoftware.openfire.security.DefaultSecurityAuditProvider.class.getName());
            xmppSettings.put("provider.admin.className", org.jivesoftware.openfire.admin.DefaultAdminProvider.class.getName());
            // Redirect
            response.sendRedirect("setup-admin-settings.jsp");
            return;
        }
把相应的:provider.auth.className,provider.user.className,provider.group.className三个属性更改为上面你配置的相应类。然后重新开启openfire进行登录http://localhost:9090/跳转到设置。设置成功后,就OK了

你可能感兴趣的:(spark,openfire,openfire,database,integration,XMPP,IM)