Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route "admin/login" does not exist Error Symfony2 + SonataAdminBundle

I followed a tutorial to set up SonataAdmin and FosUer
FosUser seems okay for the connection and the disconnection

However for Sonata I can't access to
>my_host/web/app_dev.php/admin/dashboard
When I try the firewall redirect to : my_host/web/app_dev.php/admin/login

And throws an error :
Route "admin/login" does not exist.
500 Internal Server Error - RouteNotFoundException

Routing.yml looks correct :

admin:
     resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
     prefix: /admin
_sonata_admin:
     resource: .
     type: sonata_admin
     prefix: /admin
soanata_user:
     resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
     prefix: /admin[/xml]

Config.yml :

sonata_block:
    default_contexts: [cms]
    blocks:
        sonata.admin.block.admin_list:
            contexts:   [admin]
        sonata.block.service.text:
        sonata.block.service.action:
        sonata.block.service.rss:
sonata_admin:
    title:      Admin Panel
    templates:
        ## default global templates
        layout:  SonataAdminBundle::standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig
        ## default actions templates, should extend a global templates
        list:    SonataAdminBundle:CRUD:list.html.twig
        show:    SonataAdminBundle:CRUD:show.html.twig
        edit:    SonataAdminBundle:CRUD:edit.html.twig
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Application\Sonata\UserBundle\Entity\User

Security.yml :

firewalls:
    admin:
        pattern:      /admin(.*)
        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

        # defaut login area for standard users
        main:
            pattern:      .*
            form_login:
                provider:       fos_userbundle
                login_path:     /login
                use_forward:    false
                check_path:     /login_check
                failure_path:   null
            logout:       true
            anonymous:    true

    access_control:
             # URL of FOSUserBundle which need to be available to anonymous users
        - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }

        # -> custom access control for the admin area of the URL
        - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/login-check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        # -> end

        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, 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 }

php app/console route:debug:

admin_sonata_user_group_show            ANY      /admin/sonata/user/group/{id}/show
admin_sonata_user_group_export          ANY      /admin/sonata/user/group/export
sonata_user_admin_security_login        ANY      /admin[/xml]/login
sonata_user_admin_security_check        ANY      /admin[/xml]/login_check
sonata_user_admin_security_logout       ANY      /admin[/xml]/logout

If I had IS_AUTHENTICATED_ANONYMOUSLY into role :
at line - { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] }
I can access to admin/dashboard, because I'm not redirect to admin/login, so I think is not a sonataBundle's problem.

Have you any idea?

Thank a lot.

like image 810
Morgan Avatar asked Dec 11 '12 15:12

Morgan


1 Answers

You have to add the routing information inside your app/config/routing.yml

sonata_user:
    resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
    prefix: /admin
like image 133
pyjavo Avatar answered Sep 30 '22 04:09

pyjavo