Symfony的2.8 SimplePreAuthenticatorInterface
之前在以下命名空間Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface
它已經過時的2.8和3.0改爲Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface
方式,也必須保持其向後兼容性休息
現在我正在寫一個一束必須在symfony 2.7和symfony 3.0中工作,這是一個私人使用的api驗證器包。
我想爲它編寫一個工廠,檢查接口所有腦幹從FosUserBundle
if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
$tokenStorage = $this->get('security.token_storage');
} else {
$tokenStorage = $this->get('security.context');
}
的例子,但我的類,它實現這個接口是在DI服務和symfony的防火牆直接使用此。
我的問題是如何以最佳實踐和合乎邏輯的方式進行抽象。
AccessTokenAuthenticator類別:
<?php
namespace MyCompany\SBundle\Security;
// this usage for before symfony 2.8
use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
/**
* Class AccessTokenAuthenticator
*/
class AccessTokenAuthenticator implements SimplePreAuthenticatorInterface
{
services.yml
# Authentication
mycompany_security.security.accesstoken_authenticator:
class: MyCompany\SBundle\Security\AccessTokenAuthenticator
arguments: ["@mycompany_security.security.accesstoken_userprovider"]
防火牆配置:
secure_area:
pattern: ^/
stateless: true
simple_preauth:
authenticator: mycompany_security.security.accesstoken_authenticator
我的確切的問題是,即使我定義兩個類是相同對方,但實現名稱空間不同,即使我怎麼能給這個firew所有?這是如何從防火牆中抽象出來的?
任何幫助,將不勝感激。