简体   繁体   中英

Symfony Role Rules for Routes - Access Denied

I am having issues securing a route 'dashboard' to a custom user role. I am using FOSUserBundle and I am aware that due to due users are given ROLE_USER by default - even though this role does appear in the user table.

On a user sign in (this happens via Steam) I add a new custom

$user->setRoles(['ROLE_LOGGED_STEAM_USER']);

My issue flows as such - User hits site - User logs in - redirect to Dashboard route - with the access denied error.

I have also disabled the security line and dumping out the ROLES to which I can pull from the token user object to confirm the ROLE exists and matches the rule

Here is my security ACL

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    steamauth:
        id: steam.user_provider
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        provider: steamauth
        pattern: ^/
        form_login:
            provider: fos_userbundle

        logout:       true
        anonymous:    true
        form_login:
            login_path:   login
            check_path:   login_check
        steam:
            default_route: controller.dashboard.home

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/dashboard, role: ROLE_LOGGED_STEAM_USER }

Initially, I wasn't aware that all roles had to Begin with ROLE_*

Here is a screenshot of the user entry with the role attached here

I hope its somthing simple im just overlooked so any help would be great!

Thanks it advance for any help/suggestions!

不确定,但我认为您有错别字,请尝试将角色改为“ s”

 - { path: ^/dashboard, roles: ROLE_LOGGED_STEAM_USER }

I think you must register your custom role on the " role_hierarchy " so the code will be:

role_hierarchy:
    ROLE_ADMIN:       [ROLE_USER, ROLE_LOGGED_STEAM_USER]
    ROLE_SUPER_ADMIN: ROLE_ADMIN

Hope it help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM