访问被拒绝不起作用symfony

时间:2017-08-28 16:36:10

标签: symfony

当用户拒绝用户访问时,我在重定向方面遇到一个小问题。后者没有合适的角色。

不是重定向到索引,而是重定向到登录页面,尽管在我的代码中我放了:access_denied_url:/

例如,我尝试访问具有错误角色的下一页: - {path:^ / dashboard,role:ROLE_SONATA_ADMIN}

我希望他将我重定向到索引,而不是登录页面

我的security.yml:

# To get started with security, check out the documentation:
                # https://symfony.com/doc/current/security.html
                security:
                    access_denied_url: /
                    role_hierarchy:
                        ROLE_ADMIN:       [ROLE_USER, ROLE_SONATA_ADMIN]
                        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
                        SONATA:
                            - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT  # if you are using acl then this line must be commented

                    # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
                    providers:
                        in_memory:
                            memory: ~

                        fos_userbundle:
                            id: fos_user.user_provider.username_email

                    firewalls:
                        # disables authentication for assets and the profiler, adapt it according to your needs
                        dev:
                            pattern: ^/(_(profiler|wdt)|css|images|js)/
                            security: false

                        admin:
                            pattern:      ^/
                            form_login:
                                provider:       fos_userbundle
                                login_path:     /login
                                use_forward:    false
                                check_path:     /login_check
                                failure_path:   /login
                                default_target_path: /dashboard
                                remember_me: false 
                            logout:
                                path:           /logout
                                target:         /
                                invalidate_session: true # the authenticated session will be unavailable afterwards
                            anonymous:    true

                    encoders:
                        FOS\UserBundle\Model\UserInterface: sha512

                    acl:
                        connection: default

                    access_control:
                        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
                        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
                        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
                        - { path: ^/admin/*, role: ROLE_SUPER_ADMIN }
                        - { path: ^/admin/dashboard, role: ROLE_SUPER_ADMIN }
                        - { path: ^/dashboard, role: ROLE_SONATA_ADMIN }

我的rounting.yml:

mybundle:
    resource: "@MyBundle/Controller/"
    type: annotation
    prefix:   /

#app:
 #   resource: '@AppBundle/Controller/'
 #   type: annotation

admin_area:
    resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
    prefix: /admin

sonata_user_security:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_security_1.xml"

sonata_user_resetting:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_resetting_1.xml"
    prefix: /resetting

sonata_user_profile:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_profile_1.xml"
    prefix: /profile

sonata_user_register:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_registration_1.xml"
    prefix: /register

sonata_user_change_password:
    resource: "@SonataUserBundle/Resources/config/routing/sonata_change_password_1.xml"
    prefix: /profile

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

sonata_user_admin_security:
   resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
   prefix: /admin

sonata_user_admin_resetting:
   resource: '@SonataUserBundle/Resources/config/routing/admin_resetting.xml'
   prefix: /admin/resetting

fos_user_group:
    resource: "@FOSUserBundle/Resources/config/routing/group.xml"
    prefix: /group

谢谢

0 个答案:

没有答案