diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/XML.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/XML.pm index 6bda0ba6a..859ccc8d9 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/XML.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/XML.pm @@ -4,7 +4,7 @@ use strict; use Mouse; use XML::LibXML; -our $VERSION = '2.0.8'; +our $VERSION = '2.0.10'; # XML parser has parser => ( diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm index f4b00d825..82b5cbfbe 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm @@ -19,11 +19,12 @@ use Lemonldap::NG::Common::PSGI::Constants; our $VERSION = '2.0.10'; -extends 'Lemonldap::NG::Common::Conf::AccessLib', - 'Lemonldap::NG::Handler::PSGI::Router'; +extends qw( + Lemonldap::NG::Handler::PSGI::Router + Lemonldap::NG::Common::Conf::AccessLib +); has csp => ( is => 'rw' ); - has loadedPlugins => ( is => 'rw', default => sub { [] } ); has hLoadedPlugins => ( is => 'rw', default => sub { {} } ); diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/2ndFA.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/2ndFA.pm index 35ea50615..192d7f413 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/2ndFA.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/2ndFA.pm @@ -1,7 +1,7 @@ package Lemonldap::NG::Manager::2ndFA; -use utf8; use strict; +use utf8; use Mouse; use Lemonldap::NG::Common::Session; @@ -9,8 +9,6 @@ use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Common::PSGI::Constants; use Lemonldap::NG::Common::Conf::ReConstants; -use feature 'state'; - extends qw( Lemonldap::NG::Manager::Plugin Lemonldap::NG::Common::Session::REST diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm index 6f0854a3e..09d03fc4f 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm @@ -5,12 +5,6 @@ use strict; use utf8; use Mouse; -extends qw( - Lemonldap::NG::Manager::Plugin - Lemonldap::NG::Common::Session::REST - Lemonldap::NG::Common::Conf::RESTServer -); - use Lemonldap::NG::Manager::Api::2F; use Lemonldap::NG::Manager::Api::Misc; use Lemonldap::NG::Manager::Api::Providers::OidcRp; @@ -19,6 +13,12 @@ use Lemonldap::NG::Manager::Api::Providers::CasApp; use Lemonldap::NG::Manager::Api::Menu::Cat; use Lemonldap::NG::Manager::Api::Menu::App; +extends qw( + Lemonldap::NG::Manager::Plugin + Lemonldap::NG::Common::Conf::RESTServer + Lemonldap::NG::Common::Session::REST +); + our $VERSION = '2.0.10'; ############################# diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Misc.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Misc.pm index 478d4c1dc..742c8b92b 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Misc.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api/Misc.pm @@ -86,16 +86,11 @@ sub _getSessionDBState { # Handle DBI-type session stores if ( $fakeobj->{object_store}->isa("Apache::Session::Store::DBI") ) { - # + # The 'connection' method will fail if the DB is unreachable # this is good enough a test for now eval { $fakeobj->{object_store}->connection($fakeobj) }; - if ($@) { - return 0; - } - else { - return 1; - } + return $@ ? 0 : 1; } # Handle MongoDB @@ -106,17 +101,11 @@ sub _getSessionDBState { $fakeobj->{object_store}->connection($fakeobj); $fakeobj->{object_store}->{collection}->estimated_document_count; }; - if ($@) { - return 0; - } - else { - return 1; - } + return $@ ? 0 : 1; } # We don't know return 2; - } sub _getObjectSessionModule { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm index 5ec6855e1..f41e20dfa 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf.pm @@ -17,12 +17,12 @@ use Convert::PEM; use URI::URL; use Net::SSLeay; -use feature 'state'; +extends qw( + Lemonldap::NG::Manager::Plugin + Lemonldap::NG::Common::Conf::RESTServer +); -extends 'Lemonldap::NG::Manager::Plugin', - 'Lemonldap::NG::Common::Conf::RESTServer'; - -our $VERSION = '2.0.9'; +our $VERSION = '2.0.10'; ############################# # I. INITIALIZATION METHODS # @@ -315,7 +315,8 @@ sub prx { sub getConfByNum { my ( $self, $cfgNum, @args ) = @_; - unless ( %{ $self->currentConf } + unless ($self->currentConf + and %{ $self->currentConf } and $cfgNum == $self->currentConf->{cfgNum} ) { my $tmp; diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm index 40a0b8827..f811c239c 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm @@ -2,6 +2,7 @@ package Lemonldap::NG::Manager::Conf::Tests; use strict; use utf8; +use strict; use Lemonldap::NG::Common::Regexp; use Lemonldap::NG::Handler::Main; use Lemonldap::NG::Common::Util qw(getSameSite); diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Zero.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Zero.pm index 39b56034f..591fc9964 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Zero.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Zero.pm @@ -1,5 +1,7 @@ package Lemonldap::NG::Manager::Conf::Zero; +use strict; + our $VERSION = '2.0.9'; sub zeroConf { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm index f5c559921..949f8b7d4 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Notifications.pm @@ -12,15 +12,13 @@ use Lemonldap::NG::Common::PSGI::Constants; use Lemonldap::NG::Common::Conf::ReConstants; require Lemonldap::NG::Common::Notifications; -use feature 'state'; - extends qw( Lemonldap::NG::Manager::Plugin - Lemonldap::NG::Common::Conf::AccessLib Lemonldap::NG::Common::PSGI::Router + Lemonldap::NG::Common::Conf::AccessLib ); -our $VERSION = '2.0.9'; +our $VERSION = '2.0.10'; has notifAccess => ( is => 'rw' ); has notifFormat => ( is => 'rw' ); diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Plugin.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Plugin.pm index 39df7fa62..bcbf45132 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Plugin.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Plugin.pm @@ -2,7 +2,8 @@ package Lemonldap::NG::Manager::Plugin; use strict; use Mouse; -our $VERSION = '2.0.8'; + +our $VERSION = '2.0.10'; extends 'Lemonldap::NG::Common::Module'; diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm index 965ec9e24..2641fe1de 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Sessions.pm @@ -1,7 +1,7 @@ package Lemonldap::NG::Manager::Sessions; -use utf8; use strict; +use utf8; use Mouse; use Lemonldap::NG::Common::Session; @@ -11,11 +11,13 @@ use Lemonldap::NG::Common::PSGI::Constants; use Lemonldap::NG::Common::Conf::ReConstants; use Lemonldap::NG::Common::IPv6; -use feature 'state'; +#use feature 'state'; -extends 'Lemonldap::NG::Manager::Plugin', - 'Lemonldap::NG::Common::Conf::AccessLib', - 'Lemonldap::NG::Common::Session::REST'; +extends qw( + Lemonldap::NG::Manager::Plugin + Lemonldap::NG::Common::Session::REST + Lemonldap::NG::Common::Conf::AccessLib +); our $VERSION = '2.0.10'; @@ -75,15 +77,15 @@ sub delOIDCConsent { my $epoch = $params->{epoch}; my $rp = $params->{rp}; - my $id = $req->params('sessionId') + my $id = $req->params('sessionId') or return $self->sendError( $req, 'sessionId is missing', 400 ); - $req->parameters->set('sessionId', $self->_maybeDecryptSessionId($id)); + $req->parameters->set( 'sessionId', $self->_maybeDecryptSessionId($id) ); if ( $rp =~ /\b[\w-]+\b/ and defined $epoch ) { $self->logger->debug( "Call procedure deleteOIDCConsent with RP=$rp and epoch=$epoch"); - return $self->deleteOIDCConsent( $req ); + return $self->deleteOIDCConsent($req); } else { return $self->sendError( $req, undef, 400 ); @@ -448,12 +450,12 @@ sub _maybeEncryptSessionId { sub delSession { my ( $self, $req ) = @_; - my $id = $req->params('sessionId') + my $id = $req->params('sessionId') or return $self->sendError( $req, 'sessionId is missing', 400 ); - $req->parameters->set('sessionId', $self->_maybeDecryptSessionId($id)); + $req->parameters->set( 'sessionId', $self->_maybeDecryptSessionId($id) ); - return $self->SUPER::delSession( $req ); + return $self->SUPER::delSession($req); } sub cmpIPv4 { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Viewer.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Viewer.pm index 80efd4162..1e487b8e8 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Viewer.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Viewer.pm @@ -7,14 +7,12 @@ use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Common::UserAgent; use URI::URL; -use feature 'state'; - extends 'Lemonldap::NG::Manager::Conf'; has diffRule => ( is => 'rw', default => sub { 0 } ); has brwRule => ( is => 'rw', default => sub { 0 } ); -our $VERSION = '2.0.8'; +our $VERSION = '2.0.10'; ############################# # I. INITIALIZATION METHODS # diff --git a/lemonldap-ng-manager/t/test-lib.pm b/lemonldap-ng-manager/t/test-lib.pm index c0b80df2b..a90f4f99e 100644 --- a/lemonldap-ng-manager/t/test-lib.pm +++ b/lemonldap-ng-manager/t/test-lib.pm @@ -2,7 +2,7 @@ use strict; use Data::Dumper; -use 5.10.0; + use_ok('Lemonldap::NG::Manager::Cli::Lib'); our $client; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/AD.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/AD.pm index de15c54ed..b4f959548 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/AD.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/AD.pm @@ -29,25 +29,19 @@ sub confirm { } sub modifyPassword { - my ( $self, $req, $pwd ) = @_; + my ( $self, $req, $pwd, $useMail ) = @_; my $dn = $req->data->{dn} || $req->sessionInfo->{_dn}; unless ($dn) { - $self->logger->error('"dn" is not set, aborting password modification'); + $self->logger->error('"dn" is not set, abort password modification'); return PE_ERROR; } - my $rule = $self->p->HANDLER->buildSub( - $self->p->HANDLER->substitute( - $self->conf->{portalRequireOldPassword} - ) - ); - unless ($rule) { - my $error = $self->p->HANDLER->tsv->{jail}->error || '???'; - } + my $requireOldPassword = ( $req->userData - ? $rule->( $req, $req->userData ) - : $rule->( $req, $req->sessionInfo ) + ? $self->requireOldPwdRule->( $req, $req->userData ) + : $self->requireOldPwdRule->( $req, $req->sessionInfo ) ); + $requireOldPassword = 0 if $useMail; # Ensure connection is valid $self->bind; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/Base.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/Base.pm index 47abde07a..83878a14f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/Base.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/Base.pm @@ -21,8 +21,19 @@ our $VERSION = '2.0.10'; # INITIALIZATION +has requireOldPwdRule => ( is => 'rw' ); + sub init { - $_[0]->p->{_passwordDB} = $_[0]; + my ($self) = shift; + $self->requireOldPwdRule( + $self->p->buildRule( + $self->conf->{portalRequireOldPassword}, + 'portalRequireOldPassword' + ) + ); + return 0 unless $self->requireOldPwdRule; + + $self->p->{_passwordDB} = $self; } # INTERFACE diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/LDAP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/LDAP.pm index fdf8b5059..476fc3fd3 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/LDAP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/LDAP.pm @@ -28,31 +28,25 @@ sub confirm { } sub modifyPassword { - my ( $self, $req, $pwd ) = @_; + my ( $self, $req, $pwd, $useMail ) = @_; my $dn; my $requireOldPassword; - my $rule = $self->p->HANDLER->buildSub( - $self->p->HANDLER->substitute( - $self->conf->{portalRequireOldPassword} - ) - ); - unless ($rule) { - my $error = $self->p->HANDLER->tsv->{jail}->error || '???'; - } + if ( $req->data->{dn} ) { $dn = $req->data->{dn}; - $requireOldPassword = $rule->( $req, $req->userData ); + $requireOldPassword = $self->requireOldPwdRule->( $req, $req->userData ); $self->logger->debug("Get DN from request data: $dn"); } else { $dn = $req->sessionInfo->{_dn}; - $requireOldPassword = $rule->( $req, $req->sessionInfo ); + $requireOldPassword = $self->requireOldPwdRule->( $req, $req->sessionInfo ); $self->logger->debug("Get DN from session data: $dn"); } unless ($dn) { $self->logger->error('"dn" is not set, aborting password modification'); return PE_ERROR; } + $requireOldPassword = 0 if $useMail; # Ensure connection is valid $self->bind; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm index e6f3552db..19b2b7d5c 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm @@ -473,16 +473,11 @@ sub changePwd { return $cpq; } - # Modify the password TODO: change this - # Populate $req->{user} for logging purpose - my $tmp = $self->conf->{portalRequireOldPassword}; - $self->conf->{portalRequireOldPassword} = 0; $req->user( $req->{sessionInfo}->{_user} ); my $result = $self->p->_passwordDB->modifyPassword( $req, $req->data->{newpassword}, 1 ); $req->{user} = undef; - $self->conf->{portalRequireOldPassword} = $tmp; # Mail token can be used only one time, delete the session if all is ok unless ( $result == PE_PASSWORD_OK or $result == PE_OK ) {