2017-01-06 11:57:51 +01:00
|
|
|
# Session server plugin for REST requests
|
|
|
|
#
|
|
|
|
# This plugin adds the following entry points:
|
2017-02-28 06:30:47 +01:00
|
|
|
# - Sessions backend (if restSessionServer is on)
|
2018-07-05 22:56:16 +02:00
|
|
|
# * GET /sessions/<type>/<session-id> : get session data
|
2017-01-06 11:57:51 +01:00
|
|
|
# * GET /sessions/<type>/<session-id>/<key> : get a session key value
|
2017-01-10 22:43:34 +01:00
|
|
|
# * GET /sessions/<type>/<session-id>/[k1,k2] : get some session key value
|
2017-01-06 11:57:51 +01:00
|
|
|
# * POST /sessions/<type> : create a session
|
2019-06-25 09:37:37 +02:00
|
|
|
# * POST /sessions/<type>?all=1 : get all sessions (needs a token)
|
|
|
|
# * POST /sessions/<type>?all=1&search=uid,dwho: search all sessions where uid=dwho (needs a token)
|
2017-01-06 11:57:51 +01:00
|
|
|
# * PUT /sessions/<type>/<session-id> : update some keys
|
2017-01-23 23:15:26 +01:00
|
|
|
# * DELETE /sessions/<type>/<session-id> : delete a session
|
2017-01-06 11:57:51 +01:00
|
|
|
#
|
2017-01-09 12:02:57 +01:00
|
|
|
# - Sessions for connected users (if restSessionServer is on):
|
2018-07-05 22:56:16 +02:00
|
|
|
# * GET /session/my/<type> : get session data
|
2018-06-20 21:38:26 +02:00
|
|
|
# * GET /session/my/<type>/key : get session key
|
|
|
|
# * DELETE /session/my : ask for logout
|
2022-01-26 22:46:12 +01:00
|
|
|
# * DELETE /sessions/my : ask for global logout (if GlobalLogout plugin is on)
|
2017-01-08 13:13:29 +01:00
|
|
|
#
|
2017-02-28 06:30:47 +01:00
|
|
|
# - Authentication
|
2017-02-28 07:34:51 +01:00
|
|
|
# * POST /sessions/<type>/<session-id>?auth : authenticate with a fixed
|
|
|
|
# sessionId
|
2017-02-28 06:30:47 +01:00
|
|
|
# * Note that the "getCookie" method (authentification via SOAP) exists for
|
|
|
|
# REST requests directly by using '/' path : the portal recognize REST
|
|
|
|
# calls and generate JSON response instead of web page.
|
|
|
|
#
|
2017-01-08 13:13:29 +01:00
|
|
|
# - Configuration (if restConfigServer is on)
|
2017-09-05 17:08:57 +02:00
|
|
|
# * GET /config/latest : get the last config metadata
|
|
|
|
# * GET /config/<cfgNum> : get the metadata for config
|
2017-01-06 11:57:51 +01:00
|
|
|
# n° <cfgNum>
|
2017-09-05 17:08:57 +02:00
|
|
|
# * GET /config/<latest|cfgNum>/<key> : get conf key value
|
|
|
|
# * GET /config/<latest|cfgNum>?full : get the full configuration
|
2019-07-31 23:09:38 +02:00
|
|
|
# where <type> is the session type ("global" for SSO session or "persistent")
|
2019-08-17 16:55:35 +02:00
|
|
|
# * GET /error/<lang>/<errNum> : get <errNum> message reference and errors file <lang>.json
|
|
|
|
# Return 'en' error file if no <lang> specified
|
2017-01-09 12:02:57 +01:00
|
|
|
#
|
2020-04-24 21:57:08 +02:00
|
|
|
# - Endpoints for proxy auth/userdb/password
|
|
|
|
# * POST /proxy/getUser : get user attributes (restAuthServer)
|
|
|
|
# * POST /proxy/pwdReset : reset password (restPasswordServer)
|
|
|
|
# * POST /proxy/pwdConfirm : check password (restAuthServer or restPasswordServer)
|
2020-04-24 21:55:47 +02:00
|
|
|
#
|
2017-01-09 12:02:57 +01:00
|
|
|
# - Authorizations for connected users (always):
|
2017-03-19 08:00:10 +01:00
|
|
|
# * GET /mysession/?whoami : get "my" uid
|
2017-01-09 12:02:57 +01:00
|
|
|
# * GET /mysession/?authorizationfor=<base64-encoded-url>: ask if url is
|
2019-09-18 20:58:51 +02:00
|
|
|
# authorized
|
2017-03-19 08:00:10 +01:00
|
|
|
# * PUT /mysession/<type> : update some
|
2018-06-20 21:38:26 +02:00
|
|
|
# persistent data
|
|
|
|
# (restricted)
|
|
|
|
# * DELETE /mysession/<type>/key : delete key in data
|
2017-03-19 08:00:10 +01:00
|
|
|
# (restricted)
|
2022-01-14 22:15:36 +01:00
|
|
|
# * GET /myapplications : get my appplications
|
|
|
|
# list
|
2017-01-06 11:57:51 +01:00
|
|
|
#
|
|
|
|
# There is no conflict with SOAP server, they can be used together
|
|
|
|
|
|
|
|
package Lemonldap::NG::Portal::Plugins::RESTServer;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2018-07-17 22:28:39 +02:00
|
|
|
use JSON qw(from_json to_json);
|
2017-01-08 13:13:29 +01:00
|
|
|
use MIME::Base64;
|
2020-04-24 21:55:47 +02:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_OK
|
2020-10-09 22:26:00 +02:00
|
|
|
portalConsts
|
2020-04-24 21:55:47 +02:00
|
|
|
PE_PASSWORD_OK
|
2021-03-02 08:46:59 +01:00
|
|
|
URIRE
|
2020-04-24 21:55:47 +02:00
|
|
|
);
|
2017-01-06 11:57:51 +01:00
|
|
|
|
2022-01-14 22:21:57 +01:00
|
|
|
our $VERSION = '2.0.14';
|
2017-01-06 11:57:51 +01:00
|
|
|
|
2020-10-09 22:26:00 +02:00
|
|
|
extends qw(
|
|
|
|
Lemonldap::NG::Portal::Main::Plugin
|
|
|
|
);
|
2017-01-08 09:42:16 +01:00
|
|
|
|
2017-03-06 16:06:49 +01:00
|
|
|
has configStorage => (
|
|
|
|
is => 'ro',
|
2017-03-27 18:51:18 +02:00
|
|
|
lazy => 1,
|
2017-03-06 16:06:49 +01:00
|
|
|
default => sub {
|
|
|
|
$_[0]->{p}->HANDLER->localConfig->{configStorage};
|
|
|
|
}
|
|
|
|
);
|
2017-01-10 22:43:34 +01:00
|
|
|
has exportedAttr => (
|
|
|
|
is => 'rw',
|
2017-03-27 18:51:18 +02:00
|
|
|
lazy => 1,
|
2017-01-10 22:43:34 +01:00
|
|
|
default => sub {
|
|
|
|
my $conf = $_[0]->{conf};
|
|
|
|
if ( $conf->{exportedAttr} and $conf->{exportedAttr} !~ /^\s*\+/ ) {
|
2021-04-02 23:57:30 +02:00
|
|
|
return '[' . join( ',', split /\s+/, $conf->{exportedAttr} ) . ']';
|
2017-01-10 22:43:34 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
my @attributes = (
|
|
|
|
'authenticationLevel', 'groups',
|
2017-03-21 21:52:40 +01:00
|
|
|
'ipAddr', '_startTime',
|
2017-01-10 22:43:34 +01:00
|
|
|
'_utime', '_lastSeen',
|
2019-08-26 17:38:08 +02:00
|
|
|
'_session_id', '_session_kind',
|
2017-01-10 22:43:34 +01:00
|
|
|
);
|
|
|
|
if ( my $exportedAttr = $conf->{exportedAttr} ) {
|
|
|
|
$exportedAttr =~ s/^\s*\+\s+//;
|
|
|
|
@attributes = ( @attributes, split( /\s+/, $exportedAttr ) );
|
2021-04-03 16:46:43 +02:00
|
|
|
|
|
|
|
# Convert @attributes into hash to remove duplicates
|
|
|
|
my %attributes = map( { $_ => 1 } @attributes );
|
|
|
|
return '[' . join( ',', keys %attributes ) . ']';
|
2017-01-10 22:43:34 +01:00
|
|
|
}
|
|
|
|
|
2021-04-03 16:46:43 +02:00
|
|
|
# Convert @attributes into hash to remove duplicates
|
2017-01-10 22:43:34 +01:00
|
|
|
my %attributes = map( { $_ => 1 } @attributes );
|
2022-02-16 17:43:29 +01:00
|
|
|
%attributes = (
|
|
|
|
%attributes,
|
|
|
|
%{ $conf->{exportedVars} },
|
|
|
|
%{ $conf->{macros} },
|
|
|
|
);
|
2017-01-10 22:43:34 +01:00
|
|
|
return '[' . join( ',', keys %attributes ) . ']';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2019-12-01 22:01:30 +01:00
|
|
|
has ott => (
|
2017-09-18 22:40:01 +02:00
|
|
|
is => 'rw',
|
|
|
|
lazy => 1,
|
|
|
|
default => sub {
|
|
|
|
my $ott =
|
|
|
|
$_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
|
|
|
|
$ott->timeout( $_[0]->conf->{formTimeout} );
|
|
|
|
return $ott;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-01-06 11:57:51 +01:00
|
|
|
# INITIALIZATION
|
|
|
|
|
|
|
|
sub init {
|
2017-01-09 12:02:57 +01:00
|
|
|
my ($self) = @_;
|
2017-01-08 09:42:16 +01:00
|
|
|
my @parents = ('Lemonldap::NG::Portal::Main::Plugin');
|
2017-01-09 12:02:57 +01:00
|
|
|
my $add = 0;
|
2017-01-08 09:42:16 +01:00
|
|
|
if ( $self->conf->{restConfigServer} ) {
|
|
|
|
push @parents, 'Lemonldap::NG::Common::Conf::RESTServer';
|
2017-01-09 12:02:57 +01:00
|
|
|
$add++;
|
2017-01-08 09:42:16 +01:00
|
|
|
|
|
|
|
# Methods inherited from Lemonldap::NG::Common::Conf::RESTServer
|
|
|
|
$self->addUnauthRoute(
|
2017-09-05 17:08:57 +02:00
|
|
|
config => {
|
2017-01-08 09:42:16 +01:00
|
|
|
':cfgNum' => [
|
|
|
|
qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes
|
|
|
|
applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
|
|
|
|
authChoiceModules grantSessionRules)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
['GET'],
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addUnauthRoute(
|
2017-09-05 17:08:57 +02:00
|
|
|
config => { ':cfgNum' => { '*' => 'getKey' } },
|
2017-01-08 09:42:16 +01:00
|
|
|
['GET']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addUnauthRoute( error => { '*' => 'getError' }, ['GET'] );
|
2017-01-08 09:42:16 +01:00
|
|
|
}
|
|
|
|
if ( $self->conf->{restSessionServer} ) {
|
|
|
|
push @parents, 'Lemonldap::NG::Common::Session::REST';
|
2017-01-09 12:02:57 +01:00
|
|
|
$add++;
|
2017-01-08 09:42:16 +01:00
|
|
|
|
|
|
|
# Methods inherited from Lemonldap::NG::Common::Session::REST
|
|
|
|
$self->addUnauthRoute(
|
2019-06-14 08:51:58 +02:00
|
|
|
sessions => {
|
|
|
|
':sessionType' => (
|
|
|
|
$self->conf->{restExportSecretKeys}
|
|
|
|
? 'rawSession'
|
|
|
|
: 'session'
|
|
|
|
)
|
|
|
|
},
|
2017-01-08 09:42:16 +01:00
|
|
|
['GET']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addUnauthRoute(
|
2017-01-08 09:42:16 +01:00
|
|
|
sessions => { ':sessionType' => 'newSession' },
|
|
|
|
['POST']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2019-07-31 23:09:38 +02:00
|
|
|
# Methods written below
|
|
|
|
->addUnauthRoute(
|
2017-01-09 07:11:28 +01:00
|
|
|
sessions => { ':sessionType' => 'updateSession' },
|
2017-01-08 09:42:16 +01:00
|
|
|
['PUT']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addUnauthRoute(
|
2017-01-09 07:11:28 +01:00
|
|
|
sessions => { ':sessionType' => 'delSession' },
|
2017-01-08 09:42:16 +01:00
|
|
|
['DELETE']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
2018-06-20 21:38:26 +02:00
|
|
|
|
2019-07-31 23:09:38 +02:00
|
|
|
->addAuthRoute(
|
2018-06-20 21:38:26 +02:00
|
|
|
session => { my => { ':sessionType' => 'getMyKey' } },
|
2017-01-09 12:02:57 +01:00
|
|
|
[ 'GET', 'POST' ]
|
2019-11-14 22:02:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
->addAuthRoute(
|
2022-01-26 22:46:12 +01:00
|
|
|
session => { my => 'removeSession' },
|
2019-11-14 22:02:18 +01:00
|
|
|
['DELETE']
|
2019-07-31 23:09:38 +02:00
|
|
|
);
|
2022-01-26 22:46:12 +01:00
|
|
|
|
2022-02-01 21:32:13 +01:00
|
|
|
if ( $self->conf->{globalLogoutRule} ) {
|
2022-01-26 22:46:12 +01:00
|
|
|
$self->addAuthRoute(
|
|
|
|
sessions => { my => 'removeSessions' },
|
|
|
|
['DELETE']
|
|
|
|
);
|
|
|
|
}
|
2017-01-08 09:42:16 +01:00
|
|
|
}
|
2017-01-09 07:11:28 +01:00
|
|
|
|
2020-04-24 21:55:47 +02:00
|
|
|
if ( $self->conf->{restPasswordServer} ) {
|
|
|
|
$self->addUnauthRoute(
|
|
|
|
proxy => {
|
|
|
|
'pwdReset' => 'pwdReset',
|
|
|
|
},
|
|
|
|
['POST']
|
2020-04-24 21:57:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $self->conf->{restAuthServer} or $self->conf->{restPasswordServer} ) {
|
|
|
|
$self->addUnauthRoute(
|
2020-04-24 21:55:47 +02:00
|
|
|
proxy => {
|
|
|
|
'pwdConfirm' => 'pwdConfirm',
|
|
|
|
},
|
|
|
|
['POST']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:57:08 +02:00
|
|
|
if ( $self->conf->{restAuthServer} ) {
|
|
|
|
$self->addUnauthRoute(
|
|
|
|
proxy => {
|
|
|
|
'getUser' => 'getUser',
|
|
|
|
},
|
|
|
|
['POST']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-09 07:11:28 +01:00
|
|
|
# Methods always available
|
2017-01-08 09:42:16 +01:00
|
|
|
$self->addAuthRoute(
|
2017-01-08 13:13:29 +01:00
|
|
|
mysession => { '*' => 'mysession' },
|
|
|
|
[ 'GET', 'POST' ]
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addAuthRoute(
|
2018-06-21 13:52:18 +02:00
|
|
|
mysession => {
|
|
|
|
':sessionType' =>
|
|
|
|
{ ':key' => 'delKeyInMySession', '*' => 'delMySession' }
|
|
|
|
},
|
2018-06-20 21:38:26 +02:00
|
|
|
['DELETE']
|
2019-07-31 23:09:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
->addAuthRoute(
|
2017-03-19 08:00:10 +01:00
|
|
|
mysession => { ':sessionType' => 'updateMySession' },
|
|
|
|
['PUT']
|
2022-01-13 23:25:10 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
->addAuthRoute( myapplications => 'myApplications', ['GET'] );
|
|
|
|
|
2022-02-16 17:43:29 +01:00
|
|
|
extends @parents if ($add);
|
2017-01-10 17:09:28 +01:00
|
|
|
$self->setTypes( $self->conf ) if ( $self->conf->{restSessionServer} );
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2017-01-08 09:42:16 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-09 07:11:28 +01:00
|
|
|
sub newSession {
|
2017-02-28 07:34:51 +01:00
|
|
|
my ( $self, $req, $id ) = @_;
|
|
|
|
|
|
|
|
# If id is defined
|
|
|
|
return $self->newAuthSession( $req, $id )
|
|
|
|
if ( $id and exists $req->parameters->{auth} );
|
2017-01-09 07:11:28 +01:00
|
|
|
my $mod = $self->getMod($req)
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
my $infos = $req->jsonBodyToObj
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
$infos->{_utime} = time();
|
|
|
|
|
2020-06-02 20:36:05 +02:00
|
|
|
my $secret = delete $infos->{__secret};
|
|
|
|
my $force = $self->_checkSecret($secret);
|
2017-02-27 21:48:00 +01:00
|
|
|
|
2019-06-24 23:07:34 +02:00
|
|
|
if ( $req->param('all') and not $id ) {
|
|
|
|
return $self->p->sendError( $req,
|
|
|
|
'Bad key, refuse to send all sessions', 400 )
|
|
|
|
unless ($force);
|
|
|
|
my $data = $infos->{data};
|
|
|
|
my $opts = $self->conf->{globalStorageOptions} || {};
|
|
|
|
$opts->{backend} = $self->conf->{globalStorage};
|
2019-06-25 09:18:58 +02:00
|
|
|
my $sessions;
|
|
|
|
if ( my $query = $req->param('search') ) {
|
|
|
|
my ( $field, @values ) = split /,/, $query;
|
|
|
|
$sessions = Lemonldap::NG::Common::Apache::Session->searchOn(
|
|
|
|
$opts, $field,
|
|
|
|
join( ',', @values ),
|
|
|
|
( $data ? @$data : () )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sessions =
|
|
|
|
Lemonldap::NG::Common::Apache::Session
|
|
|
|
->get_key_from_all_sessions( $opts, $data );
|
|
|
|
}
|
2019-06-24 23:07:34 +02:00
|
|
|
return $self->p->sendJSONresponse( $req, $sessions );
|
|
|
|
}
|
2017-02-28 07:34:51 +01:00
|
|
|
my $session = $self->getApacheSession( $mod, $id, $infos, $force );
|
2017-01-09 07:11:28 +01:00
|
|
|
return $self->p->sendError( $req, 'Unable to create session', 500 )
|
|
|
|
unless ($session);
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"SOAP request create a new session (" . $session->id . ")" );
|
2017-01-22 23:51:22 +01:00
|
|
|
|
2017-01-10 22:43:34 +01:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
2017-01-22 23:51:22 +01:00
|
|
|
{ result => 1, session => $session->data } );
|
2017-01-09 07:11:28 +01:00
|
|
|
}
|
|
|
|
|
2017-02-28 07:34:51 +01:00
|
|
|
sub newAuthSession {
|
|
|
|
my ( $self, $req, $id ) = @_;
|
2020-06-02 20:36:05 +02:00
|
|
|
|
|
|
|
# Check secret
|
|
|
|
my $secret = $req->param('secret');
|
|
|
|
unless ( $self->_checkSecret($secret) ) {
|
2017-02-28 07:34:51 +01:00
|
|
|
return $self->p->sendError( $req, 'Bad secret', 403 );
|
|
|
|
}
|
2020-06-02 20:36:05 +02:00
|
|
|
|
2017-02-28 07:34:51 +01:00
|
|
|
$req->{id} = $id;
|
|
|
|
$req->{force} = 1;
|
2017-02-28 10:49:37 +01:00
|
|
|
$req->user( $req->param('user') );
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->data->{password} = $req->param('password');
|
2019-02-07 09:27:56 +01:00
|
|
|
$req->steps( [
|
2017-02-28 10:49:37 +01:00
|
|
|
@{ $self->p->beforeAuth },
|
2019-09-09 23:18:53 +02:00
|
|
|
qw(getUser extractFormInfo authenticate setAuthSessionInfo),
|
2018-07-05 22:56:16 +02:00
|
|
|
@{ $self->p->betweenAuthAndData },
|
|
|
|
$self->p->sessionData,
|
|
|
|
@{ $self->p->afterData },
|
2018-09-05 09:19:01 +02:00
|
|
|
$self->p->validSession,
|
|
|
|
@{ $self->p->endAuth },
|
2017-02-28 07:34:51 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$req->{error} = $self->p->process($req);
|
|
|
|
$self->logger->debug(
|
|
|
|
"REST authentication result for $req->{user}: code $req->{error}");
|
2017-02-28 10:49:37 +01:00
|
|
|
|
2021-04-02 23:57:30 +02:00
|
|
|
return $self->p->sendError( $req, 'Bad credentials', 401 )
|
|
|
|
if ( $req->error > 0 );
|
2017-02-28 07:34:51 +01:00
|
|
|
return $self->session( $req, $id );
|
|
|
|
}
|
|
|
|
|
2017-01-09 07:11:28 +01:00
|
|
|
sub updateSession {
|
|
|
|
my ( $self, $req, $id ) = @_;
|
2017-02-20 22:00:05 +01:00
|
|
|
$self->logger->debug("REST request to update session $id");
|
2017-01-09 07:11:28 +01:00
|
|
|
my $mod = $self->getMod($req)
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
|
|
|
|
|
|
|
|
# Get new info
|
|
|
|
my $infos = $req->jsonBodyToObj
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
|
2017-02-27 21:48:00 +01:00
|
|
|
# Get secret if given
|
2020-06-02 20:36:05 +02:00
|
|
|
my $secret = delete $infos->{__secret};
|
|
|
|
my $force = $self->_checkSecret($secret);
|
2017-02-28 06:30:47 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
# Get session and store info
|
2017-02-27 21:48:00 +01:00
|
|
|
my $session = $self->getApacheSession( $mod, $id, $infos, $force )
|
2022-02-01 21:32:13 +01:00
|
|
|
or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
|
2017-02-20 22:00:05 +01:00
|
|
|
|
2017-01-09 07:11:28 +01:00
|
|
|
return $self->p->sendJSONresponse( $req, { result => 1 } );
|
2017-01-08 09:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub delSession {
|
2017-01-09 07:11:28 +01:00
|
|
|
my ( $self, $req, $id ) = @_;
|
|
|
|
my $mod = $self->getMod($req)
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
|
|
|
|
|
|
|
|
# Get session
|
|
|
|
my $session = $self->getApacheSession( $mod, $id )
|
2022-02-01 21:32:13 +01:00
|
|
|
or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
|
2017-01-09 07:11:28 +01:00
|
|
|
|
|
|
|
# Delete it
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("REST request to delete session $id");
|
2017-01-10 22:43:34 +01:00
|
|
|
my $res = $self->p->_deleteSession( $req, $session );
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(" Result is $res");
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2017-01-09 07:11:28 +01:00
|
|
|
return $self->p->sendJSONresponse( $req, { result => $res } );
|
2017-01-08 09:42:16 +01:00
|
|
|
}
|
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
sub delMySession {
|
|
|
|
my ( $self, $req, $id ) = @_;
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2017-01-10 17:09:28 +01:00
|
|
|
return $self->delSession( $req, $req->userData->{_session_id} );
|
2017-01-09 12:02:57 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 13:13:29 +01:00
|
|
|
sub mysession {
|
2017-01-08 09:42:16 +01:00
|
|
|
my ( $self, $req ) = @_;
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
# 1. whoami
|
2021-04-02 23:57:30 +02:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ result => $req->userData->{ $self->conf->{whatToTrace} } } )
|
|
|
|
if defined $req->param('whoami');
|
2017-01-09 12:02:57 +01:00
|
|
|
|
2017-09-18 22:40:01 +02:00
|
|
|
if ( defined $req->param('gettoken') ) {
|
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ token => $self->ott->createToken() } );
|
|
|
|
}
|
|
|
|
|
2017-01-08 13:13:29 +01:00
|
|
|
# Verify authorizationfor arg
|
2017-01-09 12:02:57 +01:00
|
|
|
elsif ( my $url = $req->param('authorizationfor') ) {
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
# Verify that value is base64 encoded
|
|
|
|
return $self->p->sendError( $req, "Value must be in BASE64", 400 )
|
|
|
|
if ( $url =~ m#[^A-Za-z0-9\+/=]# );
|
|
|
|
$req->urldc( decode_base64($url) );
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
# Check for XSS problems
|
|
|
|
return $self->p->sendError( $req, 'XSS attack detected', 400 )
|
|
|
|
if ( $self->p->checkXSSAttack( 'authorizationfor', $req->urldc ) );
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
# Split URL
|
2021-03-02 08:46:59 +01:00
|
|
|
$req->urldc =~ URIRE;
|
|
|
|
my ( $host, $uri ) = ( $3 . ( $4 ? ":$4" : '' ), $5 );
|
2017-03-06 17:43:06 +01:00
|
|
|
$uri ||= '/';
|
2017-03-19 08:00:10 +01:00
|
|
|
return $self->p->sendError( $req, "Bad URL $req->{urldc}", 400 )
|
|
|
|
unless ($host);
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Looking for authorization for $url");
|
2017-01-08 13:13:29 +01:00
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
# Now check for authorization
|
|
|
|
my $res =
|
2017-03-28 23:07:49 +02:00
|
|
|
$self->p->HANDLER->grant( $req, $req->userData, $uri, undef, $host );
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(" Result is $res");
|
2017-01-09 12:02:57 +01:00
|
|
|
return $self->p->sendJSONresponse( $req, { result => $res } );
|
|
|
|
}
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2018-06-21 13:52:18 +02:00
|
|
|
return $self->p->sendError( $req,
|
|
|
|
'whoami or authorizationfor is required', 400 );
|
2017-01-08 13:13:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getMyKey {
|
|
|
|
my ( $self, $req, $key ) = @_;
|
2018-07-17 22:38:01 +02:00
|
|
|
$key ||= '';
|
2021-04-02 23:57:30 +02:00
|
|
|
if ($key) {
|
|
|
|
$self->logger->debug(
|
|
|
|
"Request to get personal session info -> Key: $key");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $keys = $self->exportedAttr;
|
|
|
|
$keys =~ s/(?:\[|\])//g;
|
|
|
|
$keys =~ s/,/, /g;
|
|
|
|
$self->logger->debug(
|
|
|
|
"Request to get exported attributes -> Keys: $keys");
|
|
|
|
}
|
|
|
|
|
2017-01-10 22:43:34 +01:00
|
|
|
return $self->session(
|
|
|
|
$req,
|
|
|
|
$req->userData->{_session_id},
|
|
|
|
$key || $self->exportedAttr
|
|
|
|
);
|
2017-01-06 11:57:51 +01:00
|
|
|
}
|
|
|
|
|
2017-03-19 08:00:10 +01:00
|
|
|
sub updateMySession {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $res = 0;
|
|
|
|
my $mKeys = [];
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2017-09-18 22:40:01 +02:00
|
|
|
if ( my $token = $req->param('token') ) {
|
|
|
|
if ( $self->ott->getToken($token) ) {
|
|
|
|
if ( $req->param('sessionType') eq 'persistent' ) {
|
2018-06-21 17:22:58 +02:00
|
|
|
foreach
|
|
|
|
my $key ( @{ $self->conf->{mySessionAuthorizedRWKeys} } )
|
|
|
|
{
|
2018-06-20 21:38:26 +02:00
|
|
|
my $v;
|
|
|
|
if ( $key =~ /\*/ ) {
|
|
|
|
$key =~ s/\*/\.\*/g;
|
|
|
|
if ( my ($k) = grep( /$key/, $req->params ) ) {
|
|
|
|
$v = $req->param($k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$v = $req->param($key);
|
|
|
|
}
|
2017-09-18 22:40:01 +02:00
|
|
|
if ( defined $v ) {
|
|
|
|
$res++;
|
|
|
|
push @$mKeys, $key;
|
|
|
|
$self->p->updatePersistentSession( $req,
|
|
|
|
{ $key => $v } );
|
2018-07-16 22:56:43 +02:00
|
|
|
$self->logger->debug(
|
|
|
|
"Request to update session -> Key : $key");
|
2017-09-18 22:40:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-19 08:00:10 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-18 22:40:01 +02:00
|
|
|
else {
|
|
|
|
$self->logger->error('Update session request with invalid token');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error('Update session request without token');
|
2017-03-19 08:00:10 +01:00
|
|
|
}
|
2021-04-02 23:57:30 +02:00
|
|
|
|
|
|
|
return $self->p->sendError( $req, 'Modification refused', 403 ) unless $res;
|
2017-03-19 08:00:10 +01:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ result => 1, count => $res, modifiedKeys => $mKeys } );
|
|
|
|
}
|
|
|
|
|
2018-06-20 21:38:26 +02:00
|
|
|
sub delKeyInMySession {
|
|
|
|
my ( $self, $req ) = @_;
|
2018-07-17 18:18:50 +02:00
|
|
|
my $res = 0;
|
|
|
|
my $mKeys = [];
|
|
|
|
my $dkey = $req->param('key');
|
|
|
|
my $sub = $req->param('sub');
|
2021-04-02 23:57:30 +02:00
|
|
|
|
2018-06-20 21:38:26 +02:00
|
|
|
if ( my $token = $req->param('token') ) {
|
|
|
|
if ( $self->ott->getToken($token) ) {
|
|
|
|
if ( $req->param('sessionType') eq 'persistent' ) {
|
2018-06-21 17:22:58 +02:00
|
|
|
foreach
|
|
|
|
my $key ( @{ $self->conf->{mySessionAuthorizedRWKeys} } )
|
|
|
|
{
|
2018-06-20 21:38:26 +02:00
|
|
|
if ( $key =~ /\*/ ) {
|
|
|
|
$key =~ s/\*/\.\*/g;
|
2018-06-21 17:15:53 +02:00
|
|
|
if ( $dkey =~ /^$key$/ ) {
|
2018-06-20 21:38:26 +02:00
|
|
|
$res++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( $dkey eq $key ) {
|
|
|
|
$res++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($res) {
|
2018-07-16 22:56:43 +02:00
|
|
|
if ( $dkey !~ /^_oidcConsents$/ ) {
|
|
|
|
$self->p->updatePersistentSession( $req,
|
|
|
|
{ $dkey => undef } );
|
|
|
|
$self->logger->debug(
|
|
|
|
"Update session -> delete Key : $dkey");
|
|
|
|
}
|
2018-07-17 18:15:17 +02:00
|
|
|
elsif ( $dkey =~ /^_oidcConsents$/ and defined $sub ) {
|
2018-07-17 22:17:45 +02:00
|
|
|
|
|
|
|
# Read existing oidcConsents
|
|
|
|
$self->logger->debug("Looking for OIDC Consents ...");
|
|
|
|
my $_oidcConsents;
|
|
|
|
if ( $req->userData->{_oidcConsents} ) {
|
|
|
|
$_oidcConsents = eval {
|
|
|
|
from_json( $req->userData->{_oidcConsents},
|
|
|
|
{ allow_nonref => 1 } );
|
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error(
|
|
|
|
"Corrupted session (_oidcConsents): $@");
|
|
|
|
return $self->p->sendError( $req,
|
|
|
|
"Corrupted session", 500 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-07-17 22:38:01 +02:00
|
|
|
$self->logger->debug("No OIDC Consent found");
|
2018-07-17 22:17:45 +02:00
|
|
|
$_oidcConsents = [];
|
|
|
|
}
|
|
|
|
my @keep = ();
|
|
|
|
while (@$_oidcConsents) {
|
|
|
|
my $element = shift @$_oidcConsents;
|
|
|
|
$self->logger->debug(
|
|
|
|
"Looking for OIDC Consent to delete ...");
|
|
|
|
push @keep, $element
|
|
|
|
unless ( $element->{rp} eq $sub );
|
|
|
|
}
|
|
|
|
$self->p->updatePersistentSession( $req,
|
|
|
|
{ _oidcConsents => to_json( \@keep ) } );
|
2018-07-16 22:56:43 +02:00
|
|
|
$self->logger->debug(
|
2018-07-17 22:17:45 +02:00
|
|
|
"Update session -> delete Key : $dkey with Sub : $sub"
|
2018-07-16 22:56:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error(
|
2018-07-17 22:17:45 +02:00
|
|
|
'Update session request with invalid Key or Sub');
|
2018-07-16 22:56:43 +02:00
|
|
|
}
|
2018-06-20 21:38:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error('Update session request with invalid token');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error('Update session request without token');
|
|
|
|
}
|
2021-04-02 23:57:30 +02:00
|
|
|
|
|
|
|
return $self->p->sendError( $req, 'Modification refused', 403 ) unless $res;
|
2018-06-20 21:38:26 +02:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ result => 1, count => $res, modifiedKeys => $dkey } );
|
|
|
|
}
|
|
|
|
|
2019-07-31 23:09:38 +02:00
|
|
|
sub getError {
|
|
|
|
my ( $self, $req, $lang, $errNum ) = @_;
|
|
|
|
$lang ||= 'en';
|
2019-08-01 11:59:02 +02:00
|
|
|
$errNum
|
2019-08-17 16:55:35 +02:00
|
|
|
? $self->logger->debug("Send $lang error file path with error: $errNum")
|
|
|
|
: $self->logger->debug("Send $lang error file path");
|
2019-07-31 23:09:38 +02:00
|
|
|
|
|
|
|
return $self->p->sendJSONresponse(
|
|
|
|
$req,
|
|
|
|
{
|
2022-02-16 17:43:29 +01:00
|
|
|
result => 1,
|
|
|
|
lang => $lang,
|
|
|
|
errorNum => $errNum ? $errNum : 'all',
|
2019-08-17 16:55:35 +02:00
|
|
|
errorsFileURL =>
|
|
|
|
"$self->{conf}->{staticPrefix}/languages/$lang.json",
|
2022-02-01 21:32:13 +01:00
|
|
|
( $errNum ? ( errorMsgRef => "PE$errNum" ) : () )
|
2019-07-31 23:09:38 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:46:12 +01:00
|
|
|
sub removeSession {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $id = $req->userData->{_session_id};
|
|
|
|
return $self->p->sendError( $req, 'ID is required', 400 ) unless ($id);
|
|
|
|
my $mod = $self->getGlobal()
|
|
|
|
or return $self->p->sendError( $req, undef, 400 );
|
|
|
|
|
|
|
|
# Get session
|
|
|
|
my $session = $self->getApacheSession( $mod, $id )
|
2022-02-01 21:32:13 +01:00
|
|
|
or return $self->p->sendError( $req, 'Session Id does not exist', 400 );
|
2022-01-26 22:46:12 +01:00
|
|
|
|
|
|
|
# Delete it
|
|
|
|
$self->logger->debug("REST request to delete global session $id");
|
|
|
|
my $res = $self->p->_deleteSession( $req, $session );
|
|
|
|
$self->logger->debug(" Result is $res");
|
|
|
|
|
|
|
|
return $self->p->sendJSONresponse( $req, { result => $res } );
|
|
|
|
}
|
|
|
|
|
2019-11-14 22:02:18 +01:00
|
|
|
sub removeSessions {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $glPlugin =
|
|
|
|
$self->p->loadedModules->{'Lemonldap::NG::Portal::Plugins::GlobalLogout'};
|
|
|
|
my $sessions = $glPlugin->activeSessions($req);
|
2019-11-14 22:06:15 +01:00
|
|
|
my $nbr = $glPlugin->removeOtherActiveSessions( $req, $sessions );
|
2019-11-14 22:02:18 +01:00
|
|
|
|
2019-11-15 21:49:01 +01:00
|
|
|
return $self->p->sendJSONresponse( $req, { result => $nbr } );
|
2019-11-14 22:02:18 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 21:55:47 +02:00
|
|
|
sub pwdReset {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
$self->logger->debug("Entering REST pwdReset method");
|
|
|
|
|
|
|
|
unless ( $self->p->_passwordDB ) {
|
|
|
|
$self->logger->error(
|
|
|
|
"No Password module configured on this server, "
|
|
|
|
. "cannot execute password change" );
|
|
|
|
return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $jsonBody = eval { from_json( $req->content ) };
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error("Received invalid JSON $@");
|
|
|
|
return $self->p->sendError( $req, "Invalid JSON", 400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $user = $jsonBody->{user};
|
|
|
|
my $mail = $jsonBody->{mail};
|
|
|
|
my $password = $jsonBody->{password};
|
|
|
|
|
|
|
|
unless ( $user or $mail ) {
|
|
|
|
$self->logger->error("Missing user or mail argument");
|
|
|
|
return $self->p->sendError( $req, "Missing user or mail argument",
|
|
|
|
400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
unless ($password) {
|
|
|
|
$self->logger->error("Missing password argument");
|
|
|
|
return $self->p->sendError( $req, "Missing password argument", 400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $tmp = $self->conf->{portalRequireOldPassword};
|
|
|
|
$self->conf->{portalRequireOldPassword} = 0;
|
|
|
|
$req->user( $user || $mail );
|
|
|
|
$req->steps( ['getUser'] );
|
|
|
|
my $result = $self->p->process( $req, ( $mail ? ( useMail => 1 ) : () ) );
|
|
|
|
if ($result) {
|
|
|
|
$self->logger->error( "Error while looking up user: $result ("
|
|
|
|
. portalConsts->{$result}
|
|
|
|
. ")" );
|
|
|
|
return $self->p->sendError( $req, "User not found", 400 );
|
|
|
|
}
|
|
|
|
$result =
|
2021-06-02 09:35:02 +02:00
|
|
|
$self->p->_passwordDB->setNewPassword( $req, $password, $mail ? 1 : 0 );
|
2020-04-24 21:55:47 +02:00
|
|
|
$req->{user} = undef;
|
|
|
|
$self->conf->{portalRequireOldPassword} = $tmp;
|
|
|
|
|
|
|
|
if ( $result == PE_PASSWORD_OK or $result == PE_OK ) {
|
|
|
|
return $self->p->sendJSONresponse( $req, { 'result' => JSON::true } );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error( "Error while changing user password: $result ("
|
|
|
|
. portalConsts->{$result}
|
|
|
|
. ")" );
|
|
|
|
return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub pwdConfirm {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
$self->logger->debug("Entering REST pwdConfirm method");
|
|
|
|
|
|
|
|
my $jsonBody = eval { from_json( $req->content ) };
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error("Received invalid JSON $@");
|
|
|
|
return $self->p->sendError( $req, "Invalid JSON", 400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $user = $jsonBody->{user};
|
|
|
|
my $password = $jsonBody->{password};
|
|
|
|
|
|
|
|
unless ( $user and $password ) {
|
|
|
|
$self->logger->error("Missing required arguments");
|
|
|
|
return $self->p->sendError( $req, "Missing arguments user or password",
|
|
|
|
400 );
|
|
|
|
}
|
|
|
|
|
2021-09-10 12:27:01 +02:00
|
|
|
$req->parameters->{user} = $user;
|
|
|
|
$req->parameters->{password} = $password;
|
|
|
|
$req->data->{_pwdCheck} = 1;
|
|
|
|
$req->data->{skipToken} = 1;
|
2020-04-24 21:55:47 +02:00
|
|
|
|
|
|
|
if ( $self->p->_userDB ) {
|
2021-09-10 12:27:01 +02:00
|
|
|
$req->steps( [ $self->p->authProcess ] );
|
2020-04-24 21:55:47 +02:00
|
|
|
my $result = $self->p->process($req);
|
|
|
|
if ( $result == PE_PASSWORD_OK or $result == PE_OK ) {
|
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ 'result' => JSON::true } );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error(
|
|
|
|
"Process returned $result (" . portalConsts->{$result} . ")" );
|
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ 'result' => JSON::false } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 21:57:08 +02:00
|
|
|
sub getUser {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
$self->logger->debug("Entering REST getUser method");
|
|
|
|
|
|
|
|
my $jsonBody = eval { from_json( $req->content ) };
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error("Received invalid JSON $@");
|
|
|
|
return $self->p->sendError( $req, "Invalid JSON", 400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $user = $jsonBody->{user};
|
|
|
|
my $mail = $jsonBody->{mail};
|
|
|
|
|
|
|
|
unless ( $user or $mail ) {
|
|
|
|
$self->logger->error("Missing user or mail argument");
|
|
|
|
return $self->p->sendError( $req, "Missing user or mail argument",
|
|
|
|
400 );
|
|
|
|
}
|
|
|
|
|
|
|
|
$req->user( $user || $mail );
|
2021-04-01 19:11:07 +02:00
|
|
|
$req->data->{_pwdCheck} = 1;
|
2020-04-24 21:57:08 +02:00
|
|
|
|
|
|
|
# Search user in database
|
|
|
|
$req->steps( [
|
2022-02-01 21:32:13 +01:00
|
|
|
'getUser', 'setSessionInfo',
|
|
|
|
$self->p->groupsAndMacros, 'setLocalGroups'
|
2020-04-24 21:57:08 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
my $error = $self->p->process( $req, ( $mail ? ( useMail => 1 ) : () ) );
|
|
|
|
if ( $error == PE_OK ) {
|
|
|
|
return $self->p->sendJSONresponse(
|
|
|
|
$req,
|
|
|
|
{
|
|
|
|
'result' => JSON::true,
|
|
|
|
'info' => $req->sessionInfo,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $self->p->sendJSONresponse( $req, { 'result' => JSON::false } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 23:25:10 +01:00
|
|
|
sub myApplications {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my @appslist = map {
|
|
|
|
my @apps = map {
|
|
|
|
{
|
|
|
|
$_->{appname} => {
|
|
|
|
AppUri => $_->{appuri},
|
|
|
|
AppDesc => $_->{appdesc}
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 21:17:57 +01:00
|
|
|
} @{ $_->{applications} };
|
|
|
|
{ Category => $_->{catname}, Applications => \@apps },
|
2022-01-13 23:25:10 +01:00
|
|
|
} @{ $self->p->menu->appslist($req) };
|
|
|
|
|
2022-01-26 22:46:12 +01:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ result => 1, myapplications => \@appslist } );
|
2022-01-13 23:25:10 +01:00
|
|
|
}
|
|
|
|
|
2020-06-02 20:36:05 +02:00
|
|
|
sub _checkSecret {
|
|
|
|
my ( $self, $secret ) = @_;
|
|
|
|
my $isValid = 0;
|
|
|
|
|
|
|
|
if ($secret) {
|
|
|
|
my $t;
|
|
|
|
if ( $t = $self->conf->{cipher}->decrypt($secret) ) {
|
|
|
|
if ( $t <= time + $self->conf->{restClockTolerance}
|
|
|
|
and $t > time - $self->conf->{restClockTolerance} )
|
|
|
|
{
|
|
|
|
$isValid = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error( 'Clock drift between servers is'
|
|
|
|
. ' beyond tolerance, force denied.' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->logger->error('Bad key, force denied');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 23:57:30 +02:00
|
|
|
return $isValid;
|
2020-06-02 20:36:05 +02:00
|
|
|
}
|
|
|
|
|
2017-01-09 12:02:57 +01:00
|
|
|
1;
|