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所有?这是如何从防火墙中抽象出来的?
任何帮助,将不胜感激。