symfony2 API身份验证和路由

时间:2011-09-23 12:00:15

标签: php url-routing symfony firewall

我按照创建自定义身份验证提供程序的说明进行操作:http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

应用/配置/安全

firewalls:
    wsse_protection:
        pattern: ^/api/.*
        wsse: true
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
        logout:       true
        anonymous:    true

现在我在路由器的控制器中有一些操作。 e.g:

带有listAction的ExampleController

路由

example_list:
    pattern: /example/list
    defaults: { ... }

我是否必须将所有路由复制到example_api_list?因为api / example / list不起作用(找不到/ api / example / list的路由)。我认为防火墙的模式是所有已定义路由的前缀。

1 个答案:

答案 0 :(得分:1)

防火墙不是前缀,它是与传入路由匹配的正则表达式。在这种情况下,以/api开头的任何内容都会与您的wsse_protection防火墙匹配,并且所有内容都将与您的main防火墙相匹配。

要在/ api / *下创建路由,您必须单独定义路由。

相关问题