Uaf.pm

filter: Statementstmt 28.9% 22 / 76 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 6 / 16 Podpod 80.0% 8 / 10 totaltotal 28.1% 36 / 128 CC 13 SCAR 26.0
CC
13
Cov
22%
uaf_init
30.0
uaf_authenticate
30.0
get_callbacks
12.0
CRAP 13.4
↑ Summary Uaf/Authenticate.pm »
1 package Gantry::Plugins::Uaf;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Gantry;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Gantry::Utils::Crypt;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 our @EXPORT = qw(
12 uaf_init
13 uaf_user
14 uaf_authn
15 uaf_authz
16 uaf_inited
17 uaf_authenicate
18 do_login
19 do_logout
20 );
21  
22 2 our $VERSION = '0.03';
23 2 my %registered_callbacks;
24  
25 #-----------------------------------------------------------
26 # $class->get_callbacks( $namespace )
27 #-----------------------------------------------------------
28 0 ▶sub get_callbacks {
Subroutine get_callbacks: not called CC=3 SCAR=24.8
Pod documented
29 0 my ( $class, $namespace ) = @_;
30  
31 0 ▶ return if ( $registered_callbacks{ $namespace }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $registered_callbacks{$namespace}++ 0 0 0
32  
33 0 ▶ warn "Your app needs a 'namespace' method which doesn't return 'Gantry'"
Branch: 1 branch
BranchTrueFalseTotal
if $namespace eq "Gantry" 0 0 0
34 if ( $namespace eq 'Gantry' );
35  
36 return (
37 0 { phase => 'init', callback => \&initialize },
38 { phase => 'post_init', callback => \&uaf_authenticate }
39 );
40  
41 }
42  
43 #-----------------------------------------------------------
44 # initialize
45 #-----------------------------------------------------------
46 0 ▶sub initialize {
Subroutine initialize: not called CC=1 SCAR=6.9
Pod documented
47 0 my $gobj = shift;
48  
49 0 $gobj->uaf_init();
50  
51 }
52  
53 0 ▶sub uaf_init {
Subroutine uaf_init: not called CC=5 SCAR=34.0
Pod undocumented
54 0 my $gobj = shift;
55  
56 0 my @parts;
57 my $filename;
58 0 ▶ my $uaf_authn = $gobj->fish_config('uaf_authn_module') || 'Gantry::Plugins::Uaf::Authenticate';
Condition0%0/2
$gobj->fish_config('uaf_authn_module') || 'Gantry::Plugins::Uaf::Authenticate'
l!l
00
MC/DC0%0/1
$gobj->fish_config('uaf_authn_module') || 'Gantry::Plugins::Uaf::Authenticate'
$gobj->fish_config('uaf_authn_module')
Truth table0%0/2
A
A= $gobj->fish_config('uaf_authn_module')
Aresult
11
00
59 0 ▶ my $uaf_authz = $gobj->fish_config('uaf_authz_module') || 'Gantry::Plugins::Uaf::Authorize';
Condition0%0/2
$gobj->fish_config('uaf_authz_module') || 'Gantry::Plugins::Uaf::Authorize'
l!l
00
MC/DC0%0/1
$gobj->fish_config('uaf_authz_module') || 'Gantry::Plugins::Uaf::Authorize'
$gobj->fish_config('uaf_authz_module')
Truth table0%0/2
A
A= $gobj->fish_config('uaf_authz_module')
Aresult
11
00
60  
61 # load our authorization and authentication modules
62  
63 0 @parts = split('::', $uaf_authn);
64 0 $filename = File::Spec->catfile(@parts) . ".pm";
65  
66 0 eval {
67  
68 0 require $filename;
69 0 $uaf_authn->import();
70 0 $gobj->{_UAF_AUTHN_} = $uaf_authn->new($gobj);
71  
72 0 ▶ }; if ($@) { warn "authn died $@\n"; die "Unable to load $uaf_authn; $@"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
73  
74 0 @parts = split('::', $uaf_authz);
75 0 $filename = File::Spec->catfile(@parts) . ".pm";
76  
77 0 eval {
78  
79 0 require $filename;
80 0 $uaf_authz->import();
81 0 $gobj->{_UAF_AUTHZ_} = $uaf_authz->new($gobj);
82  
83 0 ▶ }; if ($@) { warn "authz died $@\n"; die "Unable to load $uaf_authz; $@"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
84  
85 0 $gobj->uaf_inited(1);
86  
87 }
88  
89 0 ▶sub uaf_authenticate {
Subroutine uaf_authenticate: not called CC=5 SCAR=34.0
Pod documented
90 0 my $gobj = shift;
91  
92 0 my $user;
93 0 my $regex = $gobj->uaf_authn->filter;
94  
95  
96 # authenticate the session, this happens with each access
97  
98 0 ▶ return if ($gobj->uri =~ /^$regex/);
Branch: 1 branch
BranchTrueFalseTotal
if $gobj->uri =~ /^$regex/ 0 0 0
99  
100 0 ▶ if ($gobj->uaf_authn->avoid()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gobj->uaf_authn->avoid) 0 0 0
101  
102 0 ▶ if ($gobj->session_lock()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gobj->session_lock) 0 0 0
103  
104 0 ▶ if (defined($user = $gobj->uaf_authn->is_valid())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($user = $gobj->uaf_authn->is_valid)) { } 0 0 0
105  
106 #
107 # Uncomment this line of code and you will get an everchanging
108 # security token. Some internet pundits consider this a
109 # "good thing". But in an xhr async environment you will get
110 # a rather nasty race condition. i.e. The browsers don't
111 # consistently update the cookies from xhr requests. While a
112 # standard page loads work quite nicely.
113 #
114 # --> $gobj->uaf_authn->set_token($user);
115 #
116 0 $gobj->uaf_user($user);
117 0 $gobj->session_unlock();
118  
119 } else {
120  
121 0 $gobj->session_unlock();
122 0 $gobj->uaf_authn->relocate($gobj->uaf_authn->login_rootp);
123
124 }
125
126 }
127  
128 }
129  
130 }
131  
132 0 ▶sub do_login {
Subroutine do_login: not called CC=1 SCAR=6.9
Pod documented
133 0 my ($gobj, $action) = @_;
134  
135 0 $gobj->uaf_authn->login($action);
136  
137 }
138  
139 0 ▶sub do_logout {
Subroutine do_logout: not called CC=1 SCAR=6.9
Pod documented
140 0 my $gobj = shift;
141  
142 0 $gobj->uaf_authn->logout();
143  
144 }
145  
146 # ---------------------------------------------------------------------
147 # Accessors
148 # ---------------------------------------------------------------------
149  
150 0 ▶sub uaf_authn {
Subroutine uaf_authn: not called CC=1 SCAR=6.9
Pod documented
151 0 my $gobj = shift;
152  
153 0 return $gobj->{_UAF_AUTHN_};
154  
155 }
156  
157 0 ▶sub uaf_authz {
Subroutine uaf_authz: not called CC=1 SCAR=6.9
Pod documented
158 0 my $gobj = shift;
159  
160 0 return $gobj->{_UAF_AUTHZ_};
161  
162 }
163  
164 0 ▶sub uaf_user {
Subroutine uaf_user: not called CC=2 SCAR=17.9
Pod documented
165 0 my ($gobj, $p) = @_;
166  
167 0 ▶ $gobj->{_UAF_USER_} = $p if (defined($p));
Branch: 1 branch
BranchTrueFalseTotal
if defined $p 0 0 0
168 0 return $gobj->{_UAF_USER_};
169  
170 }
171  
172 0 ▶sub uaf_inited {
Subroutine uaf_inited: not called CC=2 SCAR=17.9
Pod undocumented
173 0 my ($gobj, $p) = @_;
174  
175 0 ▶ $gobj->{_UAF_INITED_} = $p if (defined($p));
Branch: 1 branch
BranchTrueFalseTotal
if defined $p 0 0 0
176 0 return $gobj->{_UAF_INITED_};
177  
178 }
179  
180 2 1;
181  
182 __END__
↑ Summary Uaf/Authenticate.pm »