Extensible/Provider/Unix.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 SCAR 24.8
CC
3
Cov
0%
get_user_details
6.0
get_user_roles
6.0
authenticate_user
2.0
CRAP 12.0
1 package Dancer::Plugin::Auth::Extensible::Provider::Unix;
2  
3 use strict;
4 use warnings;
5  
6 use base 'Dancer::Plugin::Auth::Extensible::Provider::Base';
7 use Authen::Simple::PAM;
8 use Unix::Passwd::File;
9  
10 =head1 NAME
11  
12 Dancer::Plugin::Auth::Extensible::Unix - authenticate *nix system accounts
13  
14 =head1 DESCRIPTION
15  
16 An authentication provider for L<Dancer::Plugin::Auth::Extensible> which
17 authenticates Linux/Unix system accounts.
18  
19 Uses L<Unix::Passwd::File> to read user details, and L<Authen::Simple::PAM> to
20 perform authentication via PAM.
21  
22 The C<get_user_details> call for this provider will return information from the
23 C<passwd> file - expect C<gecos>, C<gid>, C<uid>, C<home>, C<shell>, C<uid>.
24  
25 Unix group membership is used as a reasonable facsimile for roles - this seems
26 sensible.
27  
28 =cut
29  
30 sub authenticate_user {
31 my ($class, $username, $password) = @_;
32 my $pam = Authen::Simple::PAM->new( service => 'login' );
33 return $pam->authenticate($username, $password);
34 }
35
36  
37 sub get_user_details {
38 my ($class, $username) = @_;
39  
40 my $result = Unix::Passwd::File::get_user(
41 user => $username
42 );
43 return if $result->[0] != 200;
44 return $result->[2];
45 }
46  
47 sub get_user_roles {
48 my ($class, $username) = @_;
49 my $result = Unix::Passwd::File::get_user_groups(user => $username);
50 return if $result->[0] != 200;
51 return $result->[2];
52 }
53  
54 1;
55