-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Throwing AccessDeniedException when getCredentials() in GuardAuthenticator are null #23253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Would you be able to point out this exception or the PR/commit in which it has been introduced? The guard behavior seems unchanged. |
Well, maybe it was throw in Symfony3.2 as well but it was catched by something in the middle? All I know is now (Symfony 3.3) this exception goes directly to my ExceptionListener which didn't happen in Symfony3.2.
|
This is from the documentation (version 3.3):
My getCredentials method returns null but the start method is never called. An exception is thrown instead. |
@ussuritiger exactly. It is not a problem if you do not have your own ExceptionListener - then symfony catch that exception and call |
Same issues here! AccessDeniedException instead of AuthenticationException in start(), and the start() method can't be type-hinted with AccessDeniedException and is never called! |
Status: reviewed I'm on it. Edit: culprit found, working on the fix. |
Can someone try #23291 and confirm it fixes the issue? |
@chalasr thank you, I've just checked your fix and seems to be working fine now :) |
thanks for the quick confirmation @nospor |
You are welcome. But it is you who did the most job, so well done and thx once more for your fix :) |
The next maintenance releases should occur in ~10 days (once a month). |
This PR was merged into the 3.3 branch. Discussion ---------- [Security] Fix Firewall ExceptionListener priority | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23253 | License | MIT | Doc PR | n/a When making EventDispatcher able to lazy load listeners, we stopped using `ContainerAwareEventDispatcher::addListenerService/addSubcriberService`, we use `EventDispatcher::addListener()` instead. This change makes that the order of listeners is different than before, because `ContainerAwareEventDispatcher` calls `addListener()` tardily so that factories are never stored in `EventDispatcher::$listeners`. Example diff due to the behavior change in 3.3 (registering an `AppBundle\ExceptionListener::doCatch()` exception listener in the fullstack): 3.2 ---- ```php array:5 0 => "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException" 1 => "AppBundle\ExceptionListener::doCatch" 2 => "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException" 3 => "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onException" 4 => "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException" ] ``` 3.3 ---- ```php array:5 [ 0 => "AppBundle\ExceptionListener::doCatch" 1 => "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException" 2 => "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onException" 3 => "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException" 4 => "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException" ] ``` (that is what breaks #23253, the lazy listener is called before the runtime firewall exception listener on dispatch). This fixes the order by increasing the security exception listener priority. Commits ------- 8014b38 [Security] Fix Firewall ExceptionListener priority
Hi, I upgraded to Symfony3.3 from 3.2. I am using GuardAuthenticator to authenticate my users. I also have ExceptionListener to provide my own responses to different exceptions depending on is it AJAX or not.
In class below there are two methods
According to documentation methos
start()
is called when methodgetCredentials()
returns null;It was working fine with symfony3.2. But when I upgraded to symfony3.3 it stopped working. Method
start()
was not called anymore. After long investigating it appeard, that in symfony3.3 you throw AccessDeniedException which you didn't in Symfony3.2. And now, when I have my ExceptionListener yours AccessDeniedException goes first to my ExceptionListener and then I return some Response and methodstart()
is not called anylonger. I had to add some conditions in my ExceptionListener that when is raised AccessDeniedException i must doreturn;
and then methodstart()
is finally called.Well, IMHO it is not a good solution. I think you shouldn't throw exception when
getCredentials()
returns NULL. I think you should do what you said you will do which is callstart()
method directly. Now I, and maybe others need to play with this strange situation.Robert
The text was updated successfully, but these errors were encountered: