From a0ea56a29adc5e904777d908d8f228186b3055fe Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Sun, 8 Jan 2017 08:42:19 +0000 Subject: [PATCH] SOAP/REST in progress (#970) --- .../lib/Lemonldap/NG/Common/Session/REST.pm | 24 +++++++++++++++++-- .../lib/Lemonldap/NG/Manager/Sessions.pm | 19 +++------------ .../t/jsonfiles/01-base-tree.json | 13 ---------- .../02-base-tree-all-nodes-opened.json | 14 ----------- .../t/jsonfiles/12-modified.json | 14 ----------- lemonldap-ng-manager/t/jsonfiles/14-bad.json | 14 ----------- 6 files changed, 25 insertions(+), 73 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session/REST.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session/REST.pm index ecead2ca1..5614ee031 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session/REST.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Session/REST.pm @@ -2,6 +2,26 @@ package Lemonldap::NG::Common::Session::REST; use strict; use Mouse; +use Lemonldap::NG::Common::Conf::Constants; + +has sessionTypes => ( is => 'rw' ); + +sub setTypes { + my ( $self, $conf ) = @_; + foreach my $type (@sessionTypes) { + if ( my $tmp = + $self->{ $type . 'Storage' } || $conf->{ $type . 'Storage' } ) + { + $self->{sessionTypes}->{$type}->{module} = $tmp; + $self->{sessionTypes}->{$type}->{options} = + $self->{ $type . 'StorageOptions' } + || $conf->{ $type . 'StorageOptions' } + || {}; + $self->{sessionTypes}->{$type}->{kind} = + ( $type eq 'global' ? 'SSO' : ucfirst($type) ); + } + } +} sub separator { $_[0]->{multiValuesSeparator} || $_[0]->conf->{multiValuesSeparator}; @@ -30,7 +50,7 @@ sub delSession { sub session { my ( $self, $req, $id, $skey ) = @_; my ( %h, $res ); - return $self->sendError( $req, 'Bad request', 400 ) unless($id); + return $self->sendError( $req, 'Bad request', 400 ) unless ($id); my $mod = $self->getMod($req) or return $self->sendError( $req, undef, 400 ); @@ -85,7 +105,7 @@ sub getMod { $self->error('Session type is required'); return (); } - unless ( $m = $self->conf->{$s} ) { + unless ( $m = $self->sessionTypes->{$s} ) { $self->error('Unknown (or unconfigured) session type'); return (); } diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm index 9d879e801..c5d0ea011 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm @@ -13,9 +13,8 @@ use Lemonldap::NG::Manager::Constants; use feature 'state'; -extends 'Lemonldap::NG::Common::Conf::AccessLib', 'Lemonldap::NG::Common::Session::REST'; - -has conf => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); +extends 'Lemonldap::NG::Common::Conf::AccessLib', + 'Lemonldap::NG::Common::Session::REST'; our $VERSION = '2.0.0'; @@ -50,19 +49,7 @@ sub addRoutes { # # Return unless configuration is available return 0 unless ($conf); - foreach my $type (@sessionTypes) { - if ( my $tmp = - $self->{ $type . 'Storage' } || $conf->{ $type . 'Storage' } ) - { - $self->{conf}->{$type}->{module} = $tmp; - $self->{conf}->{$type}->{options} = - $self->{ $type . 'StorageOptions' } - || $conf->{ $type . 'StorageOptions' } - || {}; - $self->{conf}->{$type}->{kind} = - ( $type eq 'global' ? 'SSO' : ucfirst($type) ); - } - } + $self->setTypes($conf); $self->{ipField} ||= 'ipAddr'; $self->{multiValuesSeparator} ||= '; '; diff --git a/lemonldap-ng-manager/t/jsonfiles/01-base-tree.json b/lemonldap-ng-manager/t/jsonfiles/01-base-tree.json index b48f52835..1b70e0eee 100644 --- a/lemonldap-ng-manager/t/jsonfiles/01-base-tree.json +++ b/lemonldap-ng-manager/t/jsonfiles/01-base-tree.json @@ -1268,19 +1268,6 @@ "_nodes": [{ "id": "customFunctions", "title": "customFunctions" - }, { - "_nodes": [{ - "default": 0, - "id": "Soap", - "title": "Soap", - "type": "bool" - }, { - "id": "exportedAttr", - "title": "exportedAttr" - }], - "id": "soap", - "title": "soap", - "type": "simpleInputContainer" }, { "_nodes": [{ "default": 1, diff --git a/lemonldap-ng-manager/t/jsonfiles/02-base-tree-all-nodes-opened.json b/lemonldap-ng-manager/t/jsonfiles/02-base-tree-all-nodes-opened.json index 18eea0d30..9a73384a5 100644 --- a/lemonldap-ng-manager/t/jsonfiles/02-base-tree-all-nodes-opened.json +++ b/lemonldap-ng-manager/t/jsonfiles/02-base-tree-all-nodes-opened.json @@ -1444,20 +1444,6 @@ "nodes": [{ "id": "customFunctions", "title": "customFunctions" - }, { - "id": "soap", - "title": "soap", - "type": "simpleInputContainer", - "nodes": [{ - "default": 0, - "id": "Soap", - "title": "Soap", - "type": "bool", - "data": 0 - }, { - "id": "exportedAttr", - "title": "exportedAttr" - }] }, { "id": "loginHistory", "title": "loginHistory", diff --git a/lemonldap-ng-manager/t/jsonfiles/12-modified.json b/lemonldap-ng-manager/t/jsonfiles/12-modified.json index 31f8e7a98..45b7d0005 100644 --- a/lemonldap-ng-manager/t/jsonfiles/12-modified.json +++ b/lemonldap-ng-manager/t/jsonfiles/12-modified.json @@ -1455,20 +1455,6 @@ "nodes": [{ "id": "customFunctions", "title": "customFunctions" - }, { - "id": "soap", - "title": "soap", - "type": "simpleInputContainer", - "nodes": [{ - "default": 0, - "id": "Soap", - "title": "Soap", - "type": "bool", - "data": 0 - }, { - "id": "exportedAttr", - "title": "exportedAttr" - }] }, { "id": "loginHistory", "title": "loginHistory", diff --git a/lemonldap-ng-manager/t/jsonfiles/14-bad.json b/lemonldap-ng-manager/t/jsonfiles/14-bad.json index 3192b1365..096a95ed6 100644 --- a/lemonldap-ng-manager/t/jsonfiles/14-bad.json +++ b/lemonldap-ng-manager/t/jsonfiles/14-bad.json @@ -1444,20 +1444,6 @@ "nodes": [{ "id": "customFunctions", "title": "customFunctions" - }, { - "id": "soap", - "title": "soap", - "type": "simpleInputContainer", - "nodes": [{ - "default": 0, - "id": "Soap", - "title": "Soap", - "type": "bool", - "data": 0 - }, { - "id": "exportedAttr", - "title": "exportedAttr" - }] }, { "id": "loginHistory", "title": "loginHistory", -- GitLab