File Coverage

blib/lib/CGI/Application/Plugin/Authentication/Display.pm
Criterion Covered Total %
statement 41 41 100.0
branch 4 4 100.0
condition 4 4 100.0
subroutine 16 16 100.0
pod 11 11 100.0
total 76 76 100.0


line stmt bran cond sub pod time code
1             package CGI::Application::Plugin::Authentication::Display;
2             $CGI::Application::Plugin::Authentication::Display::VERSION = '0.21';
3 15     15   900 use 5.006;
  15         36  
4 15     15   63 use strict;
  15         20  
  15         323  
5 15     15   56 use warnings;
  15         19  
  15         403  
6 15     15   61 use Carp;
  15         25  
  15         6215  
7              
8             sub new {
9 66     66 1 91 my $class = shift;
10 66         91 my $self = {};
11 66         139 $self->{cgiapp} = shift;
12 66         102 bless $self, $class;
13 66         145 return $self;
14             }
15              
16             sub _cgiapp {
17 778     778   654 my $self = shift;
18 778         2097 return $self->{cgiapp};
19             }
20              
21             sub login_box {
22 1     1 1 38 my $self = shift;
23 1         17 croak "not implemented in base class";
24             }
25              
26             sub logout_form {
27 4     4 1 9 my $self = shift;
28 4 100       13 return 'Logout'
29             if $self->_cgiapp->authen->is_authenticated;
30 3         12 return '';
31             }
32              
33             sub enforce_protection {
34 3     3 1 72 my $self = shift;
35 3 100       8 croak "Attempt to bypass authentication on protected template"
36             if !$self->_cgiapp->authen->is_authenticated;
37 1         6 return "\n";
38             }
39              
40             sub is_authenticated {
41 4     4 1 9 my $self = shift;
42 4         13 return $self->_cgiapp->authen->is_authenticated;
43             }
44              
45             sub username {
46 3     3 1 8 my $self = shift;
47 3         10 return $self->_cgiapp->authen->username;
48             }
49              
50             sub last_login {
51 3     3 1 6 my $self = shift;
52 3         9 return $self->_cgiapp->authen->last_login;
53             }
54              
55             sub last_access {
56 3     3 1 10 my $self = shift;
57 3         7 return $self->_cgiapp->authen->last_access;
58             }
59              
60             sub is_login_timeout {
61 3     3 1 6 my $self = shift;
62 3         10 return $self->_cgiapp->authen->is_login_timeout;
63             }
64              
65             sub login_attempts {
66 3     3 1 7 my $self = shift;
67 3         8 return $self->_cgiapp->authen->login_attempts;
68             }
69              
70             sub login_title {
71 67     67 1 3465 my $self = shift;
72 67   100     160 my $login_options = $self->_cgiapp->authen->_config->{LOGIN_FORM} || {};
73 67   100     473 return $login_options->{TITLE} || 'Sign In';
74             }
75              
76              
77             1;
78              
79             =head1 NAME
80              
81             CGI::Application::Plugin::Authentication::Display - Generate bits of HTML needed for authentication
82              
83             =head1 DESCRIPTION
84              
85             The purpose of this code is to keep display code away from the back-end of
86             authentication management. It is an abstract base class and must be used
87             in conjunction with derived classes. Those derived classes can be used
88             in an number of ways:
89              
90             =over
91              
92             =item
93              
94             The subclass L
95             is provided to ensure backwards compatibility with the old code. It has
96             the advantage of working out of the box but still retaining flexibility.
97              
98             =item
99              
100             The subclass L
101             is provided to ensure XHTML compliance and to leave styling to CSS style-sheets.
102              
103             =item
104              
105             You can handle all the HTML side yourself in which case this code is not even loaded.
106              
107             =item
108              
109             You can use derived classes in templates that have dot support, which keeps
110             the display code close to the templates. This has other advantages. For example
111             one can use the C method to mark a template as being
112             only viewable after authentication. A number of other methods can be called
113             from the template that provide information about the authentication status.
114              
115             =back
116              
117             =head1 METHODS
118              
119             =head2 new
120              
121             The constructor must be passed the L object as the first
122             non-object argument. This allows derived modules to access the
123             authentication information.
124              
125             =head2 login_box
126              
127             This method will return the HTML for a login box that can be
128             embedded into another page. This is the same login box that is used
129             in the default authen_login runmode that the plugin provides.
130              
131             This function is not implemented in this module. One must use a derived class
132             with an appropriate implementation of this function.
133              
134             =head2 logout_form
135              
136             This returns the simple bit of HTML need to have a logout button. The form
137             has '/?authen_logout=1' as the action but of course this can be changed in
138             derived modules.
139              
140             =head2 enforce_protection
141              
142             This method is useful when the class is being used in templates to mark a
143             certain template as for authenticated eyes only. So in
144             L one might have
145              
146            
147            
148             and one must set C to one of these objects via the
149             C method. If authenticated it will resolve to a
150             simple string, otherwise it will croak.
151              
152             =head2 login_title
153              
154             This returns the I parameter from the I<LOGIN_FORM> section of the config. </td> </tr> <tr> <td class="h" > <a name="155">155</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="156">156</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 is_authenticated </td> </tr> <tr> <td class="h" > <a name="157">157</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="158">158</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 username </td> </tr> <tr> <td class="h" > <a name="159">159</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="160">160</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 last_login </td> </tr> <tr> <td class="h" > <a name="161">161</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="162">162</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 last_access </td> </tr> <tr> <td class="h" > <a name="163">163</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="164">164</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 is_login_timeout </td> </tr> <tr> <td class="h" > <a name="165">165</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="166">166</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head2 login_attempts </td> </tr> <tr> <td class="h" > <a name="167">167</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="168">168</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> These methods all provide access to the cognate methods on the authentication </td> </tr> <tr> <td class="h" > <a name="169">169</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> object. They are provided as templates might find them expressive. </td> </tr> <tr> <td class="h" > <a name="170">170</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="171">171</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 BUGS </td> </tr> <tr> <td class="h" > <a name="172">172</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="173">173</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> This is alpha software and as such, the features and interface </td> </tr> <tr> <td class="h" > <a name="174">174</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> are subject to change. So please check the Changes file when upgrading. </td> </tr> <tr> <td class="h" > <a name="175">175</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="176">176</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 SEE ALSO </td> </tr> <tr> <td class="h" > <a name="177">177</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="178">178</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> L<CGI::Application>, perl(1) </td> </tr> <tr> <td class="h" > <a name="179">179</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="180">180</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 AUTHOR </td> </tr> <tr> <td class="h" > <a name="181">181</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="182">182</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Author: Cees Hek <ceeshek@gmail.com>; Co-maintainer: Nicholas Bamber <nicholas@periapt.co.uk>. </td> </tr> <tr> <td class="h" > <a name="183">183</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="184">184</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 CREDITS </td> </tr> <tr> <td class="h" > <a name="185">185</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="186">186</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Thanks to SiteSuite (http://www.sitesuite.com.au) for funding the </td> </tr> <tr> <td class="h" > <a name="187">187</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> development of this plugin and for releasing it to the world. </td> </tr> <tr> <td class="h" > <a name="188">188</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="189">189</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Thanks to Christian Walde for suggesting changes to fix the incompatibility </td> </tr> <tr> <td class="h" > <a name="190">190</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> with L<CGI::Application::Plugin::ActionDispatch> and for help with github. </td> </tr> <tr> <td class="h" > <a name="191">191</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="192">192</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 LICENCE AND COPYRIGHT </td> </tr> <tr> <td class="h" > <a name="193">193</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="194">194</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Copyright (c) 2005, SiteSuite. All rights reserved. </td> </tr> <tr> <td class="h" > <a name="195">195</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> Copyright (c) 2010, Nicholas Bamber. All rights reserved. </td> </tr> <tr> <td class="h" > <a name="196">196</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="197">197</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. </td> </tr> <tr> <td class="h" > <a name="198">198</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="199">199</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =head1 DISCLAIMER OF WARRANTY </td> </tr> <tr> <td class="h" > <a name="200">200</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="201">201</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> BECAUSE 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 "AS IS" 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. </td> </tr> <tr> <td class="h" > <a name="202">202</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="203">203</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> IN 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 (INCLUDING 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), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. </td> </tr> <tr> <td class="h" > <a name="204">204</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="205">205</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> =cut </td> </tr> <tr> <td class="h" > <a name="206">206</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="207">207</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 1; </td> </tr> </table> </body> </html>