Closed slejnej closed 1 year ago
@slejnej hi! Thank you for your question.
It's important to remember that authentication events are security events. So you need to specify correct value for a dispatcher
property of the listener configuration.
For example, if you use this bundle in main
firewall, you should specify security.event_dispatcher.main
as a dispatcher
for your listener.
@a-menshchikov Thank you for your response.
Maybe some updates to the README with an example how to use that because tagging for the event
and method
is then not sufficient to create a listener, but it also needs dispatcher: security.event_dispatcher.main
(or firewall used in) defined when wiring.
Subscriber to Nbgrp\OneloginSamlBundle\Event\UserCreatedEvent
is never visible for this event, but same subscriber for CheckPassportEvent::class
is listed.
The code:
use Nbgrp\OneloginSamlBundle\Event\UserCreatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
...
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return [
UserCreatedEvent::class => 'onUserCreated',
CheckPassportEvent::class => ['onUserCreated', -1],
];
}
debug output:
"Nbgrp\OneloginSamlBundle\Event\UserCreatedEvent" event
-------------------------------------------------------
------- ----------------------------------------------------------------------------- ----------
Order Callable Priority
------- ----------------------------------------------------------------------------- ----------
#1 Nbgrp\OneloginSamlBundle\EventListener\User\UserCreatedListener::__invoke() 0
------- ----------------------------------------------------------------------------- ----------
"Nbgrp\OneloginSamlBundle\Event\UserModifiedEvent" event
--------------------------------------------------------
"Symfony\Component\Security\Http\Event\CheckPassportEvent" event
----------------------------------------------------------------
------- ------------------------------------------------------------------------------------------- ----------
Order Callable Priority
------- ------------------------------------------------------------------------------------------- ----------
#1 Symfony\Component\Security\Http\EventListener\UserProviderListener::checkPassport() 2048
#2 Symfony\Component\Security\Http\EventListener\UserProviderListener::checkPassport() 1024
#3 Symfony\Component\Security\Http\EventListener\CsrfProtectionListener::checkPassport() 512
#4 Symfony\Component\Security\Http\EventListener\UserCheckerListener::preCheckCredentials() 256
#5 Nbgrp\OneloginSamlBundle\EventListener\User\DeferredUserListener::dispatchDeferredEvent() 0
#6 Symfony\Component\Security\Http\EventListener\CheckCredentialsListener::checkPassport() 0
#7 App\EventSubscriber\SecurityEventSubscriber::onUserCreated() -1
------- ------------------------------------------------------------------------------------------- ----------
I don't know the way to specify a certain dispatcher when use a subscriber. But I have no idea why you need to use a subsciber in a Symfony 6 application while you can use the #[AsEventListener(dispatcher: 'security.event_dispatcher.main')]
attribute. IMO this is the same approach as we've had earlier with event subscribers.
Tried with Listener and Subscriber, but despite
DeferredUserListener
is callingdispatch
nothing is kicking in.Subscriber:
Not called listeners: