0
我有一個正常工作的登錄系統的Symfony2,它使用表VtigerPortalinfo
獲取用戶和密碼,然後驗證。Symfony2安全和角色
但是我在另一個表中有角色,這個表爲管理員返回1
,爲普通用戶返回0
,這是存儲庫中的查詢。
public function findRolTypeByCustomerId($customerId)
{
$query = $this->getEntityManager()->createQuery("
SELECT u.cf771
FROM WbsGoclientsBundle:VtigerContactscf u
WHERE u.contactid = :customerid
")->setParameter('customerid', $customerId);
try {
$rol = $query->getSingleResult();
if($rol = 1)
return 'ROLE_AGENT';
else
return 'ROLE_USER';
}
catch (\Doctrine\ORM\NoResultException $e)
{
return null;
}
}
這是我Security.yml
security:
encoders:
WbsGo\clientsBundle\Entity\VtigerPortalinfo: plaintext
role_hierarchy:
ROLE_ADMIN: [ROLE_USER]
providers:
user_db:
entity: { class: WbsGo\clientsBundle\Entity\VtigerPortalinfo, property: userName }
firewalls:
main:
pattern: /.*
provider: user_db
form_login:
always_use_default_target_path: true
login_path: /login
check_path: /login_check
remember_me: true
logout:
path: /logout
target:/
remember_me:
key: XXXXXXXX
lifetime: 1800
path: /.*
domain: ~
security: true
anonymous: true
access_control:
- { path: /login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /css, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /js, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /images, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: /user, roles: ROLE_USER }
- { path: /admin, roles: ROLE_ADMIN }
- { path: /.*, roles: ROLE_USER }
所以我的問題是,我怎麼能設置的角色,從不同的表比登錄信息?正如你所看到的,在回購它返回的角色,但是,我不知道如何解析它的安全的東西...