File Coverage

blib/lib/Catalyst/Authentication/Credential/NoPassword.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Catalyst::Authentication::Credential::NoPassword;
2              
3 1     1   1708 use Moose;
  0            
  0            
4             use utf8;
5              
6             has 'realm' => (is => 'ro', required => 1);
7              
8             around BUILDARGS => sub {
9             my $orig = shift;
10             my $class = shift;
11              
12             if ( @_ == 3 ) {
13             my ($config, $app, $realm) = @_;
14             return $class->$orig( realm => $realm );
15             }
16             else {
17             return $class->$orig(@_);
18             }
19             };
20              
21             sub authenticate {
22             my ($self, $c, $realm, $authinfo) = @_;
23             $self->realm->find_user($authinfo, $c);
24             }
25              
26             1;
27              
28             __END__
29              
30             =head1 NAME
31              
32             Catalyst::Authentication::Credential::NoPassword - Authenticate a user
33             without a password.
34              
35             =head1 SYNOPSIS
36              
37             use Catalyst qw/
38             Authentication
39             /;
40              
41             package MyApp::Controller::Auth;
42              
43             sub login_as_another_user : Local {
44             my ($self, $c) = @_;
45              
46             if ($c->user_exists() and $c->user->username() eq 'root') {
47             $c->authenticate( {id => c->req->params->{user_id}}, 'nopassword' );
48             }
49             }
50              
51             =head1 DESCRIPTION
52              
53             This authentication credential checker takes authentication information
54             (most often a username) and retrieves the user from the store. No validation
55             of any credentials is done. This is intended for administrative backdoors,
56             SAML logins and so on when you have identified the new user by other means.
57              
58             =head1 CONFIGURATION
59              
60             # example
61             <Plugin::Authentication>
62             <nopassword>
63             <credential>
64             class = NoPassword
65             </credential>
66             <store>
67             class = DBIx::Class
68             user_model = DB::User
69             role_relation = roles
70             role_field = name
71             </store>
72             </nopassword>
73             </Plugin::Authentication>
74              
75             =head1 METHODS
76              
77             =head2 authenticate ( $c, $realm, $authinfo )
78              
79             Try to log a user in.
80              
81             =cut