]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_authz_dbd.xml
xforms
[apache] / docs / manual / mod / mod_authz_dbd.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_authz_dbd.xml.meta">
24
25 <name>mod_authz_dbd</name>
26 <description>Group Authorization and Login using SQL</description>
27 <status>Extension</status>
28 <sourcefile>mod_authz_dbd.c</sourcefile>
29 <identifier>authz_dbd_module</identifier>
30 <compatibility>Available in Apache 2.4 and later</compatibility>
31
32 <summary>
33     <p>This module provides authorization capabilities so that
34        authenticated users can be allowed or denied access to portions
35        of the web site by group membership.  Similar functionality is
36        provided by <module>mod_authz_groupfile</module> and
37        <module>mod_authz_dbm</module>, with the exception that
38        this module queries a SQL database to determine whether a
39        user is a member of a group.</p>
40     <p>This module can also provide database-backed user login/logout
41        capabilities.  These are likely to be of most value when used
42        in conjunction with <module>mod_authn_dbd</module>.</p>
43     <p>This module relies on <module>mod_dbd</module> to specify
44        the backend database driver and connection parameters, and
45        manage the database connections.</p>
46 </summary>
47
48 <seealso><directive module="mod_authz_core">Require</directive></seealso>
49 <seealso>
50   <directive module="mod_authn_dbd">AuthDBDUserPWQuery</directive>
51 </seealso>
52 <seealso><directive module="mod_dbd">DBDriver</directive></seealso>
53 <seealso><directive module="mod_dbd">DBDParams</directive></seealso>
54
55 <section id="login">
56 <title>Database Login</title>
57 <p>
58 In addition to the standard authorization function of checking group
59 membership, this module can also provide server-side user session
60 management via database-backed login/logout capabilities.
61 Specifically, it can update a user's session status in the database
62 whenever the user visits designated URLs (subject of course to users
63 supplying the necessary credentials).</p>
64 <p>This works by defining two special
65 <directive module="mod_authz_core">Require</directive> types:
66 <code>Require dbd-login</code> and <code>Require dbd-logout</code>.
67 For usage details, see the configuration example below.</p>
68 </section>
69
70 <section id="client">
71 <title>Client Login</title>
72 <p>Some administrators may wish to implement client-side session
73 management that works in concert with the server-side login/logout
74 capabilities offered by this module, for example, by setting or unsetting
75 an HTTP cookie or other such token when a user logs in or out.
76 To support such integration, <module>mod_authz_dbd</module> exports an
77 optional hook that will be run whenever a user's status is updated in
78 the database.  Other session management modules can then use the hook
79 to implement functions that start and end client-side sessions.</p>
80 </section>
81
82 <section id="example">
83 <title>Configuration example</title>
84 <highlight language="config">
85 # mod_dbd configuration
86 DBDriver pgsql
87 DBDParams "dbname=apacheauth user=apache pass=xxxxxx"
88
89 DBDMin  4
90 DBDKeep 8
91 DBDMax  20
92 DBDExptime 300
93
94 &lt;Directory /usr/www/my.site/team-private/&gt;
95   # mod_authn_core and mod_auth_basic configuration
96   # for mod_authn_dbd
97   AuthType Basic
98   AuthName Team
99   AuthBasicProvider dbd
100
101   # mod_authn_dbd SQL query to authenticate a logged-in user
102   AuthDBDUserPWQuery \
103     "SELECT password FROM authn WHERE user = %s AND login = 'true'"
104
105   # mod_authz_core configuration for mod_authz_dbd
106   Require dbd-group team
107
108   # mod_authz_dbd configuration
109   AuthzDBDQuery "SELECT group FROM authz WHERE user = %s"
110
111   # when a user fails to be authenticated or authorized,
112   # invite them to login; this page should provide a link
113   # to /team-private/login.html
114   ErrorDocument 401 /login-info.html
115
116   &lt;Files login.html&gt;
117     # don't require user to already be logged in!
118     AuthDBDUserPWQuery "SELECT password FROM authn WHERE user = %s"
119
120     # dbd-login action executes a statement to log user in
121     Require dbd-login
122     AuthzDBDQuery "UPDATE authn SET login = 'true' WHERE user = %s"
123
124     # return user to referring page (if any) after
125     # successful login
126     AuthzDBDLoginToReferer On
127   &lt;/Files&gt;
128
129   &lt;Files logout.html&gt;
130     # dbd-logout action executes a statement to log user out
131     Require dbd-logout
132     AuthzDBDQuery "UPDATE authn SET login = 'false' WHERE user = %s"
133   &lt;/Files&gt;
134 &lt;/Directory&gt;
135 </highlight>
136 </section>
137
138 <directivesynopsis>
139 <name>AuthzDBDQuery</name>
140 <description>Specify the SQL Query for the required operation</description>
141 <syntax>AuthzDBDQuery <var>query</var></syntax>
142 <contextlist><context>directory</context></contextlist>
143
144 <usage>
145     <p>The <directive>AuthzDBDQuery</directive> specifies an SQL
146     query to run.  The purpose of the query depends on the
147     <directive module="mod_authz_core">Require</directive> directive in
148     effect.</p>
149     <ul>
150     <li>When used with a <code>Require dbd-group</code> directive,
151     it specifies a query to look up groups for the current user.  This is
152     the standard functionality of other authorization modules such as
153     <module>mod_authz_groupfile</module> and <module>mod_authz_dbm</module>.
154     The first column value of each row returned by the query statement
155     should be a string containing a group name.  Zero, one, or more rows
156     may be returned.
157     <highlight language="config">
158 Require dbd-group
159 AuthzDBDQuery "SELECT group FROM groups WHERE user = %s"
160 </highlight>
161     </li>
162     <li>When used with a <code>Require dbd-login</code> or
163     <code>Require dbd-logout</code> directive, it will never deny access,
164     but will instead execute a SQL statement designed to log the user
165     in or out.  The user must already be authenticated with
166     <module>mod_authn_dbd</module>.
167     <highlight language="config">
168 Require dbd-login
169 AuthzDBDQuery "UPDATE authn SET login = 'true' WHERE user = %s"
170 </highlight>
171     </li>
172     </ul>
173     <p>In all cases, the user's ID will be passed as a single string
174     parameter when the SQL query is executed.  It may be referenced within
175     the query statement using a <code>%s</code> format specifier.</p>
176 </usage>
177 </directivesynopsis>
178
179 <directivesynopsis>
180 <name>AuthzDBDRedirectQuery</name>
181 <description>Specify a query to look up a login page for the user</description>
182 <syntax>AuthzDBDRedirectQuery <var>query</var></syntax>
183 <contextlist><context>directory</context></contextlist>
184
185 <usage>
186     <p>Specifies an optional SQL query to use after successful login
187     (or logout) to redirect the user to a URL, which may be
188     specific to the user.  The user's ID will be passed as a single string
189     parameter when the SQL query is executed.  It may be referenced within
190     the query statement using a <code>%s</code> format specifier.</p>
191     <highlight language="config">
192 AuthzDBDRedirectQuery "SELECT userpage FROM userpages WHERE user = %s"
193 </highlight>
194     <p>The first column value of the first row returned by the query
195     statement should be a string containing a URL to which to redirect
196     the client.  Subsequent rows will be ignored.  If no rows are returned,
197     the client will not be redirected.</p>
198     <p>Note that <directive>AuthzDBDLoginToReferer</directive> takes
199     precedence if both are set.</p>
200 </usage>
201 </directivesynopsis>
202
203 <directivesynopsis>
204 <name>AuthzDBDLoginToReferer</name>
205 <description>Determines whether to redirect the Client to the Referring
206 page on successful login or logout if a <code>Referer</code> request
207 header is present</description>
208 <syntax>AuthzDBDLoginToReferer On|Off</syntax>
209 <default>AuthzDBDLoginToReferer Off</default>
210 <contextlist><context>directory</context></contextlist>
211
212 <usage>
213     <p>In conjunction with <code>Require dbd-login</code> or
214     <code>Require dbd-logout</code>, this provides the option to
215     redirect the client back to the Referring page (the URL in
216     the <code>Referer</code> HTTP request header, if present).
217     When there is no <code>Referer</code> header,
218     <code>AuthzDBDLoginToReferer On</code> will be ignored.</p>
219 </usage>
220 </directivesynopsis>
221
222 </modulesynopsis>