Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions library/Icinga/Application/Hook/AuthenticationHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Icinga\User;
use Icinga\Web\Hook;
use Icinga\Application\Logger;
use Throwable;

/**
* Icinga Web Authentication Hook base class
Expand All @@ -28,6 +29,15 @@ public function onLogin(User $user)
{
}

/**
* 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
*
Expand All @@ -37,6 +47,24 @@ public function onLogout(User $user)
{
}

/**
* 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)
*
Expand Down
4 changes: 4 additions & 0 deletions library/Icinga/Authentication/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ public function authenticateFromSession()
$this->removeAuthorization();
}
}

if ($this->user !== null) {
AuthenticationHook::triggerAuthFromSession($this->user);
}
}

/**
Expand Down
Loading