-
-
Notifications
You must be signed in to change notification settings - Fork 356
IsGranted Attribute not working on LiveComponents #2521
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
Do you have the same problems with default security settings / tools ? |
No, applying #[IsGranted] on a normal Controller works as expected. |
Sorry no, i meant the opposite. Do the IsGranted attribute work on your component, with a more traditional / basic securty settings (firewall / authenticator / etc) ? |
I've pretty much removed everything from the security config and it still is not working. Some additional info: We use keycloak to authenticate our users and create a customized UserInterface DTO. This DTO only contains a few additional properties for conditional rendering. The AuthenticationToken containing that DTO is correctly retrieved from the TokenStorage when invoking a normal controller, IsGranted works and everything else does too. Rendering a LiveComponent within a normal Controllers request context - e.g. GET request to a controller which renders a twig template that includes a LiveComponent - the AuthenticationToken is also correctly retrieved. However, when invoking a LiveAction the TokenStorage::getToken() function always returns NULL. I'll try and setup a minimal reproducer in a few days time. |
Do you use custom events / event listeners in your Authenticator ? Could you check the priorities:
|
No custom events in the authenticator. The authenticator just retrieves some query-params from the URL and creates a SelfValidatingPassport using these query-params. The provider retrieves the user data from the keycloak endpoint by using whatever value was used to create the Passport as identifier. The workflow is pretty similar to any in-built symfony authentication/provider system. "kernel.controller" event
"kernel.controller_arguments" event
"kernel.exception" event
"kernel.finish_request" event
"kernel.request" event
"kernel.response" event
"kernel.terminate" event
"kernel.view" event
|
I setup a repo in hopes of reproducing the issue. However, isGranted seems to be working here. The reproducer uses the in-built form-login and in_memory provider.... |
Problem solved. The security config includes not only one but two firewalls and the security context did not match the correct one, which led to the "sessionKey" property in the ContextListener being set incorrectly. Guess I should've posted the full security.yaml - hindsight 20/20, will do better next time 🗡 We use 2 firewalls, one for authenticating Users and another for authenticating Admins. The admin firewall pattern is "^/admin" the User firewall has a pattern of "^/". Guess you see where this is going... Solved the issue by changing the admin firewall pattern to: "^/(admin|_components/Admin:)" |
Well, i would not have checked that first, to be honest. Happy if everything is good for you! |
As per the docs LiveComponents are like normal Symfony controllers, as that you can also use the Attributes you usually use.
However, when a LiveAction is invoked the currently logged in User is null, probably due to some priority settings.
This in turn leads to the #[isGranted] attribute failing - also every other (manual) security check fails, because Security::getUser() always returns null.
Example Code:
My current firewall configuration:
The text was updated successfully, but these errors were encountered: