<?xml version="1.0"?>
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
<!-- $LastChangedRevision$ -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<modulesynopsis metafile="mod_authn_dbd.xml.meta">

<name>mod_authn_dbd</name>
<description>User authentication using an SQL database</description>
<status>Extension</status>
<sourcefile>mod_authn_dbd.c</sourcefile>
<identifier>authn_dbd_module</identifier>
<compatibility>Available in Apache 2.1 and later</compatibility>

<summary>
    <p>This module provides authentication front-ends such as
    <module>mod_auth_digest</module> and <module>mod_auth_basic</module>
    to authenticate users by looking up users in SQL tables.
    Similar functionality is provided by, for example,
    <module>mod_authn_file</module>.</p>
    <p>This module relies on <module>mod_dbd</module> to specify
    the backend database driver and connection parameters, and
    manage the database connections.</p>

    <p>When using <module>mod_auth_basic</module> or
    <module>mod_auth_digest</module>, this module is invoked via the
    <directive module="mod_auth_basic">AuthBasicProvider</directive> or
    <directive module="mod_auth_digest">AuthDigestProvider</directive>
    with the <code>dbd</code> value.</p>
</summary>

<seealso><directive module="mod_authn_core">AuthName</directive></seealso>
<seealso><directive module="mod_authn_core">AuthType</directive></seealso>
<seealso>
  <directive module="mod_auth_basic">AuthBasicProvider</directive>
</seealso>
<seealso>
  <directive module="mod_auth_digest">AuthDigestProvider</directive>
</seealso>
<seealso><directive module="mod_dbd">DBDriver</directive></seealso>
<seealso><directive module="mod_dbd">DBDParams</directive></seealso>

<section id="example">
<title>Configuration Example</title>
<p>This simple example shows use of this module in the context of
the Authentication and DBD frameworks.</p>
<example><pre>
#Database Management

#Use the PostgreSQL driver
<code>DBDriver pgsql</code>

#Connection string: database name and login credentials
<code>DBDParams "dbname=htpasswd user=apache password=xxxxxx"</code>

#Parameters for Connection Pool Management
<code>DBDMin  1
DBDKeep 2
DBDMax  10
DBDExptime 60</code>

#Authentication Section
<code>&lt;Directory /usr/www/myhost/private&gt;</code>

    #mod_auth configuration for authn_dbd
    <code>AuthType Basic
    AuthName "My Server"
    AuthBasicProvider dbd</code>

    #authz configuration
    <code>Require valid-user</code>

    #SQL query to verify a user
    #(note: DBD drivers recognise both stdio-like %s and native syntax)
    <code>AuthDBDUserPWQuery "select password from authn where username = %s"
&lt;/Directory&gt;</code>
</pre>
</example>
</section>

<section id="exposed">
<title>Exposing Login Information</title>
<p>
Whenever a query is made to the database server, all columns returned by
the query are placed in the environment, using environment variables with
the prefix "AUTHENTICATE_".
</p>
<p>If a database query for example returned the username, full name
and telephone number of a user, a CGI program will have access to
this information without the need to make a second independent database
query to gather this additional information.</p>
<p>This has the potential to dramatically simplify the coding and
configuration required in some web applications.
</p>
</section>

<directivesynopsis>
<name>AuthDBDUserPWQuery</name>
<description>SQL query to look up a password for a user</description>
<syntax>AuthDBDUserPWQuery <var>query</var></syntax>
<contextlist><context>directory</context>
</contextlist>

<usage>
    <p>The <directive>AuthDBDUserPWQuery</directive> specifies an
    SQL query to look up a password for a specified user.
    The query must take a single string (typically SQL varchar)
    argument (username), and return a single value (encrypted password).
    </p>
    <example>
    AuthDBDUserPWQuery "SELECT password FROM authn WHERE username = %s"
    </example>
    <p>If httpd was built against apr v1.3.0 or higher, any additional
    columns specified in the select statement will be inserted into
    the environment with the name <code>AUTHENTICATE_&lt;COLUMN&gt;</code>.
    </p>
</usage>
</directivesynopsis>

<directivesynopsis>
<name>AuthDBDUserRealmQuery</name>
<description>SQL query to look up a password hash for a user and realm.
</description>
<syntax>AuthDBDUserRealmQuery <var>query</var></syntax>
<contextlist><context>directory</context>
</contextlist>

<usage>
    <p>The <directive>AuthDBDUserRealmQuery</directive> specifies an
    SQL query to look up a password for a specified user and realm.
    The query must take two string (typically SQL varchar) arguments
    (username and realm), and return a single value (encrypted password).
    </p>
    <example>
    AuthDBDUserRealmQuery "SELECT password FROM authn
                              WHERE username = %s AND realm = %s"
    </example>
    <p>If httpd was built against apr v1.3.0 or higher, any additional
    columns specified in the select statement will be inserted into
    the environment with the name <code>AUTHENTICATE_&lt;COLUMN&gt;</code>.
    </p>

</usage>
</directivesynopsis>

</modulesynopsis>
