« blib/lib/Lemonldap/NG/Portal/Plugins/Refresh.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm »
| 1 | package Lemonldap::NG::Portal::UserDB::REST; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use JSON qw(from_json to_json); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 3 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | PE_OK | ||||||||||||||
| 8 | PE_ERROR | ||||||||||||||
| 9 | PE_USERNOTFOUND | ||||||||||||||
| 10 | PE_BADCREDENTIALS | ||||||||||||||
| 11 | 3 | ); | |||||||||||||
| 12 | |||||||||||||||
| 13 | 3 | extends qw( | |||||||||||||
| 14 | Lemonldap::NG::Portal::Main::UserDB | ||||||||||||||
| 15 | Lemonldap::NG::Portal::Lib::REST | ||||||||||||||
| 16 | ); | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 3 | our $VERSION = '2.23.0'; | |||||||||||||
| 19 | |||||||||||||||
| 20 | # INITIALIZATION | ||||||||||||||
| 21 | |||||||||||||||
| 22 | has findUserDBUrl => ( | ||||||||||||||
| 23 | is => 'ro', | ||||||||||||||
| 24 | lazy => 1, | ||||||||||||||
| 25 | 0 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 26 | 0 | ▶ | $_[0]->conf->{restFindUserDBUrl} || $_[0]->conf->{restUserDBUrl}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | } | ||||||||||||||
| 28 | 3 | ); | |||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||||
| 31 | 2 | my $self = shift; | |||||||||||||
| 32 | |||||||||||||||
| 33 | 2 | ▶ | unless ( $self->initNamedCallFromConf( 'restUserDB', 'user' ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | 0 | $self->logger->error('REST User data URL is not set'); | |||||||||||||
| 35 | 0 | return 0; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 2 | return 1; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | # RUNNING METHODS | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | ▶ | sub getUser { | ||||||||||||
|
Subroutine
getUser: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 44 | 0 | my ( $self, $req, %args ) = @_; | |||||||||||||
| 45 | 0 | my $res; | |||||||||||||
| 46 | 0 | $res = eval { | |||||||||||||
| 47 | $self->restNamedCall( | ||||||||||||||
| 48 | $req, 'user', | ||||||||||||||
| 49 | { | ||||||||||||||
| 50 | ( $args{useMail} ? 'mail' : 'user' ) => $req->user, | ||||||||||||||
| 51 | 0 | ▶ | 'useMail' => ( $args{useMail} ? JSON::true : JSON::false ), | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 52 | |||||||||||||||
| 53 | }, | ||||||||||||||
| 54 | {} | ||||||||||||||
| 55 | ); | ||||||||||||||
| 56 | }; | ||||||||||||||
| 57 | 0 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 0 | $self->logger->error("UserDB REST error: $@"); | |||||||||||||
| 59 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||
| 60 | 0 | return PE_ERROR; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | 0 | ▶ | unless ( $res->{result} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 0 | $self->userLogger->warn( 'User ' . $req->user . ' not found' ); | |||||||||||||
| 64 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||
| 65 | 0 | return PE_BADCREDENTIALS; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | 0 | ▶ | $req->data->{restUserDBInfo} = $res->{info} || {}; | ||||||||||||
|
Condition0%0/2
$res->{'info'} || {}
MC/DC0%0/1
$res->{'info'} || {}
$res->{'info'}
Truth table0%0/2
A
A= $res->{'info'}
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | return PE_OK; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | sub findUser { | ||||||||||||
|
Subroutine
findUser: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 73 | 0 | my ( $self, $req, %args ) = @_; | |||||||||||||
| 74 | my $plugin = | ||||||||||||||
| 75 | 0 | $self->p->loadedModules->{"Lemonldap::NG::Portal::Plugins::FindUser"}; | |||||||||||||
| 76 | 0 | my ( $searching, $excluding ) = $plugin->retreiveFindUserParams($req); | |||||||||||||
| 77 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||
| 78 | 0 | ▶ | return PE_OK unless scalar @$searching; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | my $res; | |||||||||||||
| 81 | $searching = [ | ||||||||||||||
| 82 | map { | ||||||||||||||
| 83 | 0 | { $_->{key} => $_->{value} } | |||||||||||||
| 84 | 0 | } @$searching | |||||||||||||
| 85 | ]; | ||||||||||||||
| 86 | $excluding = [ | ||||||||||||||
| 87 | map { | ||||||||||||||
| 88 | 0 | { $_->{key} => $_->{value} } | |||||||||||||
| 89 | 0 | } @$excluding | |||||||||||||
| 90 | ]; | ||||||||||||||
| 91 | 0 | $res = eval { | |||||||||||||
| 92 | 0 | ▶ | $self->restCall( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | $self->findUserDBUrl, | ||||||||||||||
| 94 | { | ||||||||||||||
| 95 | searchingAttributes => to_json($searching), | ||||||||||||||
| 96 | ( | ||||||||||||||
| 97 | scalar @$excluding | ||||||||||||||
| 98 | ? ( excludingAttributes => to_json($excluding) ) | ||||||||||||||
| 99 | : () | ||||||||||||||
| 100 | ) | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | ); | ||||||||||||||
| 103 | }; | ||||||||||||||
| 104 | 0 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | 0 | $self->logger->error("UserDB REST error: $@"); | |||||||||||||
| 106 | 0 | return PE_ERROR; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | 0 | ▶ | unless ( $res->{result} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | 0 | $self->userLogger->info('FindUser: no user found from REST UserDB'); | |||||||||||||
| 110 | 0 | return PE_USERNOTFOUND; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 0 | my $results = $res->{users}; | |||||||||||||
| 114 | 0 | $self->logger->debug( | |||||||||||||
| 115 | 'REST UserDB number of result(s): ' . scalar @$results ); | ||||||||||||||
| 116 | 0 | ▶ | if ( scalar @$results ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | 0 | my $rank = int( rand( scalar @$results ) ); | |||||||||||||
| 118 | 0 | $self->logger->debug("REST UserDB random rank: $rank"); | |||||||||||||
| 119 | 0 | $self->userLogger->info( | |||||||||||||
| 120 | "FindUser: REST UserDB returns $results->[$rank]"); | ||||||||||||||
| 121 | 0 | $req->data->{findUser} = $results->[$rank]; | |||||||||||||
| 122 | 0 | $req->data->{findUserAll} = $results; | |||||||||||||
| 123 | 0 | return PE_OK; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 0 | return PE_USERNOTFOUND; | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | 0 | ▶ | sub setSessionInfo { | ||||||||||||
|
Subroutine
setSessionInfo: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 130 | 0 | my ( $self, $req ) = @_; | |||||||||||||
| 131 | $req->sessionInfo->{$_} = $req->data->{restUserDBInfo}->{$_} | ||||||||||||||
| 132 | 0 | foreach ( keys %{ $req->data->{restUserDBInfo} } ); | |||||||||||||
| 133 | |||||||||||||||
| 134 | 0 | return PE_OK; | |||||||||||||
| 135 | } | ||||||||||||||
| 136 | |||||||||||||||
| 137 | 3 | 1; | |||||||||||||