简体   繁体   中英

access denied 403 symfony2

I have a problem with the authentication on my webapp. When the user log on the app, have this error:

Access Denied
403 Forbidden - AccessDeniedHttpException
1 linked Exception: AccessDeniedException »

The user has the problem when log in with the role ROLE_BASIC_INSTALLER , I put it on the hierarchy.yml but it doesnt work. Thats my code:

security:
role_hierarchy:
    ROLE_PROMOTER:          [ ROLE_USER ]
    ROLE_INSTALLER:         [ ROLE_USER ]
    ROLE_INSPECTOR_INSTALLER:         [ ROLE_USER ]
    ROLE_INSPECTOR_BASIC_INSTALLER: [ROLE_USER]
    ROLE_BASIC_INSTALLER:   [ ROLE_USER ]
    ROLE_PRODUCER:          [ ROLE_USER ]        
    ROLE_INSPECTOR:         [ ROLE_USER ]
    ROLE_MANAGER:           [ ROLE_USER, ROLE_INSPECTOR, ROLE_INSTALLER]
    ROLE_ADMIN:             [ ROLE_USER, ROLE_MANAGER, ROLE_INSPECTOR, ROLE_INSTALLER, ROLE_PRODUCER ]
    ROLE_SUPER_ADMIN:       [ ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

firewalls:
    secured_area:
        pattern:    ^/
        anonymous: ~
        form_login:
            login_path:  login
            check_path:  login_check
            always_use_default_target_path: true
            default_target_path: /admin/dashboard
        http_basic:
            realm: "Secured Demo Area"
        logout:
          path: /logout
          target: /login              
        anonymous:    true
access_control:
    - { path: ^/admin/dashboard, roles: ROLE_USER }
    - { path: ^/admin/dashboard, roles: ROLE_USER }
    #ROLE_USER }
    - { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/logout, roles:  ROLE_USER }


#       - { path: ^/admin, roles: ROLE_ADMIN }
    encoders:
              Agc\ManagerBundle\Entity\User: { algorithm: sha1, encode_as_base64: false, iterations: 1 }
              #Symfony\Component\Security\Core\User\User: { algorithm: sha1, encode_as_base64: false, iterations: 1 }

    providers:
        usuarios:
            entity: { class: Agc\ManagerBundle\Entity\User,  property: username }

In localhost, the app haven't any problems, its appear a permission for http but I'm lost.

maybe you need to make sure that the user that you login with has a role as ROLE_USER by default its ROLE_ADMIN so in your security.yml file try this

access_control:
- { path: ^/admin/dashboard, roles: ROLE_ADMIN }
- { path: ^/admin/dashboard, roles: ROLE_ADMIN }
- { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/logout, roles:  ROLE_ADMIN }

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