Skip to content

Commit

Permalink
Admin global logout
Browse files Browse the repository at this point in the history
  • Loading branch information
guimard committed Nov 8, 2024
1 parent 65bc470 commit 2ee6ea9
Show file tree
Hide file tree
Showing 11 changed files with 1,887 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Fix SAML regression
* Fix Captcha rule bug
* Add admin global logout

## v2.20.0-3 _(2024-10-25)_
* Add ReCaptcha v3
Expand Down
1 change: 1 addition & 0 deletions full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUN \
echo patch ignorepollers.patch && patch -p1 < ignorepollers.patch && \
echo patch fixedLogout.patch && patch -p1 < fixedLogout.patch && \
echo patch matrix-token-exchange.patch && patch -p1 < matrix-token-exchange.patch && \
echo patch globalLogout.patch && patch -p1 < globalLogout.patch && \
rm -f *.patch && \
LLNG_DEFAULTCONFFILE=/etc/lemonldap-ng/lemonldap-ng.ini \
perl -MLemonldap::NG::Manager::Build -e 'Lemonldap::NG::Manager::Build->run( \
Expand Down
77 changes: 77 additions & 0 deletions full/globalLogout.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
diff --git a/usr/share/perl5/Lemonldap/NG/Manager/Sessions.pm b/usr/share/perl5/Lemonldap/NG/Manager/Sessions.pm
index edf6a5f19..89c7571d2 100644
--- a/usr/share/perl5/Lemonldap/NG/Manager/Sessions.pm
+++ b/usr/share/perl5/Lemonldap/NG/Manager/Sessions.pm
@@ -40,6 +40,13 @@ sub init {
['DELETE']
)

+ # DELETE ALL SESSIONS FOR A USER
+ ->addRoute(
+ sessions =>
+ { glogout => { ':sessionType' => { ':sessionId' => 'userLogout' } } },
+ ['POST']
+ )
+
# DELETE OIDC CONSENT
->addRoute(
sessions => {
@@ -60,6 +67,58 @@ sub init {
return 1;
}

+#
+# User logout
+#
+
+sub userLogout {
+ my ( $self, $req ) = @_;
+
+ my $mod = $self->getMod($req)
+ or return $self->sendError( $req, undef, 400 );
+ my $id = $req->params('sessionId')
+ or return $self->sendError( $req, 'sessionId is missing', 400 );
+ my $session = $self->getApacheSession( $mod, $id );
+
+ my $uidKey = Lemonldap::NG::Handler::Main->tsv->{whatToTrace};
+ my $uid = $session->data->{$uidKey};
+
+ my $count = 0;
+ foreach my $storage (qw(oidcStorage sessionStorage)) {
+ my $storageModule =
+ Lemonldap::NG::Handler::Main->tsv->{"${storage}Module"};
+ if ( defined $storageModule ) {
+ next if ( $storageModule eq "Apache::Session::Memcached" );
+ my $opts = Lemonldap::NG::Handler::Main->tsv->{"${storage}Options"};
+ $opts->{backend} = $storageModule;
+ my $sessions =
+ Lemonldap::NG::Common::Apache::Session->searchOn( $opts, $uidKey,
+ $uid );
+ my @keys;
+ if ( $sessions and %$sessions ) {
+ @keys = keys %$sessions;
+ foreach my $sid (@keys) {
+ my $session = Lemonldap::NG::Common::Session->new(
+ storageModule => $storageModule,
+ storageModuleOptions => $opts,
+ cacheModule => Lemonldap::NG::Handler::Main->tsv
+ ->{sessionCacheModule},
+ cacheModuleOptions => Lemonldap::NG::Handler::Main->tsv
+ ->{sessionCacheOptions},
+ id => $sid,
+ );
+ if ( $session->data ) {
+ $session->remove;
+ $count++;
+ }
+ }
+ }
+ }
+ }
+ Lemonldap::NG::Handler::PSGI::Main->localUnlog( $req, $id );
+ return $self->sendJSONresponse( $req, { result => 1, count => $count } );
+}
+
#######################
# II. CONSENT METHODS #
#######################
Loading

0 comments on commit 2ee6ea9

Please sign in to comment.