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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • FAST_ICA MTALAB工具包下载/ICA分析/独立成分分析MATLAB安装包/ICA toolbox

    FAST_ICA MTALAB工具包下载/ICA分析/独立成分分析MATLAB安装包/ICA toolbox很多小伙伴在后台问我,MATLAB怎么进行独立成分分析(ICA)。一般来讲,ICA操作可以说是EEG里面十分总要的操作。EEGLAB这方面做的非常好,只需要RunICA就能很快的进行EEG的分析,但同样也有其弊端(懂得都懂)。这里,我提供了matlab中FAST_ICA的安装包,由于年代较较远,因此,支持的MATLAB版本可能比较老。而且网址必须外网连接,如果有直接想要安装包的小伙伴可直接关注我的公众号,回复FAST_ICA,便可免费领取。打个小广告,粉爷公众号大厂面经,刷题指南,脑…

    2022年5月13日
    40
  • C语言assert函数(isspace函数)

    断言assert函数,C语言assert函数完全攻略对于断言,相信大家都不陌生,大多数编程语言也都有断言这一特性。简单地讲,断言就是对某种假设条件进行检查。在C语言中,断言被定义为宏的形式(assert(expression)),而不是函数,其原型定义在&lt;assert.h&gt;文件中。其中,assert将通过检查表达式expression的值来决定是否需要终止执行程序。也就是…

    2022年4月12日
    49
  • nginx反向代理服务contextpath的问题解决

    nginx反向代理服务contextpath的问题解决文章目录问题描述解决方案 sub filter 方案使用重定向单独域名访问问题描述现在的企业服务 往往不是单体的 同时可能涉及中间件的访问如 dubbo solr mq 等 对于中间件的监控页面访问 如果直接暴露在公网 肯定这安全 需发对中间件访问进行安全加固 方法主要有 1 限制使用 IP 白名单访问 2 安全密码访问 不使用简单密码 对于没有密码的 可以使用 basic 认证 强密码访问 3

    2025年7月11日
    3
  • 【目标检测】RCNN算法详解[通俗易懂]

    【目标检测】RCNN算法详解[通俗易懂]深度学习用于目标检测的RCNN算法

    2022年10月13日
    3
  • java高级工程师面试题_java高级工程师面试题及答案解析「建议收藏」

    java高级工程师面试题_java高级工程师面试题及答案解析「建议收藏」面试永远是程序员迈向成功的第一个门槛,想要面试成功,各种面试题的洗礼是必不可少的,下面就来看看小编精心整理的一些java高级工程师面试题及答案吧。一、堆的年轻代和老年代怎么理解?堆的年轻代大则老年代小,GC少,但是每次时间会比较长。年轻代小则老年代大,会缩短每次GC的时间,但是次数频繁。可以让老年代尽量缓存常用对象,JVM默认年轻代和老年代的大小比例为1:2,。观察峰值老年代内存,不影响fullG…

    2022年6月13日
    40
  • 用matlab绘制线性分段函数图像[通俗易懂]

    用matlab绘制线性分段函数图像[通俗易懂]假设线性分段函数如下所示在matlab中建立m文件:输入以下代码:x=0:0.01:5;y=zeros(size(x));fori=1:length(x)ifx(i)<0.9y(i)=0;elseifx(i)>=0.9&&x(i)<4.34y(i)=29.0698.*x(i)-26.1628;elsey(i)=100;endend

    2022年5月20日
    55

发表回复

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

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