blib/lib/Lemonldap/NG/Portal/Plugins/RESTServer.pm

filter: Statementstmt 12.6% 43 / 341 Branchbran 7.3% 13 / 178 Conditioncond 1.9% 1 / 52 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 27.5% 8 / 29 Podpod 0.0% 0 / 18 totaltotal 9.9% 65 / 651 CC 111 SCAR 45.4
CC
111
Cov
10%
delKeyInMySession
306.0
newSession
156.0
pwdReset
156.0
CRAP 94.0
« blib/lib/Lemonldap/NG/Portal/Auth/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm »
1 # Session server plugin for REST requests
2 #
3 # This plugin adds the following entry points:
4 # - Sessions backend (if restSessionServer is on)
5 # * GET /sessions/<type>/<session-id> : get session data
6 # * GET /sessions/<type>/<session-id>/<key> : get a session key value
7 # * GET /sessions/<type>/<session-id>/[k1,k2] : get some session key value
8 # * POST /sessions/<type> : create a session
9 # * POST /sessions/<type>?all=1 : get all sessions (needs a token)
10 # * POST /sessions/<type>?all=1&search=uid,dwho: search all sessions where uid=dwho (needs a token)
11 # * PUT /sessions/<type>/<session-id> : update some keys
12 # * PUT /sessions/<type>/<session-id>/key1 : update key1
13 # * DELETE /sessions/<type>/<session-id> : delete a session
14 #
15 # Add a "hash=1" parameter in your query if store is hashed and session-id is the user value
16 #
17 # When the storage is hashed, and if those APIs are called with real IDs, not
18 # the storage IDs, it is required to add a "hash=1" parameter in the URL.
19 #
20 #
21 # - Sessions for connected users (if restSessionServer is on):
22 # * GET /session/my/<type> : get session data
23 # * GET /session/my/<type>/key : get session key
24 # * DELETE /session/my : ask for logout
25 # * DELETE /sessions/my : ask for global logout (if GlobalLogout plugin is on)
26 #
27 # - Authentication
28 # * POST /sessions/<type>/<session-id>?auth : authenticate with a fixed sessionId
29 # * Note that the "getCookie" method (authentification via SOAP) exists for
30 # REST requests directly by using '/' path : the portal recognize REST
31 # calls and generate JSON response instead of web page.
32 #
33 # - Configuration (if restConfigServer is on)
34 # * GET /config/latest : get the last config metadata
35 # * GET /config/<cfgNum> : get the metadata for config n° <cfgNum>
36 # * GET /config/<latest|cfgNum>/<key> : get conf key value
37 # * GET /config/<latest|cfgNum>?full : get the full configuration
38 # where <type> is the session type ("global" for SSO session or "persistent")
39 # * GET /error/<lang>/<errNum> : get <errNum> message reference and errors file <lang>.json
40 # Return 'en' error file if no <lang> specified
41 #
42 # - Endpoints for proxy auth/userdb/password
43 # * POST /proxy/getUser : get user attributes (restAuthServer)
44 # * POST /proxy/pwdReset : reset password (restPasswordServer)
45 # * POST /proxy/pwdConfirm : check password (restAuthServer or restPasswordServer)
46 #
47 # - Authorizations for connected users (always):
48 # * GET /mysession/?whoami : get "my" uid
49 # * GET /mysession/?authorizationfor=<base64-encoded-url>: ask if url is
50 # authorized
51 # * PUT /mysession/<type> : update some
52 # persistent data
53 # (restricted)
54 # * DELETE /mysession/<type>/key : delete key in data
55 # (restricted)
56 # * GET /myapplications : get my appplications
57 # list
58 #
59 # - Other (always)
60 # * /languages : get available languages
61 #
62 # There is no conflict with SOAP server, they can be used together
63  
64 package Lemonldap::NG::Portal::Plugins::RESTServer;
65  
66 105 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 105 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 105 ▶use JSON qw(from_json to_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
69 105 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 105 ▶use Lemonldap::NG::Common::Languages;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 105 ▶use Lemonldap::NG::Common::Session qw(id2storage reHashedKinds);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 105 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
73 URIRE
74 PE_OK
75 portalConsts
76 PE_PASSWORD_OK
77 105 );
78  
79 105 our $VERSION = '2.23.0';
80  
81 105 extends 'Lemonldap::NG::Portal::Main::Plugin';
82  
83 has configStorage => (
84 is => 'ro',
85 lazy => 1,
86 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 $_[0]->{p}->HANDLER->localConfig->{configStorage};
88 }
89 105 );
90 has exportedAttr => (
91 is => 'ro',
92 lazy => 1,
93 0 ▶ default => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
94 0 my %attributes;
95 0 my $conf = $_[0]->{conf};
96 0 ▶ if ( !$conf->{exportedAttr} || $conf->{exportedAttr} =~ /^\s*\+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $conf->{'exportedAttr'} or $conf->{'exportedAttr'} =~ /^\s*\+/) { } 0 0 0
Condition0%0/3
not $conf->{"exportedAttr"} or $conf->{"exportedAttr"} =~ /^\s*\+/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $conf->{"exportedAttr"} or $conf->{"exportedAttr"} =~ /^\s*\+/
not $conf->{"exportedAttr"} $conf->{"exportedAttr"} =~ /^\s*\+/
Truth table0%0/3
not(A) or B
A= not $conf->{"exportedAttr"}B= $conf->{"exportedAttr"} =~ /^\s*\+/
ABresult
1X1
011
000
97 0 my @attributes = qw(
98 _lastSeen _session_id _session_kind _startTime _utime
99 authenticationLevel groups ipAddr
100 );
101 0 ▶ if ( my $exportedAttr = $conf->{exportedAttr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exportedAttr = $conf->{'exportedAttr'}) { } 0 0 0
102 0 $exportedAttr =~ s/^\s*\+\s+//;
103 0 @attributes = ( @attributes, split /[,\s]+/, $exportedAttr );
104 }
105 else {
106 @attributes = (
107 @attributes,
108 0 keys %{ $conf->{macros} },
109 0 keys %{ $conf->{exportedVars} }
110 );
111 }
112  
113 # Dedup @attributes
114 0 %attributes = map { $_ => 1 } @attributes;
115 0 return '[' . join( ',', sort keys %attributes ) . ']';
116 }
117 else {
118 return
119 '['
120 0 . join( ',', sort split /[,\s]+/, $conf->{exportedAttr} ) . ']';
121 }
122 }
123 105 );
124 has ott => (
125 is => 'rw',
126 lazy => 1,
127 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
128 my $ott =
129 0 $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
130 0 $ott->timeout( $_[0]->conf->{formTimeout} );
131 0 return $ott;
132 }
133 105 );
134  
135 # INITIALIZATION
136  
137 331 ▶sub init {
Subroutine init: called CC=11 SCAR=27.0
Pod undocumented
138 331 my ($self) = @_;
139 331 my @parents = ('Lemonldap::NG::Portal::Main::Plugin');
140 331 my $add = 0;
141 331 ▶ if ( $self->conf->{restConfigServer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"restConfigServer"}) 0 331 331
142 0 push @parents, 'Lemonldap::NG::Common::Conf::RESTServer';
143 0 $add++;
144  
145 # Methods inherited from Lemonldap::NG::Common::Conf::RESTServer
146 0 $self->addUnauthRoute(
147 config => {
148 ':cfgNum' => [
149 qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes
150 applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
151 authChoiceModules grantSessionRules)
152 ]
153 },
154 ['GET'],
155 )
156  
157 ->addUnauthRoute(
158 config => { ':cfgNum' => { '*' => 'getKey' } },
159 ['GET']
160 )
161  
162 ->addUnauthRoute( error => { '*' => 'getError' }, ['GET'] );
163 }
164 331 ▶ if ( $self->conf->{restSessionServer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"restSessionServer"}) 112 219 331
165 112 push @parents, 'Lemonldap::NG::Common::Session::REST';
166 112 $add++;
167  
168 # Methods inherited from Lemonldap::NG::Common::Session::REST
169 $self->addUnauthRoute(
170 sessions => {
171 ':sessionType' => (
172 $self->conf->{restExportSecretKeys}
173 112 ▶ ? 'rawSession'
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'restExportSecretKeys'} ? : 16 96 112
174 : 'session'
175 )
176 },
177 ['GET']
178 )
179  
180 ->addUnauthRoute(
181 sessions => { ':sessionType' => 'newSession' },
182 ['POST']
183 )
184  
185 # Methods written below
186 ->addUnauthRoute(
187 sessions => { ':sessionType' => 'updateSession' },
188 ['PUT']
189 )
190  
191 ->addUnauthRoute(
192 sessions => { ':sessionType' => 'delSession' },
193 ['DELETE']
194 )
195  
196 ->addAuthRoute(
197 session => { my => { ':sessionType' => 'getMyKey' } },
198 [ 'GET', 'POST' ]
199 )
200  
201 ->addAuthRoute(
202 session => { my => 'removeSession' },
203 ['DELETE']
204 );
205  
206 112 ▶ if ( $self->conf->{globalLogoutRule} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"globalLogoutRule"}) 0 112 112
207 0 $self->addAuthRoute(
208 sessions => { my => 'removeSessions' },
209 ['DELETE']
210 );
211 }
212 }
213  
214 331 ▶ if ( $self->conf->{restPasswordServer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"restPasswordServer"}) 0 331 331
215 0 $self->addUnauthRoute(
216 proxy => {
217 'pwdReset' => 'pwdReset',
218 },
219 ['POST']
220 );
221 }
222  
223 331 ▶ if ( $self->conf->{restAuthServer} or $self->conf->{restPasswordServer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"restAuthServer"} or $self->conf->{"restPasswordServer"}) 0 331 331
Condition33%1/3
$self->conf->{"restAuthServer"} or $self->conf->{"restPasswordServer"}
l!l&&r!l&&!r
00331
MC/DC0%0/2
$self->conf->{"restAuthServer"} or $self->conf->{"restPasswordServer"}
$self->conf->{"restAuthServer"} $self->conf->{"restPasswordServer"}
Truth table33%1/3
A or B
A= $self->conf->{"restAuthServer"}B= $self->conf->{"restPasswordServer"}
ABresult
1X1
011
000
224 0 $self->addUnauthRoute(
225 proxy => {
226 'pwdConfirm' => 'pwdConfirm',
227 },
228 ['POST']
229 );
230 }
231  
232 331 ▶ if ( $self->conf->{restAuthServer} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"restAuthServer"}) 0 331 331
233 0 $self->addUnauthRoute(
234 proxy => {
235 'getUser' => 'getUser',
236 },
237 ['POST']
238 );
239 }
240  
241 # Methods always available
242 $self->addAuthRoute(
243 331 mysession => { '*' => 'mysession' },
244 [ 'GET', 'POST' ]
245 )
246  
247 ->addAuthRoute(
248 mysession => {
249 ':sessionType' =>
250 { ':key' => 'delKeyInMySession', '*' => 'delMySession' }
251 },
252 ['DELETE']
253 )
254  
255 ->addAuthRoute(
256 mysession => { ':sessionType' => 'updateMySession' },
257 ['PUT']
258 )
259  
260 ->addAuthRoute( myapplications => 'myApplications', ['GET'] )
261  
262 ->addAuthRoute( languages => 'languages', ['GET'] )
263 ->addUnauthRoute( languages => 'languages', ['GET'] );
264  
265 331 ▶ extends @parents if ($add);
Branch: 1 branch
BranchTrueFalseTotal
if $add 112 219 331
266 331 ▶ $self->setTypes( $self->conf ) if ( $self->conf->{restSessionServer} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->conf->{"restSessionServer"} 112 219 331
267  
268 331 return 1;
269 }
270  
271 0 ▶sub newSession {
Subroutine newSession: not called CC=12 SCAR=50.5
Pod undocumented
272 0 my ( $self, $req, $id ) = @_;
273  
274 # If id is defined
275 return $self->newAuthSession( $req, $id )
276 0 ▶ if ( $id and exists $req->parameters->{auth} );
Branch: 1 branch
BranchTrueFalseTotal
if $id and exists $req->parameters->{"auth"} 0 0 0
Condition0%0/3
$id and exists $req->parameters->{"auth"}
!ll&&!rl&&r
000
MC/DC0%0/2
$id and exists $req->parameters->{"auth"}
$id exists $req->parameters->{"auth"}
Truth table0%0/3
A and B
A= $idB= exists $req->parameters->{"auth"}
ABresult
0X0
100
111
277 0 ▶ my $mod = $self->getMod($req)
Branch: 1 branch
BranchTrueFalseTotal
my $mod = $self->getMod($req) or return $self->p->sendError($req, undef, 400) 0 0 0
278 or return $self->p->sendError( $req, undef, 400 );
279 0 ▶ my $infos = $req->jsonBodyToObj
Branch: 1 branch
BranchTrueFalseTotal
my $infos = $req->jsonBodyToObj or return $self->p->sendError($req, undef, 400) 0 0 0
280 or return $self->p->sendError( $req, undef, 400 );
281 0 $infos->{_utime} = time();
282  
283 0 my $secret = delete $infos->{__secret};
284 0 my $force = $self->_checkSecret($secret);
285  
286 0 ▶ if ( $req->param('all') and not $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("all") and not $id) 0 0 0
Condition0%0/3
$req->param("all") and not $id
!ll&&!rl&&r
000
MC/DC0%0/2
$req->param("all") and not $id
$req->param("all") not $id
Truth table0%0/3
A and not(B)
A= $req->param("all")B= not $id
ABresult
0X0
100
111
287 0 ▶ return $self->p->sendError( $req,
Branch: 1 branch
BranchTrueFalseTotal
unless $force 0 0 0
288 'Bad key, refuse to send all sessions', 400 )
289 unless ($force);
290 0 my $data = $infos->{data};
291 0 ▶ my $opts = $self->conf->{globalStorageOptions} || {};
Condition0%0/2
$self->conf->{'globalStorageOptions'} || {}
l!l
00
MC/DC0%0/1
$self->conf->{'globalStorageOptions'} || {}
$self->conf->{'globalStorageOptions'}
Truth table0%0/2
A
A= $self->conf->{'globalStorageOptions'}
Aresult
11
00
292 0 $opts->{backend} = $self->conf->{globalStorage};
293 0 my $sessions;
294 0 ▶ if ( my $query = $req->param('search') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $query = $req->param('search')) { } 0 0 0
295 0 my ( $field, @values ) = split /,/, $query;
296 0 ▶ $sessions = Lemonldap::NG::Common::Apache::Session->searchOn(
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
297 $opts, $field,
298 join( ',', @values ),
299 ( $data ? @$data : () )
300 );
301 }
302 else {
303 0 $sessions =
304 Lemonldap::NG::Common::Apache::Session
305 ->get_key_from_all_sessions( $opts, $data );
306 }
307 0 return $self->p->sendJSONresponse( $req, $sessions );
308 }
309  
310 # The "hashStore" here doesn't override configuration:
311 # Lemonldap::NG::Common::Session::REST module check the configuration
312 # parameter. So here it means "use hashed id if possible" and of course
313 # if session kind is OIDC or SSO
314 my $session = $self->getApacheSession(
315 $mod, $id,
316 info => $infos,
317 force => $force,
318 0 hashStore => ( $mod->{kind} =~ reHashedKinds ),
319 );
320 0 ▶ return $self->p->sendError( $req, 'Unable to create session', 500 )
Branch: 1 branch
BranchTrueFalseTotal
unless $session 0 0 0
321 unless ($session);
322  
323 0 $self->logger->debug(
324 "REST request create a new session (" . $session->id . ")" );
325  
326 0 return $self->p->sendJSONresponse( $req,
327 { result => 1, session => $session->data } );
328 }
329  
330 0 ▶sub newAuthSession {
Subroutine newAuthSession: not called CC=4 SCAR=30.0
Pod undocumented
331 0 my ( $self, $req, $id ) = @_;
332  
333 # Check secret
334 0 my $secret = $req->param('secret');
335 0 ▶ unless ( $self->_checkSecret($secret) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_checkSecret($secret)) 0 0 0
336 0 return $self->p->sendError( $req, 'Bad secret', 403 );
337 }
338  
339 0 $req->env->{AuthBasic} = 1;
340 0 $req->{id} = $id;
341 0 $req->{force} = 1;
342 0 $req->user( $req->param('user') );
343 0 $req->data->{password} = $req->param('password');
344 $req->steps( [
345 0 @{ $self->p->beforeAuth },
346 $self->p->authProcess,
347 0 @{ $self->p->betweenAuthAndData },
348 $self->p->sessionData,
349 0 @{ $self->p->afterData },
350 $self->p->validSession,
351 0 @{ $self->p->endAuth }
352 ]
353 );
354 0 $req->{error} = $self->p->process($req);
355 0 $self->logger->debug(
356 "REST authentication result for $req->{user}: code $req->{error}");
357  
358 0 ▶ if ( $req->error != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->error != 0) 0 0 0
359 0 $self->p->deleteSession($req);
360 0 return $self->p->sendError( $req, 'Unauthorized', 401 );
361 }
362 return $self->session( $req,
363 0 ▶ $self->conf->{hashedSessionStore} ? id2storage($id) : $id );
Branch: 1 branch
BranchTrueFalseTotal
$self->conf->{'hashedSessionStore'} ? : 0 0 0
364 }
365  
366 0 ▶sub updateSession {
Subroutine updateSession: not called CC=8 SCAR=42.8
Pod undocumented
367 0 my ( $self, $req, $id, $attr ) = @_;
368 0 $self->logger->debug("REST request to update session $id");
369 0 ▶ my $mod = $self->getMod($req)
Branch: 1 branch
BranchTrueFalseTotal
my $mod = $self->getMod($req) or return $self->p->sendError($req, undef, 400) 0 0 0
370 or return $self->p->sendError( $req, undef, 400 );
371 0 ▶ return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
372  
373 # Get new info
374 0 ▶ my $infos = $req->jsonBodyToObj
Branch: 1 branch
BranchTrueFalseTotal
my $infos = $req->jsonBodyToObj or return $self->p->sendError($req, undef, 400) 0 0 0
375 or return $self->p->sendError( $req, undef, 400 );
376  
377 0 ▶ $infos = { $attr => $infos } if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 0 0 0
378  
379 # Get secret if given
380 0 my $secret = delete $infos->{__secret};
381 0 my $force = $self->_checkSecret($secret);
382  
383 # Get session and store info
384 # The hashed store is used if explicitly asked and if session type is
385 # SSO or OIDC
386 my $session = $self->getApacheSession(
387 $mod, $id,
388 info => $infos,
389 force => $force,
390 hashStore => (
391 0 ▶ ( $mod->{kind} =~ reHashedKinds )
Branch: 2 branches
BranchTrueFalseTotal
my $session = $self->getApacheSession($mod, $id, "info", $infos, "force", $force, "hashStore", $mod->{"kind"} =~ reHashedKinds() ? $req->param("hash") // 0 : 0) or return $self->p->sendError($req, "Session Id does not exist", 400) 0 0 0
$mod->{'kind'} =~ reHashedKinds() ? : 0 0 0
Condition0%0/2
$req->param("hash") // 0
l!l
00
MC/DC0%0/1
$req->param("hash") // 0
$req->param("hash")
Truth table0%0/2
A
A= $req->param("hash")
Aresult
11
00
392 ? ( $req->param('hash') ) // 0
393 : 0
394 ),
395 ) or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
396  
397 0 return $self->p->sendJSONresponse( $req, { result => 1 } );
398 }
399  
400 0 ▶sub delSession {
Subroutine delSession: not called CC=6 SCAR=37.4
Pod undocumented
401 0 my ( $self, $req, $id ) = @_;
402 0 ▶ my $mod = $self->getMod($req)
Branch: 1 branch
BranchTrueFalseTotal
my $mod = $self->getMod($req) or return $self->p->sendError($req, undef, 400) 0 0 0
403 or return $self->p->sendError( $req, undef, 400 );
404 0 ▶ return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
405  
406 # Get session
407 # The hashed store is used if explicitly asked and if session type is
408 # SSO or OIDC
409 my $session = $self->getApacheSession(
410 $mod, $id,
411 hashStore => (
412 0 ▶ ( $mod->{kind} =~ reHashedKinds )
Branch: 2 branches
BranchTrueFalseTotal
my $session = $self->getApacheSession($mod, $id, "hashStore", $mod->{"kind"} =~ reHashedKinds() ? $req->param("hash") // 0 : 0) or return $self->p->sendError($req, "Session Id does not exist", 400) 0 0 0
$mod->{'kind'} =~ reHashedKinds() ? : 0 0 0
Condition0%0/2
$req->param("hash") // 0
l!l
00
MC/DC0%0/1
$req->param("hash") // 0
$req->param("hash")
Truth table0%0/2
A
A= $req->param("hash")
Aresult
11
00
413 ? ( $req->param('hash') ) // 0
414 : 0
415 ),
416 ) or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
417  
418 # Delete it
419 0 $self->logger->debug("REST request to delete session $id");
420 0 my $res = $self->p->_deleteSession( $req, $session );
421 0 $self->logger->debug(" Result is $res");
422  
423 0 return $self->p->sendJSONresponse( $req, { result => $res } );
424 }
425  
426 0 ▶sub delMySession {
Subroutine delMySession: not called CC=1 SCAR=6.9
Pod undocumented
427 0 my ( $self, $req, $id ) = @_;
428  
429 0 return $self->delSession( $req, $req->userData->{_session_id} );
430 }
431  
432 0 ▶sub mysession {
Subroutine mysession: not called CC=9 SCAR=45.0
Pod undocumented
433 0 my ( $self, $req ) = @_;
434  
435 # 1. whoami
436 return $self->p->sendJSONresponse( $req,
437 { result => $req->userData->{ $self->conf->{whatToTrace} } } )
438 0 ▶ if defined $req->param('whoami');
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->param("whoami") 0 0 0
439  
440 0 ▶ if ( defined $req->param('gettoken') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $req->param('gettoken')) { } 0 0 0
elsif (my $url = $req->param('authorizationfor')) { } 0 0 0
441 0 return $self->p->sendJSONresponse( $req,
442 { token => $self->ott->createToken() } );
443 }
444  
445 # Verify authorizationfor arg
446 elsif ( my $url = $req->param('authorizationfor') ) {
447  
448 # Verify that value is base64 encoded
449 0 ▶ return $self->p->sendError( $req, "Value must be in BASE64", 400 )
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ m[[^A-Za-z0-9\+/=]] 0 0 0
450 if ( $url =~ m#[^A-Za-z0-9\+/=]# );
451 0 $req->urldc( decode_base64($url) );
452  
453 # Check for XSS problems
454 0 ▶ return $self->p->sendError( $req, 'XSS attack detected', 400 )
Branch: 1 branch
BranchTrueFalseTotal
if $self->p->checkXSSAttack("authorizationfor", $req->urldc) 0 0 0
455 if ( $self->p->checkXSSAttack( 'authorizationfor', $req->urldc ) );
456  
457 # Split URL
458 0 my ( $host, $uri );
459 0 ▶ if ( $req->urldc =~ URIRE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->urldc =~ m[(((?^:https?))://((?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::((?:[0-9]*)))?(/(((?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():\@&=+\$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?]((?:(?:[;/?:\@&=+\$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)]) { } 0 0 0
460 0 ▶ ( $host, $uri ) = ( $3 . ( $4 ? ":$4" : '' ), $5 );
Branch: 1 branch
BranchTrueFalseTotal
$4 ? : 0 0 0
461 0 $uri = $self->p->HANDLER->canonicalUri($uri);
462 0 ▶ return $self->p->sendError( $req, "Bad URL $req->{urldc}", 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
463 unless ($host);
464 }
465 else {
466 0 return $self->p->sendError( $req, "Bad URL $req->{urldc}", 400 );
467 }
468  
469 0 $self->logger->debug("Looking for authorization for $url");
470  
471 # Now check for authorization
472 0 my $res =
473 $self->p->HANDLER->grant( $req, $req->userData, $uri, undef, $host );
474 0 $self->logger->debug(" Result is $res");
475 0 return $self->p->sendJSONresponse( $req, { result => $res } );
476 }
477  
478 0 return $self->p->sendError( $req,
479 'whoami or authorizationfor is required', 400 );
480 }
481  
482 0 ▶sub getMyKey {
Subroutine getMyKey: not called CC=5 SCAR=34.0
Pod undocumented
483 0 my ( $self, $req, $key ) = @_;
484  
485 # All /my/ API are called with user's session, so indicates here that
486 # it uses hashed store if available
487 0 $req->data->{hashStore} = 1;
488 0 ▶ $key ||= '';
Condition0%0/2
$key ||= ""
l!l
00
MC/DC0%0/1
$key ||= ""
$key
Truth table0%0/2
A
A= $key
Aresult
11
00
489 0 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 0 0 0
490 0 $self->logger->debug(
491 "REST request to get personal session attribute: $key");
492 }
493 else {
494 0 my $keys = $self->exportedAttr;
495 0 $keys =~ s/\[|\]//g;
496 0 $keys =~ s/,/, /g;
497 0 $self->logger->debug("REST request to get exported attributes: $keys");
498 }
499  
500 0 my $id = $req->userData->{_session_id};
501 0 ▶ $id = id2storage($id) if $req->userData->{_session_hashed};
Branch: 1 branch
BranchTrueFalseTotal
if $req->userData->{"_session_hashed"} 0 0 0
502 0 ▶ return $self->session( $req, $id, $key || $self->exportedAttr );
Condition0%0/3
$key || $self->exportedAttr
l!l&&r!l&&!r
000
MC/DC0%0/2
$key || $self->exportedAttr
$key $self->exportedAttr
Truth table0%0/3
A || B
A= $keyB= $self->exportedAttr
ABresult
1X1
011
000
503 }
504  
505 0 ▶sub updateMySession {
Subroutine updateMySession: not called CC=9 SCAR=45.0
Pod undocumented
506 0 my ( $self, $req ) = @_;
507  
508 # All /my/ API are called with user's session, so indicates here that
509 # it uses hashed store if available
510 0 $req->data->{hashStore} = 1;
511 0 my $res = 0;
512 0 my $mKeys = [];
513  
514 0 ▶ if ( my $token = $req->param('token') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $req->param('token')) { } 0 0 0
515 0 ▶ if ( $self->ott->getToken($token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ott->getToken($token)) { } 0 0 0
516 0 ▶ if ( $req->param('sessionType') eq 'persistent' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("sessionType") eq "persistent") 0 0 0
517 0 foreach
518 0 my $key ( @{ $self->conf->{mySessionAuthorizedRWKeys} } )
519 {
520 0 my $v;
521 0 ▶ if ( $key =~ /\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\*/) { } 0 0 0
522 0 $key =~ s/\*/\.\*/g;
523 0 ▶ if ( my ($k) = grep( /$key/, $req->params ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($k) = grep(/$key/, $req->params)) 0 0 0
524 0 $v = $req->param($k);
525 }
526 }
527 else {
528 0 $v = $req->param($key);
529 }
530 0 ▶ if ( defined $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
531 0 $res++;
532 0 push @$mKeys, $key;
533 0 $self->p->updatePersistentSession( $req,
534 { $key => $v } );
535 0 $self->logger->debug(
536 "Request to update session -> Key : $key");
537 }
538 }
539 }
540 }
541 else {
542 0 $self->logger->error('Update session request with invalid token');
543 }
544 }
545 else {
546 0 $self->logger->error('Update session request without token');
547 }
548  
549 0 ▶ return $self->p->sendError( $req, 'Modification refused', 403 ) unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
550 0 return $self->p->sendJSONresponse( $req,
551 { result => 1, count => $res, modifiedKeys => $mKeys } );
552 }
553  
554 0 ▶sub delKeyInMySession {
Subroutine delKeyInMySession: not called CC=17 SCAR=57.2
Pod undocumented
555 0 my ( $self, $req ) = @_;
556  
557 # All /my/ API are called with user's session, so indicates here that
558 # it uses hashed store if available
559 0 $req->data->{hashStore} = 1;
560 0 my $res = 0;
561 0 my $mKeys = [];
562 0 my $dkey = $req->param('key');
563 0 my $sub = $req->param('sub');
564  
565 0 ▶ if ( my $token = $req->param('token') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $req->param('token')) { } 0 0 0
566 0 ▶ if ( $self->ott->getToken($token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ott->getToken($token)) { } 0 0 0
567 0 ▶ if ( $req->param('sessionType') eq 'persistent' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("sessionType") eq "persistent") 0 0 0
568 0 foreach
569 0 my $key ( @{ $self->conf->{mySessionAuthorizedRWKeys} } )
570 {
571 0 ▶ if ( $key =~ /\*/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key =~ /\*/) { } 0 0 0
elsif ($dkey eq $key) { } 0 0 0
572 0 $key =~ s/\*/\.\*/g;
573 0 ▶ if ( $dkey =~ /^$key$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dkey =~ /^$key$/) 0 0 0
574 0 $res++;
575 }
576 }
577 elsif ( $dkey eq $key ) {
578 0 $res++;
579 }
580 }
581 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
582 0 ▶ if ( $dkey !~ /^_oidcConsents$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $dkey =~ /^_oidcConsents$/) { } 0 0 0
elsif ($dkey =~ /^_oidcConsents$/ and defined $sub) { } 0 0 0
583 0 $self->p->updatePersistentSession( $req,
584 { $dkey => undef } );
585 0 $self->logger->debug(
586 "Update session -> delete Key : $dkey");
587 }
588 ▶ elsif ( $dkey =~ /^_oidcConsents$/ and defined $sub ) {
Condition0%0/3
$dkey =~ /^_oidcConsents$/ and defined $sub
!ll&&!rl&&r
000
MC/DC0%0/2
$dkey =~ /^_oidcConsents$/ and defined $sub
$dkey =~ /^_oidcConsents$/ defined $sub
Truth table0%0/3
A and B
A= $dkey =~ /^_oidcConsents$/B= defined $sub
ABresult
0X0
100
111
589  
590 # Read existing oidcConsents
591 0 $self->logger->debug("Looking for OIDC Consents ...");
592 0 my $_oidcConsents;
593 0 ▶ if ( $req->userData->{_oidcConsents} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->userData->{'_oidcConsents'}) { } 0 0 0
594 0 $_oidcConsents = eval {
595 from_json( $req->userData->{_oidcConsents},
596 0 { allow_nonref => 1 } );
597 };
598 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
599 0 $self->logger->error(
600 "Corrupted session (_oidcConsents): $@");
601 0 return $self->p->sendError( $req,
602 "Corrupted session", 500 );
603 }
604 }
605 else {
606 0 $self->logger->debug("No OIDC Consent found");
607 0 $_oidcConsents = [];
608 }
609 0 my @keep = ();
610 0 ▶ while (@$_oidcConsents) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$_oidcConsents) 0 0 0
611 0 my $element = shift @$_oidcConsents;
612 0 $self->logger->debug(
613 "Looking for OIDC Consent to delete ...");
614 push @keep, $element
615 0 ▶ unless ( $element->{rp} eq $sub );
Branch: 1 branch
BranchTrueFalseTotal
unless $element->{"rp"} eq $sub 0 0 0
616 }
617 0 $self->p->updatePersistentSession( $req,
618 { _oidcConsents => to_json( \@keep ) } );
619 0 $self->logger->debug(
620 "Update session -> delete Key : $dkey with Sub : $sub"
621 );
622 }
623 else {
624 0 $self->logger->error(
625 'Update session request with invalid Key or Sub');
626 }
627 }
628 }
629 }
630 else {
631 0 $self->logger->error('Update session request with invalid token');
632 }
633 }
634 else {
635 0 $self->logger->error('Update session request without token');
636 }
637  
638 0 ▶ return $self->p->sendError( $req, 'Modification refused', 403 ) unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
639 0 return $self->p->sendJSONresponse( $req,
640 { result => 1, count => $res, modifiedKeys => $dkey } );
641 }
642  
643 0 ▶sub getError {
Subroutine getError: not called CC=5 SCAR=34.0
Pod undocumented
644 0 my ( $self, $req, $lang, $errNum ) = @_;
645 0 ▶ $lang ||= 'en';
Condition0%0/2
$lang ||= "en"
l!l
00
MC/DC0%0/1
$lang ||= "en"
$lang
Truth table0%0/2
A
A= $lang
Aresult
11
00
646 0 ▶ $errNum
Branch: 1 branch
BranchTrueFalseTotal
$errNum ? : 0 0 0
647 ? $self->logger->debug("Send $lang error file path with error: $errNum")
648 : $self->logger->debug("Send $lang error file path");
649  
650 0 ▶ return $self->p->sendJSONresponse(
Branch: 2 branches
BranchTrueFalseTotal
$errNum ? : 0 0 0
$errNum ? : 0 0 0
651 $req,
652 {
653 result => 1,
654 lang => $lang,
655 errorNum => $errNum ? $errNum : 'all',
656 errorsFileURL =>
657 "$self->{conf}->{staticPrefix}/languages/$lang.json",
658 ( $errNum ? ( errorMsgRef => "PE$errNum" ) : () )
659 }
660 );
661 }
662  
663 0 ▶sub removeSession {
Subroutine removeSession: not called CC=4 SCAR=30.0
Pod undocumented
664 0 my ( $self, $req ) = @_;
665 0 my $id = $req->userData->{_session_id};
666 0 ▶ return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
667 0 ▶ my $mod = $self->getGlobal()
Branch: 1 branch
BranchTrueFalseTotal
my $mod = $self->getGlobal or return $self->p->sendError($req, undef, 400) 0 0 0
668 or return $self->p->sendError( $req, undef, 400 );
669  
670 # Get session
671 my $session =
672 $self->getApacheSession( $mod, $id,
673 0 ▶ hashStore => ( $mod->{kind} =~ reHashedKinds ), )
Branch: 1 branch
BranchTrueFalseTotal
my $session = $self->getApacheSession($mod, $id, "hashStore", $mod->{"kind"} =~ reHashedKinds()) or return $self->p->sendError($req, "Session Id does not exist", 400) 0 0 0
674 or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
675  
676 # Delete it
677 0 $self->logger->debug("REST request to delete global session $id");
678 0 my $res = $self->p->_deleteSession( $req, $session );
679 0 $self->logger->debug(" Result is $res");
680  
681 0 return $self->p->sendJSONresponse( $req, { result => $res } );
682 }
683  
684 0 ▶sub removeSessions {
Subroutine removeSessions: not called CC=1 SCAR=6.9
Pod undocumented
685 0 my ( $self, $req ) = @_;
686 my $glPlugin =
687 0 $self->p->loadedModules->{'Lemonldap::NG::Portal::Plugins::GlobalLogout'};
688 0 my $sessions = $glPlugin->activeSessions($req);
689 0 my $nbr = $glPlugin->removeOtherActiveSessions( $req, $sessions );
690  
691 0 return $self->p->sendJSONresponse( $req, { result => $nbr } );
692 }
693  
694 0 ▶sub pwdReset {
Subroutine pwdReset: not called CC=12 SCAR=50.5
Pod undocumented
695 0 my ( $self, $req ) = @_;
696  
697 0 $self->logger->debug("Entering REST pwdReset method");
698  
699 0 ▶ unless ( $self->p->_passwordDB ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->p->_passwordDB) 0 0 0
700 0 $self->logger->error(
701 "No Password module configured on this server, "
702 . "cannot execute password change" );
703 0 return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
704 }
705  
706 0 my $jsonBody = eval { from_json( $req->content ) };
707 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
708 0 $self->logger->error("Received invalid JSON $@");
709 0 return $self->p->sendError( $req, "Invalid JSON", 400 );
710 }
711  
712 0 my $user = $jsonBody->{user};
713 0 my $mail = $jsonBody->{mail};
714 0 my $password = $jsonBody->{password};
715  
716 0 ▶ unless ( $user or $mail ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user or $mail) 0 0 0
Condition0%0/3
$user or $mail
l!l&&r!l&&!r
000
MC/DC0%0/2
$user or $mail
$user $mail
Truth table0%0/3
A or B
A= $userB= $mail
ABresult
1X1
011
000
717 0 $self->logger->error("Missing user or mail argument");
718 0 return $self->p->sendError( $req, "Missing user or mail argument",
719 400 );
720 }
721  
722 0 ▶ unless ($password) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($password) 0 0 0
723 0 $self->logger->error("Missing password argument");
724 0 return $self->p->sendError( $req, "Missing password argument", 400 );
725 }
726  
727 0 ▶ $req->user( $user || $mail );
Condition0%0/3
$user || $mail
l!l&&r!l&&!r
000
MC/DC0%0/2
$user || $mail
$user $mail
Truth table0%0/3
A || B
A= $userB= $mail
ABresult
1X1
011
000
728 0 $req->steps( ['getUser'] );
729 0 ▶ my $result = $self->p->process( $req, ( $mail ? ( useMail => 1 ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$mail ? : 0 0 0
730 0 ▶ if ($result) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) 0 0 0
731 $self->logger->error( "Error while looking up user: $result ("
732 0 . portalConsts->{$result}
733 . ")" );
734 0 return $self->p->sendError( $req, "User not found", 400 );
735 }
736 $result =
737 0 ▶ $self->p->_passwordDB->setNewPassword( $req, $password, $mail ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$mail ? : 0 0 0
738 0 $req->{user} = undef;
739  
740 0 ▶ if ( $result == PE_PASSWORD_OK or $result == PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result == 35 or $result == 0) { } 0 0 0
Condition0%0/3
$result == 35 or $result == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$result == 35 or $result == 0
$result == 35 $result == 0
Truth table0%0/3
A or B
A= $result == 35B= $result == 0
ABresult
1X1
011
000
741 0 return $self->p->sendJSONresponse( $req, { 'result' => JSON::true } );
742 }
743 else {
744 $self->logger->error( "Error while changing user password: $result ("
745 0 . portalConsts->{$result}
746 . ")" );
747 0 return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
748 }
749  
750 }
751  
752 0 ▶sub pwdConfirm {
Subroutine pwdConfirm: not called CC=7 SCAR=40.3
Pod undocumented
753 0 my ( $self, $req ) = @_;
754  
755 0 $self->logger->debug("Entering REST pwdConfirm method");
756  
757 0 my $jsonBody = eval { from_json( $req->content ) };
758 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
759 0 $self->logger->error("Received invalid JSON $@");
760 0 return $self->p->sendError( $req, "Invalid JSON", 400 );
761 }
762  
763 0 my $user = $jsonBody->{user};
764 0 my $password = $jsonBody->{password};
765  
766 0 ▶ unless ( $user and $password ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user and $password) 0 0 0
Condition0%0/3
$user and $password
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $password
$user $password
Truth table0%0/3
A and B
A= $userB= $password
ABresult
0X0
100
111
767 0 $self->logger->error("Missing required arguments");
768 0 return $self->p->sendError( $req, "Missing arguments user or password",
769 400 );
770 }
771  
772 0 $req->parameters->{user} = $user;
773 0 $req->parameters->{password} = $password;
774 0 $req->data->{_pwdCheck} = 1;
775 0 $req->data->{skipToken} = 1;
776  
777 0 ▶ if ( $self->p->_userDB ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->p->_userDB) 0 0 0
778 0 $req->steps( [ $self->p->authProcess ] );
779 0 my $result = $self->p->process($req);
780 0 ▶ if ( $result == PE_PASSWORD_OK or $result == PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result == 35 or $result == 0) { } 0 0 0
Condition0%0/3
$result == 35 or $result == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$result == 35 or $result == 0
$result == 35 $result == 0
Truth table0%0/3
A or B
A= $result == 35B= $result == 0
ABresult
1X1
011
000
781 0 return $self->p->sendJSONresponse( $req,
782 { 'result' => JSON::true } );
783 }
784 else {
785 $self->logger->error(
786 0 "Process returned $result (" . portalConsts->{$result} . ")" );
787 0 return $self->p->sendJSONresponse( $req,
788 { 'result' => JSON::false } );
789 }
790 }
791 }
792  
793 0 ▶sub getUser {
Subroutine getUser: not called CC=7 SCAR=40.3
Pod undocumented
794 0 my ( $self, $req ) = @_;
795  
796 0 $self->logger->debug("Entering REST getUser method");
797  
798 0 my $jsonBody = eval { from_json( $req->content ) };
799 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
800 0 $self->logger->error("Received invalid JSON $@");
801 0 return $self->p->sendError( $req, "Invalid JSON", 400 );
802 }
803  
804 0 my $user = $jsonBody->{user};
805 0 my $mail = $jsonBody->{mail};
806  
807 0 ▶ unless ( $user or $mail ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user or $mail) 0 0 0
Condition0%0/3
$user or $mail
l!l&&r!l&&!r
000
MC/DC0%0/2
$user or $mail
$user $mail
Truth table0%0/3
A or B
A= $userB= $mail
ABresult
1X1
011
000
808 0 $self->logger->error("Missing user or mail argument");
809 0 return $self->p->sendError( $req, "Missing user or mail argument",
810 400 );
811 }
812  
813 0 ▶ $req->user( $user || $mail );
Condition0%0/3
$user || $mail
l!l&&r!l&&!r
000
MC/DC0%0/2
$user || $mail
$user $mail
Truth table0%0/3
A || B
A= $userB= $mail
ABresult
1X1
011
000
814 0 $req->data->{_pwdCheck} = 1;
815  
816 # Search user in database
817 0 $req->steps( [
818 'getUser', 'setSessionInfo',
819 $self->p->groupsAndMacros, 'setLocalGroups'
820 ]
821 );
822 0 ▶ my $error = $self->p->process( $req, ( $mail ? ( useMail => 1 ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$mail ? : 0 0 0
823 0 ▶ if ( $error == PE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error == 0) { } 0 0 0
824 0 return $self->p->sendJSONresponse(
825 $req,
826 {
827 'result' => JSON::true,
828 'info' => $req->sessionInfo,
829 }
830 );
831 }
832 else {
833 0 return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
834 }
835 }
836  
837 0 ▶sub myApplications {
Subroutine myApplications: not called CC=2 SCAR=17.9
Pod undocumented
838 0 my ( $self, $req ) = @_;
839 0 my $basePath = $req->portal;
840 0 $basePath =~ s#/*$##;
841 0 $basePath .= $self->p->{staticPrefix} . '/common/apps/';
842 my @appslist = map {
843 my @apps = map {
844 {
845 $_->{appname} => {
846 AppUri => $_->{appuri},
847 AppDesc => $_->{appdesc},
848 AppTip => $_->{apptip},
849 (
850 $_->{applogo_icon}
851 ? ( AppIcon => $_->{applogo} )
852 : ( AppLogo => $basePath . $_->{applogo} )
853 0 ▶ )
Branch: 1 branch
BranchTrueFalseTotal
$_->{'applogo_icon'} ? : 0 0 0
854 }
855 }
856 0 } @{ $_->{applications} };
857 0 { Category => $_->{catname}, Applications => \@apps },
858 0 } @{ $self->p->menu->appslist($req) };
859  
860 0 return $self->p->sendJSONresponse( $req,
861 { result => 1, myapplications => \@appslist } );
862 }
863  
864 0 ▶sub languages {
Subroutine languages: not called CC=1 SCAR=6.9
Pod undocumented
865 0 my ( $self, $req ) = @_;
866 return $self->sendJSONresponse(
867 $req,
868 [
869 map {
870 {
871 code => $_,
872 name => langName->{$_},
873 flag => $req->portal
874 . $self->p->{staticPrefix}
875 0 . "/languages/$_.png"
876 }
877 } split /[,;]\s*/,
878 $self->p->{languages}
879 0 ]
880 );
881 }
882  
883 0 ▶sub _checkSecret {
Subroutine _checkSecret: not called CC=5 SCAR=34.0
884 0 my ( $self, $secret ) = @_;
885 0 my $isValid = 0;
886  
887 0 ▶ if ($secret) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secret) 0 0 0
888 0 my $t;
889 0 ▶ if ( $t = $self->conf->{cipher}->decrypt($secret) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t = $self->conf->{'cipher'}->decrypt($secret)) { } 0 0 0
890 0 ▶ if ( $t <= time + $self->conf->{restClockTolerance}
Branch: 1 branch
BranchTrueFalseTotal
if ($t <= &CORE::GLOBAL::time() + $self->conf->{'restClockTolerance'} and $t > &CORE::GLOBAL::time() - $self->conf->{'restClockTolerance'}) { } 0 0 0
Condition0%0/3
$t <= &CORE::GLOBAL::time() + $self->conf->{"restClockTolerance"} and $t > &CORE::GLOBAL::time() - $self->conf->{"restClockTolerance"}
!ll&&!rl&&r
000
MC/DC0%0/2
$t <= &CORE::GLOBAL::time() + $self->conf->{"restClockTolerance"} and $t > &CORE::GLOBAL::time() - $self->conf->{"restClockTolerance"}
$t <= &CORE::GLOBAL::time() + $self->conf->{"restClockTolerance"} $t > &CORE::GLOBAL::time() - $self->conf->{"restClockTolerance"}
Truth table0%0/3
A and B
A= $t <= &CORE::GLOBAL::time() + $self->conf->{"restClockTolerance"}B= $t > &CORE::GLOBAL::time() - $self->conf->{"restClockTolerance"}
ABresult
0X0
100
111
891 and $t > time - $self->conf->{restClockTolerance} )
892 {
893 0 $isValid = 1;
894 }
895 else {
896 0 $self->logger->error( 'Clock drift between servers is'
897 . ' beyond tolerance, force denied.' );
898 }
899 }
900 else {
901 0 $self->logger->error('Bad key, force denied');
902 }
903 }
904  
905 0 return $isValid;
906 }
907  
908 105 1;
« blib/lib/Lemonldap/NG/Portal/Auth/OpenIDConnect.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/2F/Register/WebAuthn.pm »