blib/lib/Lemonldap/NG/Portal/2F/Radius.pm

filter: Statementstmt 41.5% 22 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 5 / 9 Podpod 33.3% 1 / 3 totaltotal 35.0% 28 / 80 CC 7 SCAR 25.6
CC
7
Cov
33%
verify
30.0
run
12.0
__ANON__
2.0
CRAP 13.0
« blib/lib/Lemonldap/NG/Portal/Auth/Radius.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/NewLocationWarning.pm »
1 package Lemonldap::NG::Portal::2F::Radius;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Lemonldap::NG::Portal::Lib::Radius;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 PE_OK
8 PE_ERROR
9 PE_BADOTP
10 PE_SENDRESPONSE
11 PE_MALFORMEDUSER
12 PE_RADIUSCONNECTFAILED
13 1 );
14  
15 1 our $VERSION = '2.21.0';
16  
17 1 extends 'Lemonldap::NG::Portal::Main::SecondFactor';
18  
19 # INITIALIZATION
20 has modulename => (
21 is => 'rw',
22 lazy => 1,
23 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 return $_[0]->prefix . "2f";
25 }
26 1 );
27  
28 1 has radiusLib => ( is => 'rw' );
29  
30 1 has prefix => ( is => 'rw', default => 'radius' );
31  
32 has initial_request => (
33 is => 'rw',
34 lazy => 1,
35 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 return $_[0]->conf->{radius2fSendInitialRequest};
37 }
38 1 );
39  
40 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
41 1 my ($self) = @_;
42 $self->radiusLib(
43 Lemonldap::NG::Portal::Lib::Radius->new(
44 radius_dictionary => $self->conf->{radius2fDictionaryFile},
45 radius_req_attribute_config =>
46 $self->conf->{radius2fRequestAttributes},
47 radius_secret => $self->conf->{radius2fSecret},
48 radius_server => $self->conf->{radius2fServer},
49 radius_timeout => $self->conf->{radius2fTimeout},
50 radius_msgauth => $self->conf->{radius2fMsgAuth},
51 1 modulename => ( $self->prefix . "2f" ),
52 logger => $self->logger,
53 p => $self->p,
54 )
55 );
56 1 return $self->SUPER::init();
57 }
58  
59 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
60 0 my ( $self, $req, $token ) = @_;
61 0 $self->logger->debug( $self->prefix . '2f: generate form' );
62  
63 0 my $session = $req->sessionInfo;
64 0 my $username = $session->{ $self->conf->{whatToTrace} };
65 0 ▶ if ( $self->initial_request ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->initial_request) 0 0 0
66 0 $self->logger->debug(
67 $self->prefix . "2f: sending empty Access-Request for $username" );
68 0 my $res = $self->radiusLib->check_pwd( $req, $session, $username );
69 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
70 0 return PE_RADIUSCONNECTFAILED;
71 }
72 }
73  
74 # Prepare form
75 0 my $tmp = $self->p->sendHtml(
76 $req,
77 'ext2fcheck',
78 params => {
79 TOKEN => $token,
80 PREFIX => $self->prefix,
81 TARGET => $self->p->relativeUrl(
82 $req,
83 $self->prefix . '2fcheck',
84 { skin => $self->p->getSkin($req) }
85 ),
86 LEGEND => 'enterRadius2fCode',
87 $self->get2fTplParams($req),
88 }
89 );
90 0 $self->logger->debug( $self->prefix . '2f: prepare verification' );
91  
92 0 $req->response($tmp);
93 0 return PE_SENDRESPONSE;
94 }
95  
96 0 ▶sub verify {
Subroutine verify: not called CC=5 SCAR=34.0
Pod undocumented
97 0 my ( $self, $req, $session ) = @_;
98  
99 # Some Radius Servers allow empty codes and perform
100 # out of band, interactive verification (InWebo...)
101 0 my $code = $req->param('code');
102  
103 # Launch Radius request
104 my $userAttr =
105 0 ▶ $self->conf->{radius2fUsernameSessionKey} || $self->conf->{whatToTrace};
Condition0%0/3
$self->conf->{'radius2fUsernameSessionKey'} || $self->conf->{'whatToTrace'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->conf->{'radius2fUsernameSessionKey'} || $self->conf->{'whatToTrace'}
$self->conf->{'radius2fUsernameSessionKey'} $self->conf->{'whatToTrace'}
Truth table0%0/3
A || B
A= $self->conf->{'radius2fUsernameSessionKey'}B= $self->conf->{'whatToTrace'}
ABresult
1X1
011
000
106 0 my $username = $session->{$userAttr};
107 0 ▶ unless ($username) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($username) 0 0 0
108 0 $self->logger->error( $self->prefix
109 . "2f: unable to find username from session attribute $userAttr"
110 );
111 0 return PE_MALFORMEDUSER;
112 }
113  
114 $self->logger->debug(
115 0 $self->prefix . "2f: checking credentials $username:$code" );
116  
117 0 my $res = $self->radiusLib->check_pwd( $req, $session, $username, $code );
118 0 ▶ unless ($res) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res) 0 0 0
119 0 return PE_RADIUSCONNECTFAILED;
120 }
121 0 ▶ unless ( $res->{result} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"result"} == 1) 0 0 0
122 $self->userLogger->warn( $self->prefix
123 . '2f: failed for '
124 0 . $session->{ $self->conf->{whatToTrace} } );
125 0 return PE_BADOTP;
126 }
127  
128 $self->logger->debug(
129 0 $self->prefix . '2f: credentials accepted by server' );
130 0 return PE_OK;
131 }
132  
133 1 1;
« blib/lib/Lemonldap/NG/Portal/Auth/Radius.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/NewLocationWarning.pm »