Symfony2安全性:多个提供程序
我的项目中有两个捆绑包:Symfony2安全性:多个提供程序,symfony,symfony-security,Symfony,Symfony Security,我的项目中有两个捆绑包: src/韩国/阿拉木图 src/Galvez/Repustosbundle 每个都有自己的数据库 韩国汽车->阿尔马森堡 galvez_motos->Repustosbundle 实际上,my security.yml只有一个提供程序: providers: korea: entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username } 如您所见,这两个捆
- src/韩国/阿拉木图
- src/Galvez/Repustosbundle
- 韩国汽车->阿尔马森堡
- galvez_motos->Repustosbundle
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
如您所见,这两个捆绑包都由同一个表进行身份验证:韩国的Usuario
表:Usuario(韩国motos数据库)
--ID--|------用户名--|------捆绑包---
-----1--------------------管理员--------------------管理员--------------------管理员----------
-----2--------------------管理--------------------回购债券-------
现在,我想验证用户,在galvez_motos中使用表Usuario的RepusosBundle,删除上一个表中的列“bundle”
问题出在security.yml文件中。如果我这样做:
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
galvez:
entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
Symfony启动异常:
The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity
我尝试使用2个提供者,每个捆绑包一个表。。这可能吗
档案:
security.yml
jms_security_extra:
secure_all_services: false
expressions: true
安全:
编码器:
韩国\AlmacenBundle\Entity\Usuario:
算法:sha1
将_编码为_base64:false
迭代次数:1
Galvez\Repostosbundle\Entity\Usuario:
算法:sha1
将_编码为_base64:false
迭代次数:1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
korea:
entity: { class: Korea\AlmacenBundle\Entity\Usuario, property: username }
galvez:
entity: { class: Galvez\RepuestosBundle\Entity\Usuario, property: username }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/
anonymous: ~
access_denied_handler: accessdenied_handler
form_login:
login_path: /login
check_path: /login_check
default_target_path: /redirect
always_use_default_target_path: true
logout:
path: /logout
target: /login
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/redirect, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/galvez, roles: ROLE_ADMIN_GALVEZ }
- { path: ^/, roles: ROLE_ADMIN_KOREA }
config.yml--无法复制/粘贴所有:(
参数.yml
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: null
database_name: korea_motos
database_user: root
database_password:
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
locale: en
secret: 5f7ac4e7c2b38d6dbe55a1f05bee2b02
database_path: null
database_name2: galvez_motos
database_user2: root
database_password2:
PD:Sry for my english:S这可能是您的类的名称空间存在问题。检查class
Galvez\repusostosbundle\Entity\Usuario
是否位于正确的名称空间中,以及配置是否正确-可能是您无意中留下了来自其他实体的一些复制和粘贴代码
尝试持久化这两个实体并获取它们(没有安全上下文)-我想你会发现问题所在。我对这两个实体进行了测试: abcController.php 很好,但是如果我用 $em=$this->getDoctrine()->getEntityManager() 而不是 $em=$this->get('doctrine')->getManager('galvez') 当我尝试刷新时,Symfony会启动相同的错误:
The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity
Usuario.php(AlmacenBundle)
相同的错误,但相反
似乎monolog验证采用默认连接(本例中为korea)进行搜索和验证这是一个老问题,但对于任何寻求解决方案的人,手册都会对此进行解释。 基本上,您需要像这样链接您的提供商:
#app/config/security.yml
安全:
供应商:
供应链供应商:
链:
供应商:[韩国,加尔维斯]
韩国:
实体:{class:Korea\AlmacenBundle\entity\Usuario,属性:username}
加尔维斯:
实体:{class:Galvez\repustosbundle\entity\Usuario,属性:username}
$em= $this->get('doctrine')->getManager('galvez');
$usuario_g = $this->get('doctrine')->getRepository('RepuestosBundle:Usuario', 'galvez')->find(1);
$usuario_g->setUsername('asdasd');
$em->persist($usuario_g);
$em->flush();
The class 'Galvez\RepuestosBundle\Entity\Usuario' was not found in the chain configured namespaces Korea\AlmacenBundle\Entity
<?php
namespace Korea\AlmacenBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Usuario
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Korea\AlmacenBundle\Entity\UsuarioRepository")
*/
class Usuario implements UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255)
*/
private $salt;
<?php
namespace Galvez\RepuestosBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Usuario
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Galvez\RepuestosBundle\Entity\UsuarioRepository")
*/
class Usuario implements UserInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=255)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255)
*/
private $salt;
MappingException: The class 'Korea\AlmacenBundle\Entity\Usuario' was not found in the chain configured namespaces Galvez\RepuestosBundle\Entity