db-integration-guide.html 12 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
5
<title>Openfire: Custom Database Integration Guide</title>
Matt Tucker's avatar
Matt Tucker committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>

<div id="pageContainer">

<a name="top"></a>

	<div id="pageHeader">
		<div id="logo"></div>
		<h1>Custom Database Integration Guide</h1>
	</div>
	<div class="navigation">
		<a href="index.html">&laquo; Back to documentation index</a>
	</div>

	<div id="pageBody">

<h2>Introduction</h2>

<p>
27
    This document provides instructions for integrating Openfire authentication, users, and
Matt Tucker's avatar
Matt Tucker committed
28
    groups with your custom database tables. This is useful when your users already have
29
    accounts in an external system and you do not wish to duplicate those accounts in Openfire.
Matt Tucker's avatar
Matt Tucker committed
30 31 32 33 34
    If your user information is available via an LDAP directory rather than custom database
    tables, see the <a href="ldap-guide.html">LDAP guide</a>.
</p>
<p>
    Simple integration with a custom database lets users authenticate using their existing
35 36
    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
Matt Tucker's avatar
Matt Tucker committed
37 38 39 40 41 42 43 44
    as a shared group, which means that you can pre-populate user's rosters using groups.
</p>

<h2>Background</h2>

<p>
    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.
45
    Your custom database can be a different database on a different server from the Openfire
Matt Tucker's avatar
Matt Tucker committed
46 47 48 49 50 51 52 53
    database -- you'll enter database connection information as part of the configuration.
</p>

<h2>Configuration</h2>

<p>
    In order to configure your server to integrate with your custom database tables:
    <ol>
54 55
        <li>Stop Openfire.</li>
        <li>Edit <tt>conf/openfire.xml</tt> in your Openfire installation folder as
Matt Tucker's avatar
Matt Tucker committed
56 57
            described below using your favorite editor.
        </li>
58
        <li>Restart Openfire.</li>
Matt Tucker's avatar
Matt Tucker committed
59 60 61 62 63 64 65 66 67 68 69
    </ol>

</p>

<h3>Database Connection Settings</h3>

<p>
    You must specify the connection string for your database as well as the JDBC driver.
</p>
<ul>
    <li>jdbcProvider.driver -- the class name of the JDBC driver used to connect to your
70 71
        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
Matt Tucker's avatar
Matt Tucker committed
72 73 74
        <a href="database.html">database guide</a> for common driver names for major databases.
    </li>
    <li>jdbcProvider.connectionString -- the full connection string for the database. Please
75 76 77 78
        consult your database driver documentation for syntax. <b>Warning:</b> it's common
        for connection string to contain "&" characters. That character has special meaning
        in XML, so you should escape it using "&amp;amp;".
    </li>
Matt Tucker's avatar
Matt Tucker committed
79 80 81
</ul>

<p>
Matt Tucker's avatar
Matt Tucker committed
82 83
    Below is a sample config file section (note: the "..." sections in the examples indicate areas
    where the rest of the config file would exist):
Matt Tucker's avatar
Matt Tucker committed
84 85 86 87 88 89
</p>
<pre>
&lt;jive&gt;
  ...
  &lt;jdbcProvider&gt;
    &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
90 91
    &lt;connectionString&gt;jdbc:mysql://localhost/dbname?user=username&amp;amp;password=secret&lt;/connectionString&gt;
  &lt;/jdbcProvider&gt;
Matt Tucker's avatar
Matt Tucker committed
92 93 94 95 96 97 98 99 100 101 102 103
  ...
&lt;/jive&gt;
</pre>

<h3>Authentication Integration</h3>

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

<ul>
104
    <li>provider.auth.className -- set the value to <tt>org.jivesoftware.openfire.auth.JDBCAuthProvider</tt>.</li>
Matt Tucker's avatar
Matt Tucker committed
105 106 107
    <li>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.</li>
108 109 110 111 112 113
    <li>jdbcAuthProvider.passwordType -- the type of the password. Valid values are <ul><li>"plain" (the password is stored as plain text)</li>
	 <li>"md5" (the password is stored as a hex-encoded MD5 hash)</li>
    <li>"sha1" (the password is stored as a hex-encoded SHA-1 hash)</li>
    <li>"sha256" (the password is stored as a hex-encoded SHA-256 hash)</li>
    <li>"sha512" (the password is stored as a hex-encoded SHA-512 hash)</li></ul>
	 If this value is not set, the password type is assumed to be plain.</li>
Matt Tucker's avatar
Matt Tucker committed
114 115 116 117 118 119 120 121 122 123
</ul>

<p>
    Below is a sample config file section:
</p>
<pre>
&lt;jive&gt;
  ...
  &lt;provider&gt;
    &lt;auth&gt;
124
      &lt;className&gt;org.jivesoftware.openfire.auth.JDBCAuthProvider&lt;/className&gt;
Matt Tucker's avatar
Matt Tucker committed
125 126 127
    &lt;/auth&gt;
  &lt;/provider&gt;
  &lt;jdbcAuthProvider&gt;
Matt Tucker's avatar
Matt Tucker committed
128 129
     &lt;passwordSQL&gt;SELECT password FROM user_account WHERE username=?&lt;/passwordSQL&gt;
     &lt;passwordType&gt;plain&lt;/passwordType&gt;
Matt Tucker's avatar
Matt Tucker committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
   &lt;/jdbcAuthProvider&gt;
   ...
  &lt;/jive&gt;
</pre>

<p>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 <tt>admin.authorizedUsernames</tt>
    property. For example, to let the usersnames "joe" and "jane" login to the admin console:</p>

<pre>
    &lt;jive&gt;
      ...
      &lt;admin&gt;
        ...
        &lt;authorizedUsernames&gt;joe, jane&lt;/authorizedUsernames&gt;
      &lt;/admin&gt;

      ...
    &lt;/jive&gt;
</pre>

<h3>User Integration</h3>

155
<p>Optionally, Openfire can load user data from your custom database. If you enable user integration
Matt Tucker's avatar
Matt Tucker committed
156 157 158 159
you must also enable authentication integration (see above). Use the following settings to
enable user integration.</p>

<ul>
160
    <li>provider.user.className -- set the value to <tt>org.jivesoftware.openfire.user.JDBCUserProvider</tt>.</li>
Matt Tucker's avatar
Matt Tucker committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    <li>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.</li>
    <li>jdbcUserProvider.userCountSQL -- the SQL statement to load the total number of users in the database.</li>
    <li>jdbcUserProvider.allUsersSQL -- the SQL statement to load all usernames in the database.</li>
    <li>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.</li>
    <li>usernameField -- the name of the username database field, which will be used for searches.</li>
    <li>nameField -- the name of the name database field, which will be used for searches.</li>
    <li>emailField -- the name of the email database field, which will be used for searches.</li>
</ul>

<p>
176 177
    Below is a sample config file section. Note that the single provider section must include
    all providers that should be configured:
Matt Tucker's avatar
Matt Tucker committed
178 179 180 181 182
</p>
<pre>
&lt;jive&gt;
  ...
  &lt;provider&gt;
183
    &lt;auth&gt;
184
      &lt;className&gt;org.jivesoftware.openfire.auth.JDBCAuthProvider&lt;/className&gt;
185
    &lt;/auth&gt;
Matt Tucker's avatar
Matt Tucker committed
186
    &lt;user&gt;
187
      &lt;className&gt;org.jivesoftware.openfire.user.JDBCUserProvider&lt;/className&gt;
Matt Tucker's avatar
Matt Tucker committed
188 189
    &lt;/user&gt;
  &lt;/provider&gt;
Matt Tucker's avatar
Matt Tucker committed
190 191 192 193
  &lt;jdbcAuthProvider&gt;
     &lt;passwordSQL&gt;SELECT password FROM user_account WHERE username=?&lt;/passwordSQL&gt;
     &lt;passwordType&gt;plain&lt;/passwordType&gt;
  &lt;/jdbcAuthProvider&gt;
Matt Tucker's avatar
Matt Tucker committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  &lt;jdbcUserProvider&gt;
     &lt;loadUserSQL&gt;SELECT name,email FROM myUser WHERE username=?&lt;/loadUserSQL&gt;
     &lt;userCountSQL&gt;SELECT COUNT(*) FROM myUser&lt;/userCountSQL&gt;
     &lt;allUsersSQL&gt;SELECT username FROM myUser&lt;/allUsersSQL&gt;
     &lt;searchSQL&gt;SELECT username FROM myUser WHERE&lt;/searchSQL&gt;
     &lt;usernameField&gt;username&lt;/usernameField&gt;
     &lt;nameField&gt;name&lt;/nameField&gt;
     &lt;emailField&gt;email&lt;/emailField&gt;
  &lt;/jdbcUserProvider&gt;
   ...
 &lt;/jive&gt;
</pre>

<h3>Group Integration</h3>

209
<p>Openfire can load group data from your custom database. If you enable group integration
Matt Tucker's avatar
Matt Tucker committed
210 211 212 213
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.</p>

<ul>
214
    <li>provider.group.className -- set the value to <tt>org.jivesoftware.openfire.group.JDBCGroupProvider</tt>.</li>
Matt Tucker's avatar
Matt Tucker committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    <li>jdbcGroupProvider.groupCountSQL -- the SQL statement to load the total number of groups in
        the database.</li>
    <li>jdbcGroupProvider.allGroupsSQL -- the SQL statement to load all groups in the database.</li>
    <li>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.</li>
    <li>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.</li>
    <li>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.</li>
    <li>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.</li>
</ul>

<p>
233 234
    Below is a sample config file section. Note that the single provider section must include
    all providers that should be configured:
Matt Tucker's avatar
Matt Tucker committed
235 236 237 238 239
</p>
<pre>
&lt;jive&gt;
  ...
  &lt;provider&gt;
240
    &lt;auth&gt;
241
      &lt;className&gt;org.jivesoftware.openfire.auth.JDBCAuthProvider&lt;/className&gt;
242 243
    &lt;/auth&gt;
    &lt;user&gt;
244
      &lt;className&gt;org.jivesoftware.openfire.user.JDBCUserProvider&lt;/className&gt;
245 246
    &lt;/user&gt;
    &lt;group&gt;
247
      &lt;className&gt;org.jivesoftware.openfire.group.JDBCGroupProvider&lt;/className&gt;
Matt Tucker's avatar
Matt Tucker committed
248
    &lt;/group&gt;
Matt Tucker's avatar
Matt Tucker committed
249
  &lt;/provider&gt;
Matt Tucker's avatar
Matt Tucker committed
250 251 252 253 254 255 256 257 258 259 260 261 262
  &lt;jdbcAuthProvider&gt;
     &lt;passwordSQL&gt;SELECT password FROM user_account WHERE username=?&lt;/passwordSQL&gt;
     &lt;passwordType&gt;plain&lt;/passwordType&gt;
  &lt;/jdbcAuthProvider&gt;
  &lt;jdbcUserProvider&gt;
     &lt;loadUserSQL&gt;SELECT name,email FROM myUser WHERE username=?&lt;/loadUserSQL&gt;
     &lt;userCountSQL&gt;SELECT COUNT(*) FROM myUser&lt;/userCountSQL&gt;
     &lt;allUsersSQL&gt;SELECT username FROM myUser&lt;/allUsersSQL&gt;
     &lt;searchSQL&gt;SELECT username FROM myUser WHERE&lt;/searchSQL&gt;
     &lt;usernameField&gt;username&lt;/usernameField&gt;
     &lt;nameField&gt;name&lt;/nameField&gt;
     &lt;emailField&gt;email&lt;/emailField&gt;
  &lt;/jdbcUserProvider&gt;
Matt Tucker's avatar
Matt Tucker committed
263 264 265
  &lt;jdbcGroupProvider&gt;
       &lt;groupCountSQL&gt;SELECT count(*) FROM myGroups&lt;/groupCountSQL&gt;
       &lt;allGroupsSQL&gt;SELECT groupName FROM myGroups&lt;/allGroupsSQL&gt;
266
       &lt;userGroupsSQL&gt;SELECT groupName FROM myGroupUsers WHERE username=?&lt;/userGroupsSQL&gt;
Matt Tucker's avatar
Matt Tucker committed
267
       &lt;descriptionSQL&gt;SELECT groupDescription FROM myGroups WHERE groupName=?&lt;/descriptionSQL&gt;
268 269
       &lt;loadMembersSQL&gt;SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin='N'&lt;/loadMembersSQL&gt;
       &lt;loadAdminsSQL&gt;SELECT username FROM myGroupUsers WHERE groupName=? AND isAdmin='Y'&lt;/loadAdminsSQL&gt;
Matt Tucker's avatar
Matt Tucker committed
270 271 272 273 274 275 276 277 278 279
  &lt;/jdbcGroupProvider&gt;
  ...
&lt;/jive&gt;
</pre>

    </div>

</div>

</body>
280
</html>