.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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 >0, 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 .\" ======================================================================== .\" .IX Title "CGI::Application::Plugin::Authentication 3pm" .TH CGI::Application::Plugin::Authentication 3pm "2024-01-07" "perl v5.36.0" "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::Authentication \- Authentication framework for CGI::Application .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package MyCGIApp; \& \& use base qw(CGI::Application); # make sure this occurs before you load the plugin \& \& use CGI::Application::Plugin::Authentication; \& \& MyCGIApp\->authen\->config( \& DRIVER => [ \*(AqGeneric\*(Aq, { user1 => \*(Aq123\*(Aq } ], \& ); \& MyCGIApp\->authen\->protected_runmodes(\*(Aqmyrunmode\*(Aq); \& \& sub myrunmode { \& my $self = shift; \& \& # The user should be logged in if we got here \& my $username = $self\->authen\->username; \& \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" CGI::Application::Plugin::Authentication adds the ability to authenticate users in your CGI::Application modules. It imports one method called 'authen' into your CGI::Application module. Through the authen method you can call all the methods of the CGI::Application::Plugin::Authentication plugin. .PP There are two main decisions that you need to make when using this module. How will the usernames and password be verified (i.e. from a database, \s-1LDAP,\s0 etc...), and how can we keep the knowledge that a user has already logged in persistent, so that they will not have to enter their credentials again on the next request (i.e. how do we 'Store' the authentication information across requests). .SS "Choosing a Driver" .IX Subsection "Choosing a Driver" There are three drivers that are included with the distribution. Also, there is built in support for all of the Authen::Simple modules (search \s-1CPAN\s0 for Authen::Simple for more information). This should be enough to cover everyone's needs. .PP If you need to authenticate against a source that is not provided, you can use the Generic driver which will accept either a hash of username/password pairs, or an array of arrays of credentials, or a subroutine reference that can verify the credentials. So through the Generic driver you should be able to write your own verification system. There is also a Dummy driver, which blindly accepts any credentials (useful for testing). See the CGI::Application::Plugin::Authentication::Driver::Generic, CGI::Application::Plugin::Authentication::Driver::DBI and, CGI::Application::Plugin::Authentication::Driver::Dummy docs for more information on how to use these drivers. And see the Authen::Simple suite of modules for information on those drivers. .SS "Choosing a Store" .IX Subsection "Choosing a Store" The Store modules keep information about the authentication status of the user persistent across multiple requests. The information that is stored in the store include the username, and the expiry time of the login. There are two Store modules included with this distribution. A Session based store, and a Cookie based store. If your application is already using Sessions (through the CGI::Application::Plugin::Session module), then I would recommend that you use the Session store for authentication. If you are not using the Session plugin, then you can use the Cookie store. The Cookie store keeps all the authentication in a cookie, which contains a checksum to ensure that users can not change the information. .PP If you do not specify which Store module you wish to use, the plugin will try to determine the best one for you. .SS "Login page" .IX Subsection "Login page" The Authentication plugin comes with a default login page that can be used if you do not want to create a custom login page. This login form will automatically be used if you do not provide either a \s-1LOGIN_URL\s0 or \s-1LOGIN_RUNMODE\s0 parameter in the configuration. If you plan to create your own login page, I would recommend that you start with the \s-1HTML\s0 code for the default login page, so that your login page will contain the correct form fields and hidden fields. .SS "Ticket based authentication" .IX Subsection "Ticket based authentication" This Authentication plugin can handle ticket based authentication systems as well. All that is required of you is to write a Store module that can understand the contents of the ticket. The Authentication plugin will require at least the 'username' to be retrieved from the ticket. A Ticket based authentication scheme will not need a Driver module at all, since the actual verification of credentials is done by an external authentication system, possibly even on a different host. You will need to specify the location of the login page using the \s-1LOGIN_URL\s0 configuration variable, and unauthenticated users will automatically be redirected to your ticket authentication login page. .SH "EXPORTED METHODS" .IX Header "EXPORTED METHODS" .SS "authen" .IX Subsection "authen" This is the only method exported from this module. Everything is controlled through this method call, which will return a CGI::Application::Plugin::Authentication object, or just the class name if called as a class method. When using the plugin, you will always first call \f(CW$self\fR\->authen or _\|_PACKAGE_\|_\->authen and then the method you wish to invoke. For example: .PP .Vb 3 \& _\|_PACKAGE_\|_\->authen\->config( \& LOGIN_RUNMODE => \*(Aqlogin\*(Aq, \& ); .Ve .PP \&\- or \- .PP .Vb 1 \& $self\->authen\->protected_runmodes(qw(one two)); .Ve .SH "METHODS" .IX Header "METHODS" .SS "config" .IX Subsection "config" This method is used to configure the CGI::Application::Plugin::Authentication module. It can be called as an object method, or as a class method. Calling this function, will not itself generate cookies or session ids. .PP The following parameters are accepted: .IP "\s-1DRIVER\s0" 4 .IX Item "DRIVER" Here you can choose which authentication module(s) you want to use to perform the authentication. For simplicity, you can leave off the CGI::Application::Plugin::Authentication::Driver:: part when specifying the \s-1DRIVER\s0 name If this module requires extra parameters, you can pass an array reference that contains as the first parameter the name of the module, and the rest of the values in the array will be considered options for the driver. You can provide multiple drivers which will be used, in order, to check the credentials until a valid response is received. .Sp .Vb 1 \& DRIVER => \*(AqDummy\*(Aq # let anyone in regardless of the password \& \& \- or \- \& \& DRIVER => [ \*(AqDBI\*(Aq, \& DBH => $self\->dbh, \& TABLE => \*(Aquser\*(Aq, \& CONSTRAINTS => { \& \*(Aquser.name\*(Aq => \*(Aq_\|_CREDENTIAL_1_\|_\*(Aq, \& \*(AqMD5:user.password\*(Aq => \*(Aq_\|_CREDENTIAL_2_\|_\*(Aq \& }, \& ], \& \& \- or \- \& \& DRIVER => [ \& [ \*(AqGeneric\*(Aq, { user1 => \*(Aq123\*(Aq } ], \& [ \*(AqGeneric\*(Aq, sub { my ($u, $p) = @_; is_prime($p) ? 1 : 0 } ] \& ], \& \& \- or \- \& \& DRIVER => [ \*(AqAuthen::Simple::LDAP\*(Aq, \& host => \*(Aqldap.company.com\*(Aq, \& basedn => \*(Aqou=People,dc=company,dc=net\*(Aq \& ], .Ve .IP "\s-1STORE\s0" 4 .IX Item "STORE" Here you can choose how we store the authenticated information after a user has successfully logged in. We need to store the username so that on the next request we can tell the user has already logged in, and we do not have to present them with another login form. If you do not provide the \s-1STORE\s0 option, then the plugin will look to see if you are using the CGI::Application::Plugin::Session module and based on that info use either the Session module, or fall back on the Cookie module. If the module requires extra parameters, you can pass an array reference that contains as the first parameter the name of the module, and the rest of the array should contain key value pairs of options for this module. These storage modules generally live under the CGI::Application::Plugin::Authentication::Store:: name-space, and this part of the package name can be left off when specifying the \s-1STORE\s0 parameter. .Sp .Vb 1 \& STORE => \*(AqSession\*(Aq \& \& \- or \- \& \& STORE => [\*(AqCookie\*(Aq, \& NAME => \*(AqMYAuthCookie\*(Aq, \& SECRET => \*(AqFortyTwo\*(Aq, \& EXPIRY => \*(Aq1d\*(Aq, \& ] .Ve .IP "\s-1POST_LOGIN_RUNMODE\s0" 4 .IX Item "POST_LOGIN_RUNMODE" Here you can specify a runmode that the user will be redirected to if they successfully login. .Sp .Vb 1 \& POST_LOGIN_RUNMODE => \*(Aqwelcome\*(Aq .Ve .IP "\s-1POST_LOGIN_URL\s0" 4 .IX Item "POST_LOGIN_URL" Here you can specify a \s-1URL\s0 that the user will be redirected to if they successfully login. If both \s-1POST_LOGIN_URL\s0 and \s-1POST_LOGIN_RUNMODE\s0 are specified, then the latter will take precedence. .Sp .Vb 1 \& POST_LOGIN_URL => \*(Aqhttp://example.com/start.cgi\*(Aq .Ve .IP "\s-1POST_LOGIN_CALLBACK\s0" 4 .IX Item "POST_LOGIN_CALLBACK" A code reference that is executed after login processing but before \s-1POST_LOGIN_RUNMODE\s0 or redirecting to \s-1POST_LOGIN_URL.\s0 This is normally a method in your CGI::Application application and as such the CGI::Application object is passed as a parameter. .Sp .Vb 1 \& POST_LOGIN_CALLBACK => \e&update_login_date .Ve .Sp and later in your code: .Sp .Vb 2 \& sub update_login_date { \& my $self = shift; \& \& return unless($self\->authen\->is_authenticated); \& \& ... \& } .Ve .IP "\s-1LOGIN_RUNMODE\s0" 4 .IX Item "LOGIN_RUNMODE" Here you can specify a runmode that the user will be redirected to if they need to login. .Sp .Vb 1 \& LOGIN_RUNMODE => \*(Aqlogin\*(Aq .Ve .IP "\s-1LOGIN_URL\s0" 4 .IX Item "LOGIN_URL" If your login page is external to this module, then you can use this option to specify a \&\s-1URL\s0 that the user will be redirected to when they need to login. If both \&\s-1LOGIN_URL\s0 and \s-1LOGIN_RUNMODE\s0 are specified, then the latter will take precedence. .Sp .Vb 1 \& LOGIN_URL => \*(Aqhttp://example.com/login.cgi\*(Aq .Ve .IP "\s-1LOGOUT_RUNMODE\s0" 4 .IX Item "LOGOUT_RUNMODE" Here you can specify a runmode that the user will be redirected to if they ask to logout. .Sp .Vb 1 \& LOGOUT_RUNMODE => \*(Aqlogout\*(Aq .Ve .IP "\s-1LOGOUT_URL\s0" 4 .IX Item "LOGOUT_URL" If your logout page is external to this module, then you can use this option to specify a \&\s-1URL\s0 that the user will be redirected to when they ask to logout. If both \&\s-1LOGOUT_URL\s0 and \s-1LOGOUT_RUNMODE\s0 are specified, then the latter will take precedence. .Sp .Vb 1 \& LOGIN_URL => \*(Aqhttp://example.com/logout.html\*(Aq .Ve .IP "\s-1DETAINT_URL_REGEXP\s0" 4 .IX Item "DETAINT_URL_REGEXP" This is a regular expression used to detaint URLs used in the login form. By default it will be set to .Sp .Vb 1 \& ^([\ew\e_\e%\e?\e&\e;\e\-\e/\e@\e.\e+\e$\e=\e#\e:\e!\e*\e"\e\*(Aq\e(\e)\e,]+)$ .Ve .Sp This regular expression is based upon the document http://www.w3.org/Addressing/URL/url\-spec.txt. You could set it to a more specific regular expression to limit the domains to which users could be directed. .IP "\s-1DETAINT_USERNAME_REGEXP\s0" 4 .IX Item "DETAINT_USERNAME_REGEXP" This is a regular expression used to detaint the username parameter used in the login form. By default it will be set to .Sp .Vb 1 \& ^([\ew\e_]+)$ .Ve .IP "\s-1CREDENTIALS\s0" 4 .IX Item "CREDENTIALS" Set this to the list of form fields where the user will type in their username and password. By default this is set to ['authen_username', 'authen_password']. The form field names should be set to a value that you are not likely to use in any other forms. This is important because this plugin will automatically look for query parameters that match these values on every request to see if a user is trying to log in. So if you use the same parameter names on a user management page, you may inadvertently perform a login when that was not intended. Most of the Driver modules will return the first \s-1CREDENTIAL\s0 as the username, so make sure that you list the username field first. This option can be ignored if you use the built in login box .Sp .Vb 1 \& CREDENTIALS => \*(Aqauthen_password\*(Aq \& \& \- or \- \& \& CREDENTIALS => [ \*(Aqauthen_username\*(Aq, \*(Aqauthen_domain\*(Aq, \*(Aqauthen_password\*(Aq ] .Ve .IP "\s-1LOGIN_SESSION_TIMEOUT\s0" 4 .IX Item "LOGIN_SESSION_TIMEOUT" This option can be used to tell the system when to force the user to re-authenticate. There are a few different possibilities that can all be used concurrently: .RS 4 .IP "\s-1IDLE_FOR\s0" 4 .IX Item "IDLE_FOR" If this value is set, a re-authentication will be forced if the user was idle for more then x amount of time. .IP "\s-1EVERY\s0" 4 .IX Item "EVERY" If this value is set, a re-authentication will be forced every x amount of time. .IP "\s-1CUSTOM\s0" 4 .IX Item "CUSTOM" This value can be set to a subroutine reference that returns true if the session should be timed out, and false if it is still active. This can allow you to be very selective about how the timeout system works. The authen object will be passed in as the only parameter. .RE .RS 4 .Sp Time values are specified in seconds. You can also specify the time by using a number with the following suffixes (m h d w), which represent minutes, hours, days and weeks. The default is 0 which means the login will never timeout. .Sp Note that the login is also dependent on the type of \s-1STORE\s0 that is used. If the Session store is used, and the session expires, then the login will also automatically expire. The same goes for the Cookie store. .Sp For backwards compatibility, if you set \s-1LOGIN_SESSION_TIMEOUT\s0 to a time value instead of a hashref, it will be treated as an \s-1IDLE_FOR\s0 time out. .Sp .Vb 2 \& # force re\-authentication if idle for more than 15 minutes \& LOGIN_SESSION_TIMEOUT => \*(Aq15m\*(Aq \& \& # Everyone must re\-authentication if idle for more than 30 minutes \& # also, everyone must re\-authentication at least once a day \& # and root must re\-authentication if idle for more than 5 minutes \& LOGIN_SESSION_TIMEOUT => { \& IDLE_FOR => \*(Aq30m\*(Aq, \& EVERY => \*(Aq1d\*(Aq, \& CUSTOM => sub { \& my $authen = shift; \& return ($authen\->username eq \*(Aqroot\*(Aq && (time() \- $authen\->last_access) > 300) ? 1 : 0; \& } \& } .Ve .RE .IP "\s-1RENDER_LOGIN\s0" 4 .IX Item "RENDER_LOGIN" This value can be set to a subroutine reference that returns the \s-1HTML\s0 of a login form. The subroutine reference overrides the default call to login_box. The subroutine is normally a method in your CGI::Application application and as such the CGI::Application object is passed as the first parameter. .Sp .Vb 1 \& RENDER_LOGIN => \e&login_form .Ve .Sp and later in your code: .Sp .Vb 2 \& sub login_form { \& my $self = shift; \& \& ... \& return $html \& } .Ve .IP "\s-1LOGIN_FORM\s0" 4 .IX Item "LOGIN_FORM" You can set this option to customize the login form that is created when a user needs to be authenticated. If you wish to replace the entire login form with a completely custom version, then just set \s-1LOGIN_RUNMODE\s0 to point to your custom runmode. .Sp All of the parameters listed below are optional, and a reasonable default will be used if left blank: .RS 4 .IP "\s-1DISPLAY_CLASS\s0 (default: Classic)" 4 .IX Item "DISPLAY_CLASS (default: Classic)" the class used to display the login form. The alternative is \f(CW\*(C`Basic\*(C'\fR which aims for \s-1XHTML\s0 compliance and leaving style to \s-1CSS.\s0 See CGI::Application::Plugin::Authentication::Display for more details. .IP "\s-1TITLE\s0 (default: Sign In)" 4 .IX Item "TITLE (default: Sign In)" the heading at the top of the login box .IP "\s-1USERNAME_LABEL\s0 (default: User Name)" 4 .IX Item "USERNAME_LABEL (default: User Name)" the label for the user name input .IP "\s-1PASSWORD_LABEL\s0 (default: Password)" 4 .IX Item "PASSWORD_LABEL (default: Password)" the label for the password input .IP "\s-1SUBMIT_LABEL\s0 (default: Sign In)" 4 .IX Item "SUBMIT_LABEL (default: Sign In)" the label for the submit button .IP "\s-1COMMENT\s0 (default: Please enter your username and password in the fields below.)" 4 .IX Item "COMMENT (default: Please enter your username and password in the fields below.)" a message provided on the first login attempt .IP "\s-1REMEMBERUSER_OPTION\s0 (default: 1)" 4 .IX Item "REMEMBERUSER_OPTION (default: 1)" provide a checkbox to offer to remember the users name in a cookie so that their user name will be pre-filled the next time they log in .IP "\s-1REMEMBERUSER_LABEL\s0 (default: Remember User Name)" 4 .IX Item "REMEMBERUSER_LABEL (default: Remember User Name)" the label for the remember user name checkbox .IP "\s-1REMEMBERUSER_COOKIENAME\s0 (default: \s-1CAPAUTHTOKEN\s0)" 4 .IX Item "REMEMBERUSER_COOKIENAME (default: CAPAUTHTOKEN)" the name of the cookie where the user name will be saved .IP "\s-1REGISTER_URL\s0 (default: )" 4 .IX Item "REGISTER_URL (default: )" the \s-1URL\s0 for the register new account link .IP "\s-1REGISTER_LABEL\s0 (default: Register Now!)" 4 .IX Item "REGISTER_LABEL (default: Register Now!)" the label for the register new account link .IP "\s-1FORGOTPASSWORD_URL\s0 (default: )" 4 .IX Item "FORGOTPASSWORD_URL (default: )" the \s-1URL\s0 for the forgot password link .IP "\s-1FORGOTPASSWORD_LABEL\s0 (default: Forgot Password?)" 4 .IX Item "FORGOTPASSWORD_LABEL (default: Forgot Password?)" the label for the forgot password link .ie n .IP "\s-1INVALIDPASSWORD_MESSAGE\s0 (default: Invalid username or password
(login attempt %d)" 4 .el .IP "\s-1INVALIDPASSWORD_MESSAGE\s0 (default: Invalid username or password
(login attempt \f(CW%d\fR)" 4 .IX Item "INVALIDPASSWORD_MESSAGE (default: Invalid username or password
(login attempt %d)" a message given when a login failed .IP "\s-1INCLUDE_STYLESHEET\s0 (default: 1)" 4 .IX Item "INCLUDE_STYLESHEET (default: 1)" use this to disable the built in style-sheet for the login box so you can provide your own custom styles .IP "\s-1FORM_SUBMIT_METHOD\s0 (default: post)" 4 .IX Item "FORM_SUBMIT_METHOD (default: post)" use this to get the form to submit using 'get' instead of 'post' .IP "\s-1FOCUS_FORM_ONLOAD\s0 (default: 1)" 4 .IX Item "FOCUS_FORM_ONLOAD (default: 1)" use this to automatically focus the login form when the page loads so a user can start typing right away. .IP "\s-1BASE_COLOUR\s0 (default: #445588)" 4 .IX Item "BASE_COLOUR (default: #445588)" This is the base colour that will be used in the included login box. All other colours are automatically calculated based on this colour (unless you hardcode the colour values). In order to calculate other colours, you will need the Color::Calc module. If you do not have the Color::Calc module, then you will need to use fixed values for all of the colour options. All colour values besides the \s-1BASE_COLOUR\s0 can be simple percentage values (including the % sign). For example if you set the \s-1LIGHTER_COLOUR\s0 option to 80%, then the calculated colour will be 80% lighter than the \s-1BASE_COLOUR.\s0 .IP "\s-1LIGHT_COLOUR\s0 (default: 50% or #a2aac4)" 4 .IX Item "LIGHT_COLOUR (default: 50% or #a2aac4)" A colour that is lighter than the base colour. .IP "\s-1LIGHTER_COLOUR\s0 (default: 75% or #d0d5e1)" 4 .IX Item "LIGHTER_COLOUR (default: 75% or #d0d5e1)" A colour that is another step lighter than the light colour. .IP "\s-1DARK_COLOUR\s0 (default: 30% or #303c5f)" 4 .IX Item "DARK_COLOUR (default: 30% or #303c5f)" A colour that is darker than the base colour. .IP "\s-1DARKER_COLOUR\s0 (default: 60% or #1b2236)" 4 .IX Item "DARKER_COLOUR (default: 60% or #1b2236)" A colour that is another step darker than the dark colour. .IP "\s-1GREY_COLOUR\s0 (default: #565656)" 4 .IX Item "GREY_COLOUR (default: #565656)" A grey colour that is calculated by desaturating the base colour. .RE .RS 4 .RE .SS "protected_runmodes" .IX Subsection "protected_runmodes" This method takes a list of runmodes that are to be protected by authentication. If a user tries to access one of these runmodes, then they will be redirected to a login page unless they are properly logged in. The runmode names can be a list of simple strings, regular expressions, or special directives that start with a colon. This method is cumulative, so if it is called multiple times, the new values are added to existing entries. It returns a list of all entries that have been saved so far. Calling this function, will not itself generate cookies or session ids. .IP ":all \- All runmodes in this module will require authentication" 4 .IX Item ":all - All runmodes in this module will require authentication" .PP .Vb 2 \& # match all runmodes \& _\|_PACKAGE_\|_\->authen\->protected_runmodes(\*(Aq:all\*(Aq); \& \& # only protect runmodes one two and three \& _\|_PACKAGE_\|_\->authen\->protected_runmodes(qw(one two three)); \& \& # protect only runmodes that start with auth_ \& _\|_PACKAGE_\|_\->authen\->protected_runmodes(qr/^auth_/); \& \& # protect all runmodes that *do not* start with public_ \& _\|_PACKAGE_\|_\->authen\->protected_runmodes(qr/^(?!public_)/); .Ve .SS "is_protected_runmode" .IX Subsection "is_protected_runmode" This method accepts the name of a runmode, and will tell you if that runmode is a protected runmode (i.e. does a user need to be authenticated to access this runmode). Calling this function, will not itself generate cookies or session ids. .SS "redirect_after_login" .IX Subsection "redirect_after_login" This method is be called during the prerun stage to redirect the user to the page that has been configured as the destination after a successful login. The location is determined as follows: .IP "\s-1POST_LOGIN_RUNMODE\s0" 4 .IX Item "POST_LOGIN_RUNMODE" If the \s-1POST_LOGIN_RUNMODE\s0 config parameter is set, that run mode will be the chosen location. .IP "\s-1POST_LOGIN_URL\s0" 4 .IX Item "POST_LOGIN_URL" If the above fails and the \s-1POST_LOGIN_URL\s0 config parameter is set, then there will be a 302 redirection to that location. .IP "destination" 4 .IX Item "destination" If the above fails and there is a destination query parameter, which must a taint check against the \s-1DETAINT_URL_REGEXP\s0 config parameter, then there will be a 302 redirection to that location. .IP "original destination" 4 .IX Item "original destination" If all the above fail then there the originally requested page will be delivered. .SS "redirect_to_login" .IX Subsection "redirect_to_login" This method is be called during the prerun stage if the current user is not logged in, and they are trying to access a protected runmode. It will redirect to the page that has been configured as the login page, based on the value of \s-1LOGIN_RUNMODE\s0 or \s-1LOGIN_URL\s0 If nothing is configured a simple login page will be automatically provided. .SS "redirect_to_logout" .IX Subsection "redirect_to_logout" This method is called during the prerun stage if the user has requested to be logged out. It will redirect to the page that has been configured as the logout page, based on the value of \s-1LOGOUT_RUNMODE\s0 or \s-1LOGOUT_URL\s0 If nothing is configured, the page will redirect to the website homepage. .SS "setup_runmodes" .IX Subsection "setup_runmodes" This method is called during the prerun stage to register some custom runmodes that the Authentication plugin requires in order to function. Calling this function, will not itself generate cookies or session ids. .SS "last_login" .IX Subsection "last_login" This will return return the time of the last login for this user .PP .Vb 1 \& my $last_login = $self\->authen\->last_login; .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "last_access" .IX Subsection "last_access" This will return return the time of the last access for this user .PP .Vb 1 \& my $last_access = $self\->authen\->last_access; .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "is_login_timeout" .IX Subsection "is_login_timeout" This will return true or false depending on whether the users login status just timed out .PP .Vb 1 \& $self\->add_message(\*(Aqlogin session timed out\*(Aq) if $self\->authen\->is_login_timeout; .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "is_authenticated" .IX Subsection "is_authenticated" This will return true or false depending on the login status of this user .PP .Vb 1 \& assert($self\->authen\->is_authenticated); # The user should be logged in if we got here .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "login_attempts" .IX Subsection "login_attempts" This method will return the number of failed login attempts have been made by this user since the last successful login. This is not a number that can be trusted, as it is dependent on the underlying store to be able to return the correct value for this user. For example, if the store uses a cookie based session, the user trying to login could delete their cookies, and hence get a new session which will not have any login attempts listed. The number will be cleared upon a successful login. This function will initiate a session or cookie if one has not been created already. .SS "username" .IX Subsection "username" This will return the username of the currently logged in user, or undef if no user is currently logged in. .PP .Vb 1 \& my $username = $self\->authen\->username; .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "is_new_login" .IX Subsection "is_new_login" This will return true or false depending on if this is a fresh login .PP .Vb 1 \& $self\->log\->info("New Login") if $self\->authen\->is_new_login; .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "credentials" .IX Subsection "credentials" This method will return the names of the form parameters that will be looked for during a login. By default they are authen_username and authen_password, but these values can be changed by supplying the \s-1CREDENTIALS\s0 parameters in the configuration. Calling this function, will not itself generate cookies or session ids. .SS "logout" .IX Subsection "logout" This will attempt to logout the user. If during a request the Authentication module sees a parameter called 'authen_logout', it will automatically call this method to log out the user. .PP .Vb 1 \& $self\->authen\->logout(); .Ve .PP This function will initiate a session or cookie if one has not been created already. .SS "drivers" .IX Subsection "drivers" This method will return a list of driver objects that are used for verifying the login credentials. Calling this function, will not itself generate cookies or session ids. .SS "store" .IX Subsection "store" This method will return a store object that is used to store information about the status of the authentication across multiple requests. This function will initiate a session or cookie if one has not been created already. .SS "initialize" .IX Subsection "initialize" This does most of the heavy lifting for the Authentication plugin. It will check to see if the user is currently attempting to login by looking for the credential form fields in the query object. It will load the required driver objects and authenticate the user. It is \s-1OK\s0 to call this method multiple times as it checks to see if it has already been executed and will just return without doing anything if called multiple times. This allows us to call initialize as late as possible in the request so that no unnecessary work is done. .PP The user will be logged out by calling the \f(CW\*(C`logout()\*(C'\fR method if the login session has been idle for too long, if it has been too long since the last login, or if the login has timed out. If you need to know if a user was logged out because of a time out, you can call the \f(CW\*(C`is_login_timeout\*(C'\fR method. .PP If all goes well, a true value will be returned, although it is usually not necessary to check. .PP This function will initiate a session or cookie if one has not been created already. .SS "display" .IX Subsection "display" This method will return the CGI::Application::Plugin::Authentication::Display object, creating and caching it if necessary. .SS "login_box" .IX Subsection "login_box" This method will return the \s-1HTML\s0 for a login box that can be embedded into another page. This is the same login box that is used in the default authen_login runmode that the plugin provides. .PP This function will initiate a session or cookie if one has not been created already. .SS "new" .IX Subsection "new" This method creates a new CGI::Application::Plugin::Authentication object. It requires as it's only parameter a CGI::Application object. This method should never be called directly, since the 'authen' method that is imported into the CGI::Application module will take care of creating the CGI::Application::Plugin::Authentication object when it is required. Calling this function, will not itself generate cookies or session ids. .SS "instance" .IX Subsection "instance" This method works the same way as 'new', except that it returns the same Authentication object for the duration of the request. This method should never be called directly, since the 'authen' method that is imported into the CGI::Application module will take care of creating the CGI::Application::Plugin::Authentication object when it is required. Calling this function, will not itself generate cookies or session ids. .SH "CGI::Application CALLBACKS" .IX Header "CGI::Application CALLBACKS" .SS "prerun_callback" .IX Subsection "prerun_callback" This method is a CGI::Application prerun callback that will be automatically registered for you if you are using CGI::Application 4.0 or greater. If you are using an older version of CGI::Application you will have to create your own cgiapp_prerun method and make sure you call this method from there. .PP .Vb 2 \& sub cgiapp_prerun { \& my $self = shift; \& \& $self\->CGI::Application::Plugin::Authentication::prerun_callback(); \& } .Ve .SH "CGI::Application RUNMODES" .IX Header "CGI::Application RUNMODES" .SS "authen_login_runmode" .IX Subsection "authen_login_runmode" This runmode is provided if you do not want to create your own login runmode. It will display a simple login form for the user, which can be replaced by assigning \s-1RENDER_LOGIN\s0 a coderef that returns the \s-1HTML.\s0 .SS "authen_dummy_redirect" .IX Subsection "authen_dummy_redirect" This runmode is provided for convenience when an external redirect needs to be done. It just returns an empty string. .SH "EXAMPLE" .IX Header "EXAMPLE" In a CGI::Application module: .PP .Vb 4 \& use base qw(CGI::Application); \& use CGI::Application::Plugin::AutoRunmode; \& use CGI::Application::Plugin::Session; \& use CGI::Application::Plugin::Authentication; \& \& _\|_PACKAGE_\|_\->authen\->config( \& DRIVER => [ \*(AqGeneric\*(Aq, { user1 => \*(Aq123\*(Aq } ], \& STORE => \*(AqSession\*(Aq, \& LOGOUT_RUNMODE => \*(Aqstart\*(Aq, \& ); \& _\|_PACKAGE_\|_\->authen\->protected_runmodes(qr/^auth_/, \*(Aqone\*(Aq); \& \& sub start : RunMode { \& my $self = shift; \& \& } \& \& sub one : RunMode { \& my $self = shift; \& \& # The user will only get here if they are logged in \& } \& \& sub auth_two : RunMode { \& my $self = shift; \& \& # This is also protected because of the \& # regexp call to protected_runmodes above \& } .Ve .SH "COMPATIBILITY WITH CGI::Application::Plugin::ActionDispatch" .IX Header "COMPATIBILITY WITH CGI::Application::Plugin::ActionDispatch" The prerun callback has been modified so that it will check for the presence of a prerun mode. This is for compatibility with CGI::Application::Plugin::ActionDispatch. This change should be considered experimental. It is necessary to load the ActionDispatch module so that the two prerun callbacks will be called in the correct order. .SH "RECOMMENDED USAGE" .IX Header "RECOMMENDED USAGE" .IP "\s-1CSS\s0" 4 .IX Item "CSS" The best practice nowadays is generally considered to be to not have \s-1CSS\s0 embedded in \s-1HTML.\s0 Thus it should be best to set \s-1LOGIN_FORM\s0 \-> \s-1DISPLAY_CLASS\s0 to \&'Basic'. .IP "Post login destination" 4 .IX Item "Post login destination" Of the various means of selecting a post login destination the most secure would seem to be \s-1POST_LOGIN_URL.\s0 The \f(CW\*(C`destination\*(C'\fR parameter could potentially be hijacked by hackers. The \s-1POST_LOGIN_RUNMODE\s0 parameter requires a hidden parameter that could potentially be hijacked. .IP "Taint mode" 4 .IX Item "Taint mode" Do run your code under taint mode. It should help protect your application against a number of attacks. .IP "\s-1URL\s0 and username checking" 4 .IX Item "URL and username checking" Please set the \f(CW\*(C`DETAINT_URL_REGEXP\*(C'\fR and \f(CW\*(C`DETAINT_USERNAME_REGEXP\*(C'\fR parameters as tightly as possible. In particular you should prevent the destination parameter being used to redirect authenticated users to external sites; unless of course that is what you want in which case that site should be the only possible external site. .IP "The login form" 4 .IX Item "The login form" The \s-1HTML\s0 currently generated does not seem to be standards compliant as per \&\s-1RT\s0 bug 58023. Also the default login form includes hidden forms which could conceivably be hijacked. Set \s-1LOGIN_FORM\s0 \-> \s-1DISPLAY_CLASS\s0 to 'Basic' to fix this. .SH "TODO" .IX Header "TODO" There are lots of things that can still be done to improve this plugin. If anyone else is interested in helping out feel free to dig right in. Many of these things don't need my input, but if you want to avoid duplicated efforts, send me a note, and I'll let you know of anyone else is working in the same area. .IP "review the code for security bugs and report" 4 .IX Item "review the code for security bugs and report" .PD 0 .IP "complete the separation of presentation and logic" 4 .IX Item "complete the separation of presentation and logic" .IP "write a tutorial" 4 .IX Item "write a tutorial" .IP "build more Drivers (Class::DBI, \s-1LDAP,\s0 Radius, etc...)" 4 .IX Item "build more Drivers (Class::DBI, LDAP, Radius, etc...)" .IP "Add support for method attributes to identify runmodes that require authentication" 4 .IX Item "Add support for method attributes to identify runmodes that require authentication" .IP "finish the test suite" 4 .IX Item "finish the test suite" .IP "provide more example code" 4 .IX Item "provide more example code" .IP "clean up the documentation" 4 .IX Item "clean up the documentation" .IP "build a \s-1DB\s0 driver that builds it's own table structure. This can be used by people that don't have their own user database to work with, and could include a simple user management application." 4 .IX Item "build a DB driver that builds it's own table structure. This can be used by people that don't have their own user database to work with, and could include a simple user management application." .PD .SH "BUGS" .IX Header "BUGS" This is alpha software and as such, the features and interface are subject to change. So please check the Changes file when upgrading. .PP Some of the test scripts appear to be incompatible with versions of Devel::Cover later than 0.65. .SH "SEE ALSO" .IX Header "SEE ALSO" CGI::Application, \fBperl\fR\|(1) .SH "AUTHOR" .IX Header "AUTHOR" Author: Cees Hek ; Co-maintainer: Nicholas Bamber . .SH "CREDITS" .IX Header "CREDITS" Thanks to SiteSuite for funding the development of this plugin and for releasing it to the world. .PP Thanks to Christian Walde for suggesting changes to fix the incompatibility with CGI::Application::Plugin::ActionDispatch and for help with github. .PP Thanks to Alexandr Ciornii for pointing out some typos. .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (c) 2005, SiteSuite. All rights reserved. Copyright (c) 2010, Nicholas Bamber. (Portions of the code). .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The background images in the default login forms are used courtesy of www.famfamfam.com . Those icons are issued under the Creative Commons Attribution 3.0 License . Those icons are copyrighted 2006 by Mark James .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