<-
Apache > HTTP Server > Documentation > Modules

Apache Module mod_authz_dbd c6w1b

Available Languages:  fr 

Description: Group Authorization and using SQL
Status: Extension
Module Identifier: authz_dbd_module
Source File: mod_authz_dbd.c
Compatibility: Available in Apache 2.4 and later

Summary 6m2os

This module provides authorization capabilities so that authenticated s can be allowed or denied access to portions of the web site by group hip. Similar functionality is provided by mod_authz_dbm, with the exception that this module queries a SQL database to determine whether a is a member of a group.

This module can also provide database-backed / capabilities. These are likely to be of most value when used in conjunction with mod_authn_dbd.

This module relies on mod_dbd to specify the backend database driver and connection parameters, and manage the database connections.

 Apache!

Topics 2c136y

Directives 1a4l6m

Bugfix checklist 4i2533

See also 27136x

top

The Require Directives 503h1o

Apache's Require directives are used during the authorization phase to ensure that a is allowed to access a resource. mod_authz_dbd extends the authorization types with dbd-group, dbd- and dbd-.

Since v2.4.8, expressions are ed within the DBD require directives.

Require dbd-group 11i2t

This directive specifies group hip that is required for the to gain access.

Require dbd-group team
AuthzDBDQuery "SELECT group FROM authz WHERE  = %s"

Require dbd- 6v361c

This directive specifies a query to be run indicating the has logged in.

Require dbd-
AuthzDBDQuery "UPDATE authn SET  = 'true' WHERE  = %s"

Require dbd- 6v361c

This directive specifies a query to be run indicating the has logged out.

Require dbd-
AuthzDBDQuery "UPDATE authn SET  = 'false' WHERE  = %s"
top

Database r361e

In addition to the standard authorization function of checking group hip, this module can also provide server-side session management via database-backed / capabilities. Specifically, it can update a 's session status in the database whenever the visits designated URLs (subject of course to s supplying the necessary credentials).

This works by defining two special Require types: Require dbd- and Require dbd-. For usage details, see the configuration example below.

top

Client integration 4q5t2c

Some s may wish to implement client-side session management that works in concert with the server-side / capabilities offered by this module, for example, by setting or unsetting an HTTP cookie or other such token when a logs in or out.

To such integration, mod_authz_dbd exports an optional hook that will be run whenever a 's status is updated in the database. Other session management modules can then use the hook to implement functions that start and end client-side sessions.

top

Configuration example 4h6y1d

# mod_dbd configuration
DBDriver pgsql
DBDParams "dbname=apacheauth =apache =xxxxxx"

DBDMin  4
DBDKeep 8
DBDMax  20
DBDExptime 300

<Directory "/usr/www/my.site/team-private/">
  # mod_authn_core and mod_auth_basic configuration
  # for mod_authn_dbd
  AuthType Basic
  AuthName Team
  AuthBasirovider dbd

  # mod_authn_dbd SQL query to authenticate a logged-in 
  AuthDBDPWQuery \
    "SELECT  FROM authn WHERE  = %s AND  = 'true'"

  # mod_authz_core configuration for mod_authz_dbd
  Require dbd-group team

  # mod_authz_dbd configuration
  AuthzDBDQuery "SELECT group FROM authz WHERE  = %s"

  # when a  fails to be authenticated or authorized,
  # invite them to ; this page should provide a link
  # to /team-private/.html
  ErrorDocument 401 "/-info.html"

  <Files ".html">
    # don't require  to already be logged in!
    AuthDBDPWQuery "SELECT  FROM authn WHERE  = %s"

    # dbd- action executes a statement to log  in
    Require dbd-
    AuthzDBDQuery "UPDATE authn SET  = 'true' WHERE  = %s"

    # return  to referring page (if any) after
    # successful 
    AuthzDBDToReferer On
  </Files>

  <Files ".html">
    # dbd- action executes a statement to log  out
    Require dbd-
    AuthzDBDQuery "UPDATE authn SET  = 'false' WHERE  = %s"
  </Files>
</Directory>
top

AuthzDBDToReferer Directive 6rt6w

Description: Determines whether to redirect the Client to the Referring page on successful or if a Referer request header is present
Syntax: AuthzDBDToReferer On|Off
Default: AuthzDBDToReferer Off
Context: directory
Status: Extension
Module: mod_authz_dbd

In conjunction with Require dbd- or Require dbd-, this provides the option to redirect the client back to the Referring page (the URL in the Referer HTTP request header, if present). When there is no Referer header, AuthzDBDToReferer On will be ignored.

top

AuthzDBDQuery Directive 441e2v

Description: Specify the SQL Query for the required operation
Syntax: AuthzDBDQuery query
Context: directory
Status: Extension
Module: mod_authz_dbd

The AuthzDBDQuery specifies an SQL query to run. The purpose of the query depends on the Require directive in effect.

In all cases, the 's ID will be ed as a single string parameter when the SQL query is executed. It may be referenced within the query statement using a %s format specifier.

top

AuthzDBDRedirectQuery Directive 3d1a21

Description: Specify a query to look up a page for the
Syntax: AuthzDBDRedirectQuery query
Context: directory
Status: Extension
Module: mod_authz_dbd

Specifies an optional SQL query to use after successful (or ) to redirect the to a URL, which may be specific to the . The 's ID will be ed as a single string parameter when the SQL query is executed. It may be referenced within the query statement using a %s format specifier.

AuthzDBDRedirectQuery "SELECT page FROM pages WHERE  = %s"

The first column value of the first row returned by the query statement should be a string containing a URL to which to redirect the client. Subsequent rows will be ignored. If no rows are returned, the client will not be redirected.

Note that AuthzDBDToReferer takes precedence if both are set.

Available Languages:  fr 

top

Comments 2p1l6j

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our s if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.