mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 11:18:51 +02:00
Use LogoutEvent listener instead of deprecated LogoutHandler.
This commit is contained in:
parent
7f263e9916
commit
d9c83d8bb2
3 changed files with 19 additions and 4 deletions
|
@ -16,7 +16,8 @@ security:
|
||||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||||
security: false
|
security: false
|
||||||
main:
|
main:
|
||||||
anonymous: lazy
|
anonymous: true
|
||||||
|
lazy: true
|
||||||
user_checker: App\Security\UserChecker
|
user_checker: App\Security\UserChecker
|
||||||
|
|
||||||
two_factor:
|
two_factor:
|
||||||
|
@ -40,7 +41,6 @@ security:
|
||||||
logout:
|
logout:
|
||||||
path: logout
|
path: logout
|
||||||
target: homepage
|
target: homepage
|
||||||
handlers: [App\EventSubscriber\LogSystem\LogoutLoggerHandler]
|
|
||||||
|
|
||||||
remember_me:
|
remember_me:
|
||||||
secret: '%kernel.secret%'
|
secret: '%kernel.secret%'
|
||||||
|
|
|
@ -78,6 +78,12 @@ services:
|
||||||
$allow_attachments_downloads: '%partdb.attachments.allow_downloads%'
|
$allow_attachments_downloads: '%partdb.attachments.allow_downloads%'
|
||||||
$mimeTypes: '@mime_types'
|
$mimeTypes: '@mime_types'
|
||||||
|
|
||||||
|
App\EventSubscriber\LogSystem\LogoutLoggerListener:
|
||||||
|
tags:
|
||||||
|
- name: 'kernel.event_listener'
|
||||||
|
event: 'Symfony\Component\Security\Http\Event\LogoutEvent'
|
||||||
|
dispatcher: security.event_dispatcher.main
|
||||||
|
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
# Attachment system
|
# Attachment system
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
|
|
|
@ -48,12 +48,13 @@ use App\Services\LogSystem\EventLogger;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||||
|
use Symfony\Component\Security\Http\Event\LogoutEvent;
|
||||||
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
|
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This handler logs to event log, if a user logs out.
|
* This handler logs to event log, if a user logs out.
|
||||||
*/
|
*/
|
||||||
class LogoutLoggerHandler implements LogoutHandlerInterface
|
class LogoutLoggerListener
|
||||||
{
|
{
|
||||||
protected $logger;
|
protected $logger;
|
||||||
protected $gpdr_compliance;
|
protected $gpdr_compliance;
|
||||||
|
@ -64,8 +65,16 @@ class LogoutLoggerHandler implements LogoutHandlerInterface
|
||||||
$this->gpdr_compliance = $gpdr_compliance;
|
$this->gpdr_compliance = $gpdr_compliance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logout(Request $request, Response $response, TokenInterface $token): void
|
|
||||||
|
public function __invoke(LogoutEvent $event)
|
||||||
{
|
{
|
||||||
|
$request = $event->getRequest();
|
||||||
|
$token = $event->getToken();
|
||||||
|
|
||||||
|
if ($token === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance);
|
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance);
|
||||||
$user = $token->getUser();
|
$user = $token->getUser();
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
Loading…
Add table
Add a link
Reference in a new issue