From 0b709c791d7c765fb9bf6f0c392e68c696f15a39 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Mon, 19 Dec 2022 23:05:11 +1300 Subject: [PATCH] Fix the storing of cached credentials when an authentication hook is used. Thank you LDAP tests for picking up this issue! --- inc/HTTPAuthSession.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/inc/HTTPAuthSession.php b/inc/HTTPAuthSession.php index e31b2a9d..c2768b55 100644 --- a/inc/HTTPAuthSession.php +++ b/inc/HTTPAuthSession.php @@ -368,11 +368,14 @@ class HTTPAuthSession { * - Configuration data will be in $c->authenticate_hook['config'], which might be an array, or whatever is needed. */ $principal = call_user_func( $c->authenticate_hook['call'], $username, $password ); + if ( $principal !== false && !($principal instanceof Principal) ) { + $principal = new Principal('username', $username); + } + if ( $principal === false ) { $this->SetCache($username, $password, 'fail'); - } else if (!($principal instanceof Principal) ) { + } else { $this->SetCache($username, $password, 'pass'); - $principal = new Principal('username', $username); } return $principal;