登录后,控制器必须返回响应(NULL给定)



我正在使用Symfony FosuserBundle,SonatauserBundle,FosfaceBookBundle。我已在我的应用中添加了登录按钮。

我可以使用Facebook登录,但是登录页面后,将页面重定向到DEMO/SECURED/LOGIN_CHECK,我会收到以下错误。

"控制器必须返回响应(给定为null)。您是否忘记了在控制器中的某处添加返回语句?"

我已经看过

未触发服务:控制器必须返回响应(NULL给定)

https://github.com/friendsofsymfony/fosfacebookbundle/issues/186

,但不确定我应该对我的配置进行哪些更改。

以下我的安全配置

security:
    encoders:
        FOSUserBundleModelUserInterface: sha512
    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
    providers:
        chain_provider:
            chain:
                providers: [fos_userbundle, fo_fos_facebook_provider]      
        fos_userbundle:
            id: fos_user.user_manager
        fo_fos_facebook_provider:
            id: my.facebook.user
    firewalls:
        # Disabling the security for the web debug toolbar, the profiler and Assetic.
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
        # -> custom firewall for the admin area of the URL
        admin:
            pattern:            /admin(.*)
            context:            user
            form_login:
                provider:       fos_userbundle
                login_path:     /admin/login
                use_forward:    false
                check_path:     /admin/login_check
                failure_path:   null
            logout:
                path:           /admin/logout
            anonymous:          true
        main:
            pattern: ^/
            context:             user
            form_login:
                provider:       fos_userbundle
                login_path:     /login
                use_forward:    false
                check_path:     /login_check
                failure_path:   null
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true
        public:
            # since anonymous is allowed users will not be forced to login
            pattern:   ^/.*
            fos_facebook:
                app_url: "http://apps.facebook.com/my-app/"
                server_url: "http://localhost/me/my/symfony/web/app_dev.php/"
                login_path: /login
                check_path: /login_check
                default_target_path: /
                provider: fo_fos_facebook_provider
                redirect_to_facebook_login: false
            anonymous: true
    access_control:
        # URL of FOSUserBundle which need to be available to anonymous users      
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # Admin login page needs to be access without credential
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # Secured part of the site
        # This config requires being logged for the whole site and having the admin role for the admin part.
        # Change these rules to adapt them to your needs
        - { path: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
        - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] }
    acl:
        connection: default        

我尝试在下面尝试更改配置,以避免2个防火墙匹配相同的URL模式。

security:
    encoders:
        FOSUserBundleModelUserInterface: sha512
    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
    providers:
        chain_provider:
            chain:
                providers: [fos_userbundle, fo_fos_facebook_provider]      
        fos_userbundle:
            id: fos_user.user_manager
        fo_fos_facebook_provider:
            id: my.facebook.user
    firewalls:
        # Disabling the security for the web debug toolbar, the profiler and Assetic.
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
        # -> custom firewall for the admin area of the URL
        admin:
            pattern:            /admin(.*)
            context:            user
            form_login:
                provider:       fos_userbundle
                login_path:     /admin/login
                use_forward:    false
                check_path:     /admin/login_check
                failure_path:   null
            logout:
                path:           /admin/logout
            anonymous:          true
        main:
            pattern: ^/
            context:             user
            fos_facebook:
                app_url: "http://apps.facebook.com/my-app/"
                server_url: "http://localhost/me/my/symfony/web/app_dev.php/"
                login_path: /login
                check_path: /login_check
                default_target_path: /
                provider: fo_fos_facebook_provider
                redirect_to_facebook_login: false                
            form_login:
                provider:       fos_userbundle
                login_path:     /login
                use_forward:    false
                check_path:     /login_check
                failure_path:   null
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true
    access_control:
        # URL of FOSUserBundle which need to be available to anonymous users      
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # Admin login page needs to be access without credential
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # Secured part of the site
        # This config requires being logged for the whole site and having the admin role for the admin part.
        # Change these rules to adapt them to your needs
        - { path: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
        - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] }
    acl:
        connection: default        

但是我现在遇到不同的错误

"无效ConfigurationException:不允许您为路径" security.firewalls"定义新元素。请在一个配置文件中定义此路径的所有元素。"

,如GIYHUB问题报道:"您不能有2个具有相同模式的防火墙:将使用第一个防火墙匹配,因此您的公共防火墙不能被使用,因为Main已经是All Catch-All"

您的主要模式和公共模式与相同的路线匹配。您可以在这里尝试:http://www.regular-expressions.info/javascriptexample.html

案例: ^/主题:/home确定案例: ^/。*主题/home ok

因此,您有两个与完全相同的URL匹配的防火墙。您必须更改公共防火墙或主要防火墙的路由规则。

我在这里弄清楚并共享我的代码

https://github.com/vishalmelmatti/fossonatauserfacebookintegration

fosuserbundle fosfacebookbundle sonataadminbundle sonatauserbundle。

相关内容

  • 没有找到相关文章

最新更新