2017-08-08 62 views
0

我有一個將被用來作爲一個REST API一個symfony的2.8應用後端如何在symfony 2.8中對同一模式使用多個防火牆?

我想補充的安全性,所有終點匹配^/API 我想能夠使用3種不同的認證方法^/api

我使用的是uma/psr7-hmac-bundle,friendsofsymfony/oauth-server-bundle,APIKey認證。

我定義了3個不同的防火牆,如果我刪除了其他兩個防火牆,一切都適用於每個防火牆。

firewalls: 
     dev: 
      pattern: ^/(_(profiler|wdt)|css|images|js)/ 
      security: false 

     oauth_token: 
      pattern: ^/oauth/v2/token 
      security: false 

     oauth_authorize: 
      pattern: ^/oauth/v2/auth 
      security: false 

     api_key: 
      pattern: ^/api 
      stateless: true 
      simple_preauth: 
       authenticator: api_key_authenticator 
      provider: api_key_user_provider 

     oauth_api: 
      pattern: ^/api 
      stateless: true 
      fos_oauth: true 
      provider: oauth_user 

     hmac_api: 
      pattern: ^/api 
      stateless: true 
      hmac: 
       apikey_header: 'X-Custom-Header-Key' 
      provider: hmac_user 

如何將所有3個防火牆一起使用(鏈接它們)? (hmac_api,oauth_api,api_key)

我看着衛兵,但我不知道如何定義/實現HMAC和oAuth的Authenticators。

我查看了防火牆上下文,但因爲它是無狀態的,所以無法工作。

基本上我怎樣才能鏈接多個防火牆相同的模式?或者我怎麼能定義一個防火牆與3個不同的驗證器,考慮到我正在使用第三部分包如friendsofsymfony/oauth-server-bundle,uma/psr7-hmac-bundle?

回答

0

使用

guard: 
    authenticators: 

的鏈接驗證器爲您的防火牆 這就是我在我的應用程序

api: 
      pattern: ^/api   
      guard: 
       authenticators: 
        - bor.api_bundle.session_authenticator 
        - lexik_jwt_authentication.jwt_token_authenticator 
        - sergei_k_security.token_authenticator 
       entry_point: lexik_jwt_authentication.jwt_token_authenticator 

文檔 - http://symfony.com/doc/current/security/multiple_guard_authenticators.html

+0

你如何定義的UMA/PSR7-HMAC認證程序-bundle,friendsofsymfony/oauth-server-bundle? – PMoubed

+0

https://symfony.com/doc/current/security/guard_authentication.html –