2011-09-23 60 views
0

我跟着用於創建自定義身份驗證提供者的指令:http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.htmlSymfony2的API認證和路由

應用程序/配置/安全

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

現在我有與路由控制器的一些行動。 e.g:

ExampleController用的listAction

路由

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

我一定要所有路由複製到example_api_list?因爲api/example/list不起作用(沒有爲/ api/example/list找到路由)。我認爲來自防火牆的模式是所有定義的路由的前綴。

回答

1

防火牆不是一個前綴,它是一個匹配傳入路由的正則表達式。在這種情況下,任何以/api開頭的內容都將與您的wsse_protection防火牆相匹配,並且所有遇到的情況都將與您的main防火牆相匹配。

要在/ api/*下創建路由,您必須單獨定義路由。

+0

好的。謝謝。與此同時,我在確保控制器方法方面遇到了一些問題。添加@Secure(roles =「ROLE_ADMIN」)註釋將導致重播附加。你知道如何解決這個問題或者是什麼原因? – Uwe

+0

與security.yml中的$ this-> get('security.context') - > isGranted('ROLE_ADMIN')或access_control改爲ROLE_ADMIN一樣。 – Uwe