« blib/lib/Lemonldap/NG/Portal/UserDB/REST.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/GlobalLogout.pm »
| 1 | package Lemonldap::NG::Portal::Plugins::GrantSession; | ||||||||||||||||||||||||||||||||||||
| 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::Main::Constants qw( | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | PE_OK | ||||||||||||||||||||||||||||||||||||
| 7 | PE_BADCREDENTIALS | ||||||||||||||||||||||||||||||||||||
| 8 | PE_SESSIONNOTGRANTED | ||||||||||||||||||||||||||||||||||||
| 9 | 1 | ); | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 1 | extends 'Lemonldap::NG::Portal::Main::Plugin'; | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use constant afterData => 'run'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | has rules => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 20 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | foreach ( keys %{ $self->conf->{grantSessionRules} // {} } ) { | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->conf->{"grantSessionRules"} // {}
MC/DC0%0/1
$self->conf->{"grantSessionRules"} // {}
$self->conf->{"grantSessionRules"}
Truth table50%1/2
A
A= $self->conf->{"grantSessionRules"}
| |||||||||||||||||||||||||||||||||||||
| 22 | 6 | $self->logger->debug("GrantRule key: $_"); | |||||||||||||||||||||||||||||||||||
| 23 | $self->logger->debug( | ||||||||||||||||||||||||||||||||||||
| 24 | 6 | "GrantRule value: " . $self->conf->{grantSessionRules}->{$_} ); | |||||||||||||||||||||||||||||||||||
| 25 | 6 | my $rule = $self->p->buildRule( $self->conf->{grantSessionRules}->{$_}, | |||||||||||||||||||||||||||||||||||
| 26 | 'grantSessionRules' ); | ||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | next unless ($rule); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 28 | 5 | $self->rules->{$_} = $rule; | |||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||
| 30 | 2 | return 1; | |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=9 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 34 | 1 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub sortByComment { | ||||||||||||||||||||||||||||||||||
|
Subroutine
sortByComment: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $A = ( $a =~ /^.*?##(.*)$/ )[0]; | |||||||||||||||||||||||||||||||||||
| 38 | 0 | my $B = ( $b =~ /^.*?##(.*)$/ )[0]; | |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return !( $A or $B ) ? $a cmp $b : !$A ? 1 : !$B ? -1 : $A cmp $B; | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$A || $B
MC/DC0%0/2
$A || $B
$A
$B
Truth table0%0/3
A || B
A= $AB= $B
| |||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | # Avoid display notification if AuthResult is not null | ||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if ( $req->authResult > PE_OK ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||||||||||
| 45 | "Bad authentication, do not check grant session rules"); | ||||||||||||||||||||||||||||||||||||
| 46 | 0 | return PE_BADCREDENTIALS; | |||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 1 | my $user = $req->{sessionInfo}->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||||||||||
| 50 | 1 | foreach ( sort sortByComment keys %{ $self->rules } ) { | |||||||||||||||||||||||||||||||||||
| 51 | 1 | my $rule = $self->conf->{grantSessionRules}->{$_}; | |||||||||||||||||||||||||||||||||||
| 52 | 1 | $self->logger->debug("Grant session rule: $rule"); | |||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | unless ( $self->rules->{$_}->( $req, $req->sessionInfo ) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 54 | 0 | $req->userData( {} ); | |||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||
| 56 | # Catch rule message | ||||||||||||||||||||||||||||||||||||
| 57 | 0 | $_ =~ /^(.*?)##.*$/; | |||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 59 | 0 | $self->logger->debug("Message: $1"); | |||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||
| 61 | # Message can contain session data as user attributes or macros | ||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $hd = $self->p->HANDLER; | |||||||||||||||||||||||||||||||||||
| 63 | 0 | my $msg = $hd->substitute($1); | |||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | unless ( $msg = $hd->buildSub($msg) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $error = $hd->tsv->{jail}->error || '???'; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hd->tsv->{'jail'}->error || '???'
MC/DC0%0/1
$hd->tsv->{'jail'}->error || '???'
$hd->tsv->{'jail'}->error
Truth table0%0/2
A
A= $hd->tsv->{'jail'}->error
| |||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->error("Bad message: $error"); | |||||||||||||||||||||||||||||||||||
| 67 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | 0 | $msg = $msg->( $req, $req->sessionInfo ); | |||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->logger->debug("Transformed message: $msg"); | |||||||||||||||||||||||||||||||||||
| 71 | 0 | $req->info( | |||||||||||||||||||||||||||||||||||
| 72 | $self->loadTemplate( | ||||||||||||||||||||||||||||||||||||
| 73 | $req, 'simpleInfo', params => { trspan => $msg } | ||||||||||||||||||||||||||||||||||||
| 74 | ) | ||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||
| 76 | 0 | $req->urldc( | |||||||||||||||||||||||||||||||||||
| 77 | $self->p->buildUrl( $req->portal, { cancel => 1 } ) ); | ||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||||||||
| 80 | 0 | $req->urldc( $req->portal ); | |||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $self->userLogger->warn( | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 83 | "User $user was not granted to open session by rule: $rule") | ||||||||||||||||||||||||||||||||||||
| 84 | if $user; | ||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $req->authResult(PE_SESSIONNOTGRANTED); | |||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | # Log | ||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $mod = $req->{sessionInfo}->{_auth}; | |||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | $self->userLogger->notice( | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 92 | "Session granted for $user by $mod ($req->{sessionInfo}->{ipAddr})") | ||||||||||||||||||||||||||||||||||||
| 93 | if $user; | ||||||||||||||||||||||||||||||||||||
| 94 | 1 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||
| 97 | 1 | 1; | |||||||||||||||||||||||||||||||||||