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

filter: Statementstmt 86.0% 68 / 79 Branchbran 73.3% 22 / 30 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 7 totaltotal 76.2% 106 / 139 CC 18 SCAR 20.6
CC
18
Cov
81%
extractFormInfo
16.5
get_user_from_req
4.0
auth_route
2.2
CRAP 7.8
« blib/lib/Lemonldap/NG/Portal/2F/Okta.pm ↑ Summary scripts/downloadSamlMetadata »
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(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 PE_CERTIFICATEREQUIRED
7 PE_ERROR
8 PE_BADCERTIFICATE
9 PE_FIRSTACCESS
10 PE_OK
11 6 );
12  
13 6 our $VERSION = '2.23.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 6 ▶ ( is => 'rw', lazy => 1, default => sub { $_[0]->conf->{SSLVar} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26 has issuer_var =>
27 6 ▶ ( 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 26 ▶sub init {
Subroutine init: called CC=2 SCAR=6.9
32 26 my ($self) = @_;
33 $self->AjaxInitScript( '<script type="application/init">{"sslHost":"'
34 . $self->conf->{sslHost}
35 . '"}</script>' )
36 26 ▶ if $self->conf->{sslByAjax};
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"sslByAjax"} 18 8 26
37 26 return 1;
38 }
39  
40 # Create authentication token so you can use 2FA, notifications, etc, with Ajax
41 4 ▶sub auth_route {
Subroutine auth_route: called CC=2 SCAR=7.9
Pod undocumented
42 4 my ( $self, $req ) = @_;
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 12 ▶sub get_user_from_req {
Subroutine get_user_from_req: called CC=4 SCAR=13.9
Pod undocumented
61 12 my ( $self, $req ) = @_;
62  
63 12 my $field = $self->subject_var;
64 12 my $issuer_var = $self->issuer_var;
65 12 ▶ if ( $req->env->{$issuer_var} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->env->{$issuer_var}) 7 5 12
66 $self->logger->debug(
67 7 'Received SSL issuer ' . $req->env->{$issuer_var} );
68  
69 7 ▶ if ( my $tmp = $self->conf->{SSLVarIf}->{ $req->env->{$issuer_var} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tmp = $self->conf->{"SSLVarIf"}{$req->env->{$issuer_var}}) 2 5 7
70 2 $field = $tmp;
71 }
72 }
73 12 my $value = $req->env->{$field};
74 12 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 11 1 12
75 11 $self->logger->debug("Using SSL environment variable $field");
76 }
77 else {
78 1 $self->logger->notice(
79 "No name found in certificate, check your configuration");
80 }
81  
82 12 return $value;
83 }
84  
85 # Read username in SSL environment variables, or return an error
86 # @return Lemonldap::NG::Portal constant
87 10 ▶sub extractFormInfo {
Subroutine extractFormInfo: called CC=12 SCAR=28.0
Pod undocumented
88 10 my ( $self, $req ) = @_;
89  
90 # If this is the ajax query, allow response to contain HTML code
91 # to update the portal error message
92 10 ▶ if ( $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantJSON) 7 3 10
93 7 $req->wantErrorRender(1);
94 }
95  
96 10 ▶ if ( $self->conf->{sslByAjax} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"sslByAjax"}) 5 5 10
97 5 my $token_id = $req->param('ajax_auth_token');
98 5 ▶ if ($token_id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_id) 2 3 5
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(
103 "Good SSL authentication for " . $user );
104 2 $req->user($user);
105 2 $req->data->{_Issuer} = $token->{extraInfo}->{_Issuer};
106 2 return PE_OK;
107 }
108 else {
109 0 return PE_ERROR;
110 }
111 }
112 }
113  
114 8 my $ssl_user = $self->get_user_from_req($req);
115  
116 8 ▶ if ( $ssl_user and $req->user($ssl_user) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ssl_user and $req->user($ssl_user)) { } 7 1 8
elsif ($req->env->{'SSL_CLIENT_S_DN'}) { } 0 1 1
elsif ($self->conf->{'sslByAjax'} and not $req->param('nossl')) { } 1 0 1
Condition66%2/3
$ssl_user and $req->user($ssl_user)
!ll&&!rl&&r
107
MC/DC50%1/2
$ssl_user and $req->user($ssl_user)
$ssl_user $req->user($ssl_user)
Truth table66%2/3
A and B
A= $ssl_userB= $req->user($ssl_user)
ABresult
0X0
100
111
117 7 $self->userLogger->notice(
118 "Good SSL authentication for " . $req->user );
119 7 $req->data->{_Issuer} = $req->env->{ $self->issuer_var };
120 7 return PE_OK;
121 }
122 elsif ( $req->env->{SSL_CLIENT_S_DN} ) {
123 0 return PE_BADCERTIFICATE;
124 }
125 ▶ elsif ( $self->conf->{sslByAjax} and not $req->param('nossl') ) {
Condition33%1/3
$self->conf->{"sslByAjax"} and not $req->param("nossl")
!ll&&!rl&&r
001
MC/DC0%0/2
$self->conf->{"sslByAjax"} and not $req->param("nossl")
$self->conf->{"sslByAjax"} not $req->param("nossl")
Truth table33%1/3
A and not(B)
A= $self->conf->{"sslByAjax"}B= not $req->param("nossl")
ABresult
0X0
100
111
126  
127 # If this is the AJAX query
128 1 ▶ if ( $req->wantJSON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->wantJSON) 0 1 1
129 0 return PE_CERTIFICATEREQUIRED;
130 }
131  
132 1 $self->initDisplay($req);
133 1 $req->data->{waitingMessage} = 1;
134 1 return PE_FIRSTACCESS;
135 }
136 else {
137 0 ▶ if ( $self->conf->{sslByAjax} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"sslByAjax"}) 0 0 0
138 0 $self->initDisplay($req);
139 0 return PE_BADCERTIFICATE;
140 }
141 0 $self->userLogger->warn('No certificate found');
142 0 return PE_CERTIFICATEREQUIRED;
143 }
144 }
145  
146 8 ▶sub authenticate {
Subroutine authenticate: called CC=1 SCAR=0.0
Pod undocumented
147 8 return PE_OK;
148 }
149  
150 8 ▶sub setAuthSessionInfo {
Subroutine setAuthSessionInfo: called CC=1 SCAR=0.0
Pod undocumented
151 8 my ( $self, $req ) = @_;
152 8 $req->sessionInfo->{authenticationLevel} = $self->conf->{SSLAuthnLevel};
153 8 $req->sessionInfo->{_Issuer} = $req->data->{_Issuer};
154 8 return PE_OK;
155 }
156  
157 4 ▶sub getDisplayType {
Subroutine getDisplayType: called CC=2 SCAR=7.2
Pod undocumented
158 4 my ($self) = @_;
159 4 ▶ return ( $self->{conf}->{sslByAjax} ? "sslform" : "logo" );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'conf'}{'sslByAjax'} ? : 4 0 4
160 }
161  
162 0 ▶sub authLogout {
Subroutine authLogout: not called CC=1 SCAR=6.9
Pod undocumented
163 0 return PE_OK;
164 }
165  
166 6 1;
« blib/lib/Lemonldap/NG/Portal/2F/Okta.pm ↑ Summary scripts/downloadSamlMetadata »