jmi*_*ola 12
Silex 的SecurityServiceProvider可能是一个很好的起点,因为它将所有基本组件服务集成在一个文件中.虽然很大,但你可能会发现它比Symfony2的SecurityBundle更容易消化.
为了保持理智,您应该考虑使用服务容器来组织所有这些对象.在前面提到的类中,Silex Application类是一个Pimple实例,所以你应该能够用适度的努力将它移植到独立的Pimple.我之所以看到这一点,是因为将Pimple服务容器集成到您的应用程序中应该比采用Silex框架更具侵入性.
一旦您拥有必要的安全组件类,您就应该能够遵循ACL文档并根据需要向容器添加其他服务.此时,SecurityBundle的ACL特定部分可能会有所帮助,因为您可以专注于相关位.请记住,文档中有多个ACL的cookbook条目.
首先要包括什么类?
您很可能需要至少包括部分(如果不是全部)安全核心,以及您想要使用的 ACL 实现。您可以查看 ACL 实现开头列出的依赖项并了解它们扩展了哪些内容。例如,ACL/DBAL在标头中调用了以下依赖项:
namespace Symfony\Component\Security\Acl\Dbal;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\Entry;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException;
use Symfony\Component\Security\Acl\Model\AclCacheInterface;
use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
use Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface;
Run Code Online (Sandbox Code Playgroud)
但是您可能需要检查列出的每个项的依赖项,并加载它们。
我会回溯依赖关系,并跟踪什么需要什么。将这些类挑选到一个单独的位置,以便您只拥有所需的内容,并使用一些错误捕获来确定您拥有所有内容。
要实例化哪个对象?
你的 ACL。如果依赖项全部确定并加载,那么您应该能够实例化 ACL 类对象。
是否可以在没有模型和控制器的情况下使用?
老实说,我不确定是否可以在不做大量工作的情况下在 S2 之外使用 ACL,但如果您可以使用它所需的一切来实例化它,那么您应该能够在没有 MVC 模型的情况下使用该对象。
不幸的是,根据我对 S2 的理解,它是一个全栈框架,意味着要么全有要么全无。但如果我要尝试让它发挥作用,我就会这样做。