Skip to content

IsGranted Attribute not working on LiveComponents #2521

@Mauriceu

Description

@Mauriceu

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:

#[LiveAction]
#[IsGranted("SOME_ROLE")]
public function save(): Response 
{ 
    /** AuthenticationEntrypoint logic will be invoked, implying no logged in User is found */ 
}
#[LiveAction]
public function save(): Response 
{
    $user = $this->security->getUser();
    // User is null
}

My current firewall configuration:

        user:
            pattern: ^/
            lazy: false

            # Repository implements UserLoaderInterface 
            # retrieves the User by comparing an identifier 
            # to either email or username.
            provider: user

            custom_authenticators:
                - App\Security\Authenticator\UserAuthenticator

            entry_point: App\Security\Authenticator\AuthenticationEntryPoint
            user_checker: App\Security\IsDisabledChecker
            login_throttling:
                limiter: "app.user_rate_limiter"

            remember_me:
                secret: '%kernel.secret%'
                lifetime: 604800

            login_link:
                check_route: user_login_link
                signature_properties: [ 'id' ]
                success_handler: App\Security\AutoLoginSuccessHandler

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions