openfire 使用已有的数据库作为用户认证数据库 Custom Database Integration Guide「建议收藏」

openfire 使用已有的数据库作为用户认证数据库 Custom Database Integration Guide

大家好,又见面了,我是全栈君。

http://download.igniterealtime.org/openfire/docs/latest/documentation/db-integration-guide.html

 

Introduction

This document provides instructions for integrating Openfire authentication, users, and groups with your custom database tables. This is useful when your users already have accounts in an external system and you do not wish to duplicate those accounts in Openfire. If your user information is available via an LDAP directory rather than custom database tables, see the LDAP guide.

Simple integration with a custom database lets users authenticate using their existing username and password. Optionally, you can configure Openfire to load user profile and group information from your custom database. Any group in Openfire can be designated as a shared group, which means that you can pre-populate user’s rosters using groups.

Background

The integration requires that you enter customized database queries to access your database. You’ll need to be familiar with your database table structure and simple SQL. Your custom database can be a different database on a different server from the Openfire database — you’ll enter database connection information as part of the configuration.

Configuration

In order to configure your server to integrate with your custom database tables:

  1. Stop Openfire.
  2. Edit conf/openfire.xml in your Openfire installation folder as described below using your favorite editor.
  3. Restart Openfire.

Database Connection Settings

You must specify the connection string for your database as well as the JDBC driver.

  • jdbcProvider.driver — the class name of the JDBC driver used to connect to your custom database. The driver must also be in the Openfire classpath (for example, by placing it into the “lib/” directory of your Openfire installation. See the database guide for common driver names for major databases.
  • jdbcProvider.connectionString — the full connection string for the database. Please consult your database driver documentation for syntax. Warning: it’s common for connection string to contain “&” characters. That character has special meaning in XML, so you should escape it using “&”.

Below is a sample config file section (note: the “…” sections in the examples indicate areas where the rest of the config file would exist):

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

Authentication Integration

The simplest possible integration with a custom external database is authentication integration. Use the following settings to enable authentication integration.

  • provider.auth.className — set the value to org.jivesoftware.openfire.auth.JDBCAuthProvider.
  • jdbcAuthProvider.passwordSQL — the SQL String to select a user’s password. The SQL statement should contain a single “?” character, which will be dynamically replaced with a username when being executed.
  • jdbcAuthProvider.passwordType — the type of the password. Valid values are
    • “plain” (the password is stored as plain text)
    • “md5” (the password is stored as a hex-encoded MD5 hash)
    • “sha1” (the password is stored as a hex-encoded SHA-1 hash)
    • “sha256” (the password is stored as a hex-encoded SHA-256 hash)
    • “sha512” (the password is stored as a hex-encoded SHA-512 hash)

    If this value is not set, the password type is assumed to be plain.

Below is a sample config file section:

<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>

You’ll most likely want to change which usernames are authorized to login to the admin console. By default, only the user with username “admin” is allowed to login. However, you may have different users in your LDAP directory that you’d like to be administrators. The list of authorized usernames is controlled via the admin.authorizedUsernames property. For example, to let the usersnames “joe” and “jane” login to the admin console:

    <jive>
      ...
      <admin>
        ...
        <authorizedUsernames>joe, jane</authorizedUsernames>
      </admin>

      ...
    </jive>

Another option is to use an AdminProvider. AdminProvider instances are responsible for listing the administrators users dynamically. The default use the authorizedUsernames setting previously explained. JDBCAdminProvider allows to list the administrators from a SQL query. For example:

<jive>
  ...
  <provider>
    ...
    <admin>
      <className>org.jivesoftware.openfire.admin.JDBCAdminProvider</className>
    </admin>
    ...
  </provider>
  <jdbcAdminProvider>
    <getAdminsSQL>SELECT userid FROM user_account WHERE administrator='Y'</getAdminsSQL>
  </jdbcAdminProvider>
  ...
</jive>

User Integration

Optionally, Openfire can load user data from your custom database. If you enable user integration you must also enable authentication integration (see above). Use the following settings to enable user integration.

  • provider.user.className — set the value to org.jivesoftware.openfire.user.JDBCUserProvider.
  • jdbcUserProvider.loadUserSQL — the SQL statement to load the name and email address of a user (in that order) given a username. The SQL statement should contain a single “?” character, which will be dynamically replaced with a username when being executed.
  • jdbcUserProvider.userCountSQL — the SQL statement to load the total number of users in the database.
  • jdbcUserProvider.allUsersSQL — the SQL statement to load all usernames in the database.
  • jdbcUserProvider.searchSQL — the SQL statement fragment used to search your database for users. the statement should end with “WHERE” — the username, name, and email fields will then be dynamically appended to the statement depending on the search. If this value is not set, searching will not be enabled.
  • usernameField — the name of the username database field, which will be used for searches.
  • nameField — the name of the name database field, which will be used for searches.
  • emailField — the name of the email database field, which will be used for searches.

Below is a sample config file section. Note that the single provider section must include all providers that should be configured:

<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>

Group Integration

Openfire can load group data from your custom database. If you enable group integration you must also enable authentication integration; you’ll also likely want to enable user integration (see above). Use the following settings to enable group integration.

  • provider.group.className — set the value to org.jivesoftware.openfire.group.JDBCGroupProvider.
  • jdbcGroupProvider.groupCountSQL — the SQL statement to load the total number of groups in the database.
  • jdbcGroupProvider.allGroupsSQL — the SQL statement to load all groups in the database.
  • jdbcGroupProvider.userGroupsSQL — the SQL statement to load all groups for a particular user. The SQL statement should contain a single “?” character, which will be dynamically replaced with a username when being executed.
  • jdbcGroupProvider.descriptionSQL — the SQL statement to load the description of a group. The SQL statement should contain a single “?” character, which will be dynamically replaced with a group name when being executed.
  • jdbcGroupProvider.loadMembersSQL — the SQL statement to load all members in a group. The SQL statement should contain a single “?” character, which will be dynamically replaced with a group name when being executed.
  • jdbcGroupProvider.loadAdminsSQL — the SQL statement to load all administrators in a group. The SQL statement should contain a single “?” character, which will be dynamically replaced with a group name when being executed.

Below is a sample config file section. Note that the single provider section must include all providers that should be configured:

<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>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108466.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ST7789V+初始化代码调

    MyfirstblogonCSDN本文简单写一下本次调屏经过遇到的问题和解决方法,主要是怕以后遇到同样问题的时候又忘记了~1、屏分辨率是240×320,接口是16bitparalledatabusfor8080seriescpu,就是16位并口再加WR,RD,CS,RS接口,屏的复位可以采用RC上电复位电路。2、cpu这边输出的信号是320×240的,这里没写错,输

    2022年4月16日
    212
  • mongodb与mysql区别对比

    mongodb与mysql区别对比参考来源mongodb与关系型数据库相比的优缺点与关系型数据库相比,MongoDB的优点:①弱一致性(最终一致),更能保证用户的访问速度:举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的较精确值。这在某些情况下,例如通过ATM查看账户信息的时候很重要,但对于Wordnik来说,数据是不断更新和增长的,这种“较精确”的保证几乎没有任何…

    2022年6月22日
    62
  • 基于MeanShift的目标跟踪算法及实现

    基于MeanShift的目标跟踪算法及实现这次将介绍基于MeanShift的目标跟踪算法,首先谈谈简介,然后给出算法实现流程,最后实现了一个单目标跟踪的MeanShift算法【matlab/c两个版本】 一、简介    首先扯扯无参密度估计理论,无参密度估计也叫做非参数估计,属于数理统计的一个分支,和参数密度估计共同构成了概率密度估计方法。参数密度估计方法要求特征空间服从一个已知的概率密度函数,在实际的应用中这个条件很难达到

    2022年7月26日
    3
  • plsql 查询到别的用户下面的表

    plsql 查询到别的用户下面的表

    2021年9月1日
    48
  • XGBoost的基本原理

    XGBoost的基本原理XGBoost原理与实践

    2022年5月30日
    36
  • system.out.println()里面_println的意思

    system.out.println()里面_println的意思1.第一次见到该表达式的感受&amp;nbsp;&amp;nbsp;第一此次见到该表达式的时候,我还不知道什么是方法引用,当时真是一脸蒙圈,然后问了好多同事,给我的解释也是五花八门,但我还是感觉莫名其妙,有段时间想着就当一个特例记住就好了,不要再去深究了!!!但是我这个人,在这种时候就是很难说服自己,于是有了上篇文章,再回过头来看这个问题,其实就变得非常简单了。2.揭开System.out::print…

    2022年10月2日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号