Difference between revisions of "Gbrowse/authentication plugins/testauthenticator"

From GMOD
Jump to: navigation, search
(yes, it's true, I love myself... I give up)
(I got there in teh end)
Line 1: Line 1:
 
The TestAuthenticator plugin is used for testing the GBrowse authentication system. The entire module's code looks like this:
 
The TestAuthenticator plugin is used for testing the GBrowse authentication system. The entire module's code looks like this:
  
<source lang="perl">
+
<perl>
 
  package Bio::Graphics::Browser2::Plugin::TestAuthenticator;
 
  package Bio::Graphics::Browser2::Plugin::TestAuthenticator;
 
  use strict;
 
  use strict;
Line 14: Line 14:
  
 
  1;
 
  1;
</source>
+
</perl>
  
 
The idea is very simple. The module inherits from Bio::Graphics::Browser2::Plugin::AuthPlugin, a "template" module that does the hard work. It then overrides the authenticate() method, which does the actual matching of username and password. The call to $self->credentials() returns a username and password previously entered into the login dialog box. We return false unless the username is "lincoln" and the password is "foobar". Otherwise, we return a two-element list consisting of the username and the user's full name.
 
The idea is very simple. The module inherits from Bio::Graphics::Browser2::Plugin::AuthPlugin, a "template" module that does the hard work. It then overrides the authenticate() method, which does the actual matching of username and password. The call to $self->credentials() returns a username and password previously entered into the login dialog box. We return false unless the username is "lincoln" and the password is "foobar". Otherwise, we return a two-element list consisting of the username and the user's full name.

Revision as of 14:22, 5 May 2011

The TestAuthenticator plugin is used for testing the GBrowse authentication system. The entire module's code looks like this:

<perl>

package Bio::Graphics::Browser2::Plugin::TestAuthenticator;
use strict;
use base 'Bio::Graphics::Browser2::Plugin::AuthPlugin';
sub authenticate {
   my $self = shift;
   my ($name,$password) = $self->credentials;
   return unless $name eq 'lincoln' && $password eq 'foobar';
   return ($name,'Lincoln Stein');  # username, fullname
}
1;

</perl>

The idea is very simple. The module inherits from Bio::Graphics::Browser2::Plugin::AuthPlugin, a "template" module that does the hard work. It then overrides the authenticate() method, which does the actual matching of username and password. The call to $self->credentials() returns a username and password previously entered into the login dialog box. We return false unless the username is "lincoln" and the password is "foobar". Otherwise, we return a two-element list consisting of the username and the user's full name.

Run perldoc Bio::Graphics::Browser2::Plugin::AuthPlugin for information on how to write more sophisticated authentication plugins.