blib/lib/Bio/Graphics/Browser2/Plugin/AuthPlugin.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 70 CC 1 SCAR 6.9
CC
1
Cov
0%
authenticate
2.0
user_in_group
2.0
authentication_hint
2.0
CRAP 2.0
1 package Bio::Graphics::Browser2::Plugin::AuthPlugin;
2 # $Id#
3  
4 =head1 NAME
5  
6 Bio::Graphics::Browser2::Plugin::AuthPlugin -- Base class for authentication plugins
7  
8 =head1 SYNOPSIS
9  
10 package Bio::Graphics::Browser2::Plugin::MyPlugin;
11 use base 'Bio::Graphics::Browser2::Plugin::AuthPlugin';
12  
13 sub authenticate {
14 my $self = shift;
15 my ($user,$password) = $self->credentials;
16 return unless $user eq 'george' && $password eq 'washington';
17 return ($user,'George Washington','george@whitehouse.gov');
18 }
19  
20 sub user_in_group {
21 my $self = shift;
22 my ($user,$group) = @_;
23 return $user eq 'george' && $group eq 'potomac';
24 }
25  
26 =head1 DESCRIPTION
27  
28 This is a template for authorizer plugins. To define a new type of
29 authorizer, you need only inherit from this class and define an
30 authenticate() method. This method takes two arguments: the username
31 and password and returns an empty list if authentication fails, or a
32 list of (username, fullname, email) if authentication succeeds (fullname
33 and email are optional).
34  
35 In addition, you may override the user_in_group() method, which takes
36 two argumetns: the username and group. Return true if the user belongs
37 to the group, and false otherwise.
38  
39 Other methods you may wish to override include:
40  
41 * authentication_hint()
42 * authentication_help()
43 * configure_form()
44 * reconfigure()
45 * credentials()
46  
47 These are described below.
48  
49 =cut
50  
51  
52 use strict;
53 use Bio::Graphics::Browser2::Plugin;
54 use Bio::Graphics::Browser2::Util 'shellwords';
55 use CGI qw(:standard);
56 use base 'Bio::Graphics::Browser2::Plugin';
57  
58 =head2 Methods you will need to override
59  
60 =over 4
61  
62 =item $boolean = $plugin->authenticate($username,$password)
63  
64 Return true if username and password are correct. False otherwise.
65  
66 =item $boolean = $plugin->user_in_group($username,$groupname)
67  
68 Return true if user belongs to group. False otherwise.
69  
70 =back
71  
72 =cut
73  
74 ######################################################33
75 # OVERRIDE THESE METHODS
76 ######################################################33
77 sub authenticate {
78 my $self = shift;
79 my ($name,$password) = $self->credentials;
80 return;
81 }
82 sub user_in_group {
83 my $self = shift;
84 my ($user,$group) = @_;
85 return;
86 }
87  
88 =head2 Methods that you may want to customize
89  
90 =over 4
91  
92 =item $message = $plugin->authentication_hint
93  
94 Returns a message printed at the top of the login dialog, that will
95 help the user know which credentials he is expected to present. For
96 example, returning "Acme Corp Single Sign-on" will present the user
97 with "Please log into your Acme Corp Single Sign-on".
98  
99 The default behavior is to take this value from the "login hint"
100 option in a stanza named [AuthPlugin:plugin]. Example:
101  
102 =item $message = $plugin->authentication_help
103  
104 Returns a message printed at the bottom of the login dialog. It is
105 expected to be used for a help message or link that will give the user
106 help with logging in. For example, it can take him to a link to reset
107 his password.
108  
109 The default behavior is to take this value from the "login help"
110 option in a stanza named [AuthPlugin:plugin].
111  
112 [AuthPlugin:plugin]
113 login hint = your Acme Corp Single Sign-on Account
114 login help = <a href="www.acme.com/passwd_help">Recover forgotten password</a>
115  
116 =back
117  
118 =cut
119  
120 ######################################################33
121 # YOU MAY CUSTOMIZE THESE METHODS
122 ######################################################33
123  
124 # use this to return a hint about what type of account is wanted
125 sub authentication_hint {
126 my $self = shift;
127 return $self->setting('login hint');
128 }
129 sub authentication_help {
130 my $self = shift;
131 return $self->setting('login help');
132 }
133  
134 sub name { "Authorizer Template" }
135 sub description {
136 p("This plugin implements a template authorizer.",
137 "It was written by Lincoln Stein.");
138 }
139  
140 sub type { 'authenticator' }
141  
142 =head2 Methods that you may want to override
143  
144 =over 4
145  
146 =item $html = $plugin->configure_form()
147  
148 This method returns the contents of the login form. The default
149 behavior is to produce two text fields, one named 'name' and the
150 other named 'password'.
151  
152 =item $plugin->reconfigure()
153  
154 This method is called to copy the values from the filled-out form into
155 the plugin's hash of configuration variables. If you add fields to
156 configure_form() will you need to adjust this method as well.
157  
158 =item $plugin->config_defaults()
159  
160 Set up defaults for the configuration hash. Use this if you wish to
161 default to a particular username.
162  
163 =item $plugin->credentials()
164  
165 This returns a two-element list containing the username and password
166 last entered into the authentication dialog. It reads these values
167 from the configuration hash returned by $self->configuration().
168 If you add additional types of credentials to the login dialog, you
169 may need to override this method.
170  
171 =back
172  
173 =cut
174  
175 sub config_defaults {
176 my $self = shift;
177 return { };
178 }
179  
180 sub reconfigure {
181 my $self = shift;
182 my $current_config = $self->configuration;
183 $current_config->{name} = $self->config_param('name');
184 $current_config->{pass} = $self->config_param('password');
185 }
186  
187 sub configure_form {
188 my $self = shift;
189 my $current_config = $self->configuration;
190 return table(
191 TR(th({-align=>'right'},'Name'),
192 td(textfield(-name => $self->config_name('name'),
193 -value => $current_config->{name},
194 -size => 20))),
195 TR(th({-align=>'right'},'Password'),
196 td(password_field(-name => $self->config_name('password'),
197 -value => '',
198 -override=>1,
199 -size => 20)))
200 );
201 }
202  
203 sub credentials {
204 my $self = shift;
205 my $current_config = $self->configuration;
206 return ($current_config->{name},
207 $current_config->{pass});
208 }
209  
210 1;
211  
212 __END__