WIP - favApps skeleton (#1689)
This commit is contained in:
parent
476212094a
commit
e490addd2d
|
@ -86,7 +86,7 @@
|
|||
"authentication" : "Demo",
|
||||
"cfgAuthor" : "The LemonLDAP::NG team",
|
||||
"cfgNum" : 1,
|
||||
"cfgVersion" : "2.0.3",
|
||||
"cfgVersion" : "2.1.0",
|
||||
"cookieName" : "lemonldap",
|
||||
"demoExportedVars" : {
|
||||
"cn" : "cn",
|
||||
|
|
|
@ -57,6 +57,8 @@ sub defaultValues {
|
|||
'facebookExportedVars' => {},
|
||||
'facebookUserField' => 'id',
|
||||
'failedLoginNumber' => 5,
|
||||
'favApps' => 1,
|
||||
'favAppsMaxNumber' => 5,
|
||||
'formTimeout' => 120,
|
||||
'globalStorage' => 'Apache::Session::File',
|
||||
'globalStorageOptions' => {
|
||||
|
|
|
@ -1144,6 +1144,14 @@ qr/^(?:\*\.)?(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][
|
|||
'default' => 5,
|
||||
'type' => 'int'
|
||||
},
|
||||
'favApps' => {
|
||||
'default' => 1,
|
||||
'type' => 'bool'
|
||||
},
|
||||
'favAppsMaxNumber' => {
|
||||
'default' => 5,
|
||||
'type' => 'int'
|
||||
},
|
||||
'formTimeout' => {
|
||||
'default' => 120,
|
||||
'type' => 'int'
|
||||
|
|
|
@ -446,6 +446,18 @@ sub attributes {
|
|||
documentation => 'Display session empty values',
|
||||
flags => 'p',
|
||||
},
|
||||
favApps => {
|
||||
default => 1,
|
||||
type => 'bool',
|
||||
documentation => 'Enable favorite Apps',
|
||||
flags => 'p',
|
||||
},
|
||||
favAppsMaxNumber => {
|
||||
default => 5,
|
||||
type => 'int',
|
||||
documentation => 'Maximum favorite Apps number',
|
||||
flags => 'p',
|
||||
},
|
||||
impersonationMergeSSOgroups => {
|
||||
default => 0,
|
||||
type => 'bool',
|
||||
|
|
|
@ -649,6 +649,15 @@ sub tree {
|
|||
'checkUserDisplayEmptyValues',
|
||||
]
|
||||
},
|
||||
{
|
||||
title => 'appsFav',
|
||||
help => 'favapps.html',
|
||||
form => 'simpleInputContainer',
|
||||
nodes => [
|
||||
'favApps',
|
||||
'favAppsMaxNumber',
|
||||
]
|
||||
},
|
||||
{
|
||||
title => 'impersonation',
|
||||
help => 'impersonation.html',
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -27,6 +27,7 @@ our @pList = (
|
|||
portalForceAuthn => '::Plugins::ForceAuthn',
|
||||
checkUser => '::Plugins::CheckUser',
|
||||
impersonationRule => '::Plugins::Impersonation',
|
||||
favApps => '::Plugins::FavApps',
|
||||
);
|
||||
|
||||
##@method list enabledPlugins
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package Lemonldap::NG::Portal::Plugins::FavApps;
|
||||
|
||||
use strict;
|
||||
use Mouse;
|
||||
use JSON qw(from_json to_json);
|
||||
use Lemonldap::NG::Portal::Main::Constants qw(
|
||||
PE_BADCREDENTIALS
|
||||
PE_TOKENEXPIRED
|
||||
PE_NOTOKEN
|
||||
PE_MALFORMEDUSER
|
||||
);
|
||||
|
||||
our $VERSION = '2.1.0';
|
||||
|
||||
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
||||
|
||||
# INITIALIZATION
|
||||
|
||||
sub init {
|
||||
my $self = shift;
|
||||
|
||||
$self->addAuthRoute( favapps => 'register', ['POST'] );
|
||||
$self->addAuthRoute( favapps => 'read', ['GET'] );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
# RUNNING METHOD
|
||||
|
||||
sub register {
|
||||
my ( $self, $req, $apps ) = @_;
|
||||
my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
|
||||
|
||||
# Read existing favorite Apps
|
||||
$self->logger->debug("Looking for favorite Apps...");
|
||||
my $_favapps;
|
||||
if ( $req->sessionInfo->{_favApps} ) {
|
||||
$_favapps = eval {
|
||||
from_json( $req->sessionInfo->{_favapps}, { allow_nonref => 1 } );
|
||||
};
|
||||
if ($@) {
|
||||
$self->logger->error("Corrupted session (_2fDevices): $@");
|
||||
return $self->p->sendError( $req, "Corrupted session", 500 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$self->logger->debug("No favorite Apps found");
|
||||
$_favapps = [];
|
||||
}
|
||||
|
||||
push @$_favapps, $apps;
|
||||
$self->p->updatePersistentSession( $req,
|
||||
{ _favapps => to_json($_favapps) } );
|
||||
$self->userLogger->notice("Apps registration of $apps succeeds for $user");
|
||||
|
||||
return [
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/json',
|
||||
'Content-Length' => 12,
|
||||
],
|
||||
['{"result":1}']
|
||||
];
|
||||
}
|
||||
|
||||
sub read {
|
||||
my ( $self, $req ) = @_;
|
||||
my $user = $req->sessionInfo->{ $self->conf->{whatToTrace} };
|
||||
|
||||
# Read existing favorite Apps
|
||||
$self->logger->debug("Looking for favorite Apps...");
|
||||
my $_favapps;
|
||||
if ( $req->sessionInfo->{_favApps} ) {
|
||||
$_favapps = eval {
|
||||
from_json( $req->sessionInfo->{_favapps}, { allow_nonref => 1 } );
|
||||
};
|
||||
if ($@) {
|
||||
$self->logger->error("Corrupted session (_2fDevices): $@");
|
||||
return $self->p->sendError( $req, "Corrupted session", 500 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$self->logger->debug("No favorite Apps found");
|
||||
$_favapps = [];
|
||||
}
|
||||
|
||||
# Serialize data
|
||||
my $data = to_json( {
|
||||
result => 1, apps => $_favapps
|
||||
}
|
||||
);
|
||||
$self->logger->debug(scalar @$_favapps . " Apps found for $user");
|
||||
|
||||
return [
|
||||
200,
|
||||
[
|
||||
'Content-Type' => 'application/json',
|
||||
'Content-Length' => length($data),
|
||||
],
|
||||
[$data]
|
||||
];
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue