Introduce AuthenticationHook#onAuthFromSession() (#5467)
Some checks failed
L10n Update / update (push) Has been cancelled
CI / PHP (push) Has been cancelled

Especially useful for code not for ApplicationStateHook due to the fact
that a user can block requests to /application-state.
This commit is contained in:
Eric Lippmann 2026-01-28 09:59:08 +01:00 committed by GitHub
commit a73cd1c758
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -5,6 +5,7 @@ namespace Icinga\Application\Hook;
use Icinga\User;
use Icinga\Web\Hook;
use Icinga\Application\Logger;
use Throwable;
/**
* Icinga Web Authentication Hook base class
@ -28,6 +29,15 @@ abstract class AuthenticationHook
{
}
/**
* Triggered after Icinga Web authenticates a user with the current session
*
* @param User $user
*/
public function onAuthFromSession(User $user): void
{
}
/**
* Triggered before logout from Icinga Web
*
@ -37,6 +47,24 @@ abstract class AuthenticationHook
{
}
/**
* Call the onAuthFromSession() method of all registered {@link AuthenticationHook}s
*
* @param User $user
*/
public static function triggerAuthFromSession(User $user): void
{
/** @var static $hook */
foreach (Hook::all(self::NAME) as $hook) {
try {
$hook->onAuthFromSession($user);
} catch (Throwable $e) {
// Avoid error propagation if a hook failed in a third party application
Logger::error($e);
}
}
}
/**
* Call the onLogin() method of all registered AuthHook(s)
*

View file

@ -230,6 +230,10 @@ class Auth
$this->removeAuthorization();
}
}
if ($this->user !== null) {
AuthenticationHook::triggerAuthFromSession($this->user);
}
}
/**