2017-02-23 22:46:00 +01:00
|
|
|
package Lemonldap::NG::Portal::UserDB::REST;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2019-12-16 17:44:41 +01:00
|
|
|
use JSON;
|
2017-02-23 22:46:00 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_ERROR
|
|
|
|
PE_OK
|
2019-02-04 17:40:18 +01:00
|
|
|
PE_BADCREDENTIALS
|
2017-02-23 22:46:00 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Common::Module', 'Lemonldap::NG::Portal::Lib::REST';
|
|
|
|
|
2020-09-04 17:59:00 +02:00
|
|
|
our $VERSION = '2.0.9';
|
2017-02-23 22:46:00 +01:00
|
|
|
|
|
|
|
# INITIALIZATION
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Add warning in log
|
|
|
|
unless ( $self->conf->{restUserDBUrl} ) {
|
|
|
|
$self->logger->error('No User REST URL given');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# RUNNING METHODS
|
|
|
|
|
|
|
|
sub getUser {
|
2018-01-22 21:57:48 +01:00
|
|
|
my ( $self, $req, %args ) = @_;
|
|
|
|
my $res;
|
|
|
|
$res = eval {
|
2019-12-16 17:44:41 +01:00
|
|
|
$self->restCall(
|
|
|
|
$self->conf->{restUserDBUrl},
|
|
|
|
{
|
|
|
|
( $args{useMail} ? 'mail' : 'user' ) => $req->user,
|
|
|
|
'useMail' => ( $args{useMail} ? JSON::true : JSON::false ),
|
|
|
|
|
|
|
|
}
|
2018-01-22 21:57:48 +01:00
|
|
|
);
|
2017-02-23 22:46:00 +01:00
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error("UserDB REST error: $@");
|
2019-09-27 16:49:41 +02:00
|
|
|
eval { $self->p->_authentication->setSecurity($req) };
|
2017-02-23 22:46:00 +01:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
unless ( $res->{result} ) {
|
|
|
|
$self->userLogger->warn( 'User ' . $req->user . ' not found' );
|
2019-09-27 16:49:41 +02:00
|
|
|
eval { $self->p->_authentication->setSecurity($req) };
|
2019-02-04 17:40:18 +01:00
|
|
|
return PE_BADCREDENTIALS;
|
2017-02-23 22:46:00 +01:00
|
|
|
}
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->data->{restUserDBInfo} = $res->{info} || {};
|
2017-02-23 22:46:00 +01:00
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setSessionInfo {
|
|
|
|
my ( $self, $req ) = @_;
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->sessionInfo->{$_} = $req->data->{restUserDBInfo}->{$_}
|
|
|
|
foreach ( keys %{ $req->data->{restUserDBInfo} } );
|
2017-02-23 22:46:00 +01:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setGroups {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|