.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::Authorization::Driver::DBI 3pm" .TH CGI::Application::Plugin::Authorization::Driver::DBI 3pm "2016-07-22" "perl v5.22.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" CGI::Application::Plugin::Authorization::Driver::DBI \- DBI Authorization driver .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use base qw(CGI::Application); \& use CGI::Application::Plugin::Authorization; \& \& # Simple task based authentication \& _\|_PACKAGE_\|_\->authz\->config( \& DRIVER => [ \*(AqDBI\*(Aq, \& TABLES => [\*(Aqaccount\*(Aq, \*(Aqtask\*(Aq], \& JOIN_ON => \*(Aqaccount.id = task.accountid\*(Aq, \& USERNAME => \*(Aqaccount.name\*(Aq, \& CONSTRAINTS => { \& \*(Aqtask.name\*(Aq => \*(Aq_\|_PARAM_1_\|_\*(Aq, \& } \& ], \& ); \& if ($self\->authz\->authorize(\*(Aqeditfoo\*(Aq) { \& # User is allowed access if it can \*(Aqeditfoo\*(Aq \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This Authorization driver uses the \s-1DBI\s0 module to allow you to gather authorization information from any database for which there is a \s-1DBD\s0 module. You can either provide an active database handle, or provide the parameters necessary to connect to the database. .SS "\s-1DBH\s0" .IX Subsection "DBH" The \s-1DBI\s0 database handle to use. Defaults to \f(CW\*(C`$self\->dbh()\*(C'\fR, which is provided and configured through CGI::Application::Plugin::DBH .PP When describing the database structure you have two options: .IP "\s-1TABLE\s0(S), \s-1JOIN_ON, USERNAME\s0 and \s-1CONSTRAINTS:\s0" 4 .IX Item "TABLE(S), JOIN_ON, USERNAME and CONSTRAINTS:" Use these values to describe the table structure, and an sql statement will be automatically generated to query the database .IP "\s-1SQL:\s0" 4 .IX Item "SQL:" just provide one \s-1SQL\s0 parameters that gives a complete sql statement that will be used to query the database .PP Following is a description of all the available parameters: .SS "\s-1TABLE\s0(S)" .IX Subsection "TABLE(S)" Provide either a single table name, or an array of table names. You can give the table names aliases which can be referenced in later columns. .PP .Vb 1 \& TABLE => \*(Aqgroup\*(Aq, \& \& \- or \- \& \& TABLES => [\*(Aquser U\*(Aq, \*(Aqgroup G\*(Aq], .Ve .SS "\s-1JOIN_ON\s0" .IX Subsection "JOIN_ON" If you have specified multiple tables, then you need to provide an \s-1SQL\s0 expression that can be used to join those tables. .PP .Vb 1 \& JOIN_ON => \*(Aquser.id = group.userid\*(Aq, \& \& \- or \- \& \& JOIN_ON => \*(AqU.id = G.userid\*(Aq, .Ve .SS "\s-1USERNAME\s0" .IX Subsection "USERNAME" This should be set to the column name that contains the username. This column will be compared against the currently logged in user. .PP .Vb 1 \& USERNAME => \*(Aqname\*(Aq \& \& \- or \- \& \& USERNAME => \*(AqU.name\*(Aq .Ve .SS "\s-1CONSTRAINTS\s0" .IX Subsection "CONSTRAINTS" Constraints are used to restrict the database query against the options that are passed to the \f(CW\*(C`authorize\*(C'\fR method. In the common case, you will check these parameters against a group permission table, although there is no limit to the number of parameters that can be used. Each constraint can be set to a static value, or it can be set to '_\|_PARAM_n_\|_' where 'n' is the position of the parameter that is passed in to the \f(CW\*(C`authorize\*(C'\fR method. .PP .Vb 5 \& CONSTRAINTS => { \& \*(Aquser.active\*(Aq => \*(Aqt\*(Aq, \& \*(Aqgroup.type\*(Aq => \*(Aq_\|_PARAM_1_\|_\*(Aq, \& \*(Aqgroup.name\*(Aq => \*(Aq_\|_PARAM_2_\|_\*(Aq, \& } .Ve .SS "\s-1SQL\s0" .IX Subsection "SQL" If you need to perform a complex query that can not be defined by the above syntax, then you can provide your own \s-1SQL\s0 statement where the first placeholder is used to fill in the username, and the rest of the placeholders are filled in using the parameters passed to the authorize method. .PP .Vb 7 \& SQL => \*(AqSELECT count(*) \& FROM account \& LEFT JOIN ip ON (account.id = ip.accountid) \& LEFT JOIN task ON (account.id = task.accountid) \& WHERE account.name = ? \& AND (ip.address >> inet ? OR task.name = ?) \& \*(Aq, .Ve .SH "EXAMPLE" .IX Header "EXAMPLE" .Vb 10 \& # \& # Example table structure (for PostgreSQL): \& # \& CREATE TABLE account ( \& id SERIAL NOT NULL PRIMARY KEY, \& name VARCHAR(50) NOT NULL \& ); \& CREATE TABLE task ( \& id SERIAL NOT NULL PRIMARY KEY, \& accountid INTEGER NOT NULL REFERENCES account(id), \& name VARCHAR(50) NOT NULL \& ); \& CREATE TABLE ip ( \& id SERIAL NOT NULL PRIMARY KEY, \& accountid INTEGER NOT NULL REFERENCES account(id), \& address INET NOT NULL \& ); \& INSERT INTO account (name) VALUES (\*(Aqtestuser\*(Aq); \& INSERT INTO task (accountid, name) VALUES (1, \*(Aqeditfoo\*(Aq); \& INSERT INTO ip (accountid, address) VALUES (1, \*(Aq192.168.1.0/24\*(Aq); \& \& # Simple task based authentication \& _\|_PACKAGE_\|_\->authz\->config( \& DRIVER => [ \*(AqDBI\*(Aq, \& # the handle comes from $self\->dbh, via the "DBH" plugin. \& TABLES => [\*(Aqaccount\*(Aq, \*(Aqtask\*(Aq], \& JOIN_ON => \*(Aqaccount.id = task.accountid\*(Aq, \& USERNAME => \*(Aqaccount.name\*(Aq, \& CONSTRAINTS => { \& \*(Aqtask.name\*(Aq => \*(Aq_\|_PARAM_1_\|_\*(Aq, \& \*(Aqtask.active\*(Aq => \*(Aqt\*(Aq \& } \& ], \& ); \& if ($self\->authz\->authorize(\*(Aqeditfoo\*(Aq) { \& # User is allowed access if they can \*(Aqeditfoo\*(Aq \& } \& \& # IP address configuration \& _\|_PACKAGE_\|_\->authz(\*(AqbyIP\*(Aq)\->config( \& DRIVER => [ \*(AqDBI\*(Aq, \& SQL => \*(AqSELECT count(*) \& FROM account JOIN ip ON (account.id = ip.accountid) \& WHERE account.name = ? \& AND ip.address >> inet ? \& \*(Aq, \& ], \& ); \& if ($self\->authz(\*(AqbyIP\*(Aq)\->authorize($ENV{REMOTE_ADDR}) { \& # User is allowed to connect from this address \& } \& \& # both together in one test \& # IP address configuration \& _\|_PACKAGE_\|_\->authz\->config( \& DRIVER => [ \*(AqDBI\*(Aq, \& SQL => \*(AqSELECT count(*) \& FROM account \& JOIN ip ON (account.id = ip.accountid) \& JOIN task ON (account.id = task.accountid) \& WHERE account.name = ? \& AND task.name = ? \& AND ip.address >> inet ? \& \*(Aq, \& ], \& ); \& if ($self\->authz\->authorize(\*(Aqeditfoo\*(Aq, $ENV{REMOTE_ADDR}) { \& # User is allowed to connect from this address if they can \& # also \*(Aqeditfoo\*(Aq \& } .Ve .SH "METHODS" .IX Header "METHODS" .SS "authorize_user" .IX Subsection "authorize_user" This method accepts a username followed by a list of parameters and will return true if the configured query returns at least one row based on the given parameters. .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application::Plugin::Authorization::Driver, CGI::Application::Plugin::Authorization, \fIperl\fR\|(1) .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (c) 2005, SiteSuite. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" \&\s-1BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE \*(L"AS IS\*(R" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.\s0 .PP \&\s-1IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE \s0(\s-1INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE\s0), \s-1EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\s0