| 1 | # ABSTRACT: Dancer::Plugin::Auth::RBAC authentication via the Dancer configuration file! | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Dancer::Plugin::Auth::RBAC::Credentials::Config; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | $Dancer::Plugin::Auth::RBAC::Credentials::Config::VERSION = '1.110720'; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use base qw/Dancer::Plugin::Auth::RBAC::Credentials/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | sub authorize { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authorize: called CC=10 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | my ($self, $options, @arguments) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | my ($login, $password) = @arguments; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | my $settings = $Dancer::Plugin::Auth::RBAC::settings; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | if ($login) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # authorize a new account using supplied credentials | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | my $accounts = $options->{accounts}; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | unless ($password) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $self->errors('login and password are required'); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | if (defined $accounts->{$login}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | if (defined $accounts->{$login}->{password}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | if ($accounts->{$login}->{password} =~ /^$password$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | my $session_data = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | id => $login, | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | name => $accounts->{$login}->{name} || ucfirst($login), | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | login => $login, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | roles => [@{$accounts->{$login}->{roles}}], | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$accounts->{$login}{'name'} || ucfirst $login
MC/DC0%0/2
$accounts->{$login}{'name'} || ucfirst $login
$accounts->{$login}{'name'}
ucfirst $login
Truth table33%1/3
A || B
A= $accounts->{$login}{'name'}B= ucfirst $login
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | error => [] | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | return $self->credentials($session_data); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->errors('login and/or password is invalid'); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $self->errors('attempting to access as inaccessible account'); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->errors('login and/or password is invalid'); | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # check if current user session is authorized | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | my $user = $self->credentials; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (($user->{id} || $user->{login}) && !@{$user->{error}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$user->{"id"} || $user->{"login"} and not @{$user->{"error"};}
$user->{"id"} or $user->{"login"}
MC/DC0%0/3
$user->{"id"} || $user->{"login"} and not @{$user->{"error"};}
$user->{"id"}
$user->{"login"}
not @{$user->{"error"};}
Truth table20%1/5
A or B and not(C)
A= $user->{"id"}B= $user->{"login"}C= not @{$user->{"error"};}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return $user; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | $self->errors('you are not authorized', 'your session may have ended'); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||