blib/lib/Lemonldap/NG/Portal/Auth/SSL.pm

filter: Statementstmt 70.8% 56 / 79 Branchbran 36.6% 11 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 7 totaltotal 56.8% 79 / 139 CC 18 SCAR 32.6
CC
18
Cov
58%
extractFormInfo
62.2
get_user_from_req
4.3
auth_route
2.2
CRAP 26.2
« blib/lib/Lemonldap/NG/Portal/Plugins/Refresh.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Key.pm »
1 package Lemonldap::NG::Portal::Auth::SSL;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 use Lemonldap::NG::Portal::Main::Constants qw(
6 PE_CERTIFICATEREQUIRED
7 PE_ERROR
8 PE_BADCERTIFICATE
9 PE_FIRSTACCESS
10 PE_OK
11 6 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 our $VERSION = '2.22.0';
14  
15 6 extends 'Lemonldap::NG::Portal::Main::Auth';
16  
17 # INITIALIZATION
18  
19 6 has AjaxInitScript => ( is => 'rw', default => '' );
20 6 has Name => ( is => 'ro', default => 'SSL' );
21  
22 6 has auth_id => ( is => 'ro', default => 'ssl' );
23  
24 has subject_var =>
25 2 ▶ ( is => 'rw', lazy => 1, default => sub { $_[0]->conf->{SSLVar} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26 has issuer_var =>
27 2 ▶ ( is => 'rw', lazy => 1, default => sub { $_[0]->conf->{SSLIssuerVar} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 6 with 'Lemonldap::NG::Portal::Auth::_Ajax';
30  
31 sub init {
32 8 ▶ my ($self) = @_;
Subroutine init: called CC=2 SCAR=6.9
33 $self->AjaxInitScript( '<script type="application/init">{"sslHost":"'
34 . $self->conf->{sslHost}
35 . '"}</script>' )
36 8 ▶ if $self->conf->{sslByAjax};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"sslByAjax"} 3 5 8
37 8 return 1;
38 }
39  
40 # Create authentication token so you can use 2FA, notifications, etc, with Ajax
41 sub auth_route {
42 4 ▶ my ( $self, $req ) = @_;
Subroutine auth_route: called CC=2 SCAR=7.9
Pod undocumented
43  
44 4 my $ssl_user = $self->get_user_from_req($req);
45 4 ▶ if ($ssl_user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ssl_user) { } 4 0 4
46 return $self->ajax_success(
47 $req,
48 $ssl_user,
49 {
50 4 _Issuer => $req->env->{ $self->issuer_var },
51 }
52 );
53 }
54 else {
55 0 $req->wantErrorRender(1);
56 0 return $self->p->doPE($req, PE_CERTIFICATEREQUIRED);
57 }
58 }
59  
60 sub get_user_from_req {
61 4 ▶ my ( $self, $req ) = @_;
Subroutine get_user_from_req: called CC=4 SCAR=14.7
Pod undocumented
62  
63 4 my $field = $self->subject_var;
64 4 my $issuer_var = $self->issuer_var;
65 4 ▶ if ( $req->env->{$issuer_var} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->env->{$issuer_var}) 4 0 4
66 $self->logger->debug(
67 4 'Received SSL issuer ' . $req->env->{$issuer_var} );
68  
69 4 ▶ if ( my $tmp = $self->conf->{SSLVarIf}->{ $req->env->{$issuer_var} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tmp = $self->conf->{"SSLVarIf"}{$req->env->{$issuer_var}}) 0 4 4
70 0 $field = $tmp;
71 }
72 }
73 4 my $value = $req->env->{$field};
74 4 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 4 0 4
75 4 $self->logger->debug("Using SSL environment variable $field");
76 }
77 else {
78 0 $self->logger->notice(
79 "No name found in certificate, check your configuration");
80 }
81  
82 4 return $value;
83 }
84  
85 # Read username in SSL environment variables, or return an error
86 # @return Lemonldap::NG::Portal constant
87 sub extractFormInfo {
88 2 ▶ my ( $self, $req ) = @_;
Subroutine extractFormInfo: called CC=12 SCAR=41.3
Pod undocumented
89  
90 # If this is the ajax query, allow response to contain HTML code
91 # to update the portal error message
92 2 ▶ if ( $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantJSON) 0 2 2
93 0 $req->wantErrorRender(1);
94 }
95  
96 2 ▶ if ($self->conf->{sslByAjax}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"sslByAjax"}) 2 0 2
97 2 my $token_id = $req->param('ajax_auth_token');
98 2 ▶ if ($token_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_id) 2 0 2
99 2 my $token = $self->get_auth_token( $req, $token_id );
100 2 ▶ if ( $token->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'user'}) { } 2 0 2
101 2 my $user = $token->{user};
102 2 $self->userLogger->notice( "Good SSL authentication for " . $user );
103 2 $req->user($user);
104 2 $req->data->{_Issuer} = $token->{extraInfo}->{_Issuer};
105 2 return PE_OK;
106 }
107 else {
108 0 return PE_ERROR;
109 }
110 }
111 }
112  
113 0 my $ssl_user = $self->get_user_from_req($req);
114  
115 0 ▶ if ( $ssl_user and $req->user($ssl_user) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ssl_user and $req->user($ssl_user)) { } 0 0 0
elsif ($req->env->{'SSL_CLIENT_S_DN'}) { } 0 0 0
elsif ($self->conf->{'sslByAjax'} and not $req->param('nossl')) { } 0 0 0
Condition0%0/3
$ssl_user and $req->user($ssl_user)
!ll&&!rl&&r
000
MC/DC0%0/2
$ssl_user and $req->user($ssl_user)
$ssl_user $req->user($ssl_user)
Truth table0%0/3
A and B
A= $ssl_userB= $req->user($ssl_user)
ABresult
0X0
100
111
116 0 $self->userLogger->notice( "Good SSL authentication for " . $req->user );
117 0 $req->data->{_Issuer} = $req->env->{ $self->issuer_var };
118 0 return PE_OK;
119 }
120 elsif ( $req->env->{SSL_CLIENT_S_DN} ) {
121 0 return PE_BADCERTIFICATE;
122 }
123 ▶ elsif ( $self->conf->{sslByAjax} and not $req->param('nossl') ) {
Condition0%0/3
$self->conf->{"sslByAjax"} and not $req->param("nossl")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->conf->{"sslByAjax"} and not $req->param("nossl")
$self->conf->{"sslByAjax"} not $req->param("nossl")
Truth table0%0/3
A and not(B)
A= $self->conf->{"sslByAjax"}B= not $req->param("nossl")
ABresult
0X0
100
111
124  
125 # If this is the AJAX query
126 0 ▶ if ( $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantJSON) 0 0 0
127 0 return PE_CERTIFICATEREQUIRED;
128 }
129  
130 0 $self->initDisplay($req);
131 0 $req->data->{waitingMessage} = 1;
132 0 return PE_FIRSTACCESS;
133 }
134 else {
135 0 ▶ if ( $self->conf->{sslByAjax} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"sslByAjax"}) 0 0 0
136 0 $self->initDisplay($req);
137 0 return PE_BADCERTIFICATE;
138 }
139 0 $self->userLogger->warn('No certificate found');
140 0 return PE_CERTIFICATEREQUIRED;
141 }
142 }
143  
144 sub authenticate {
145 1 ▶ return PE_OK;
Subroutine authenticate: called CC=1 SCAR=0.0
Pod undocumented
146 }
147  
148 sub setAuthSessionInfo {
149 1 ▶ my ( $self, $req ) = @_;
Subroutine setAuthSessionInfo: called CC=1 SCAR=0.0
Pod undocumented
150 1 $req->sessionInfo->{authenticationLevel} = $self->conf->{SSLAuthnLevel};
151 1 $req->sessionInfo->{_Issuer} = $req->data->{_Issuer};
152 1 return PE_OK;
153 }
154  
155 sub getDisplayType {
156 2 ▶ my ($self) = @_;
Subroutine getDisplayType: called CC=2 SCAR=7.2
Pod undocumented
157 2 ▶ return ( $self->{conf}->{sslByAjax} ? "sslform" : "logo" );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'conf'}{'sslByAjax'} ? : 2 0 2
158 }
159  
160 sub authLogout {
161 0 ▶ return PE_OK;
Subroutine authLogout: not called CC=1 SCAR=6.9
Pod undocumented
162 }
163  
164 6 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/Refresh.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Lib/Key.pm »