简体   繁体   English

Symfony超级角色无法访问基本角色

[英]Symfony Super Roles have no access to Base Roles

The Super Role has no access to the inherited Roles..?? 超级角色无权访问继承的角色。

This is how my role hierarchy looks like: 这是我的角色层次结构:

role_hierarchy:
    ROLE_ADMIN:           [ROLE_BACKEND_USER, ROLE_SALES]
    ROLE_SUPER_ADMIN:     ROLE_ADMIN
    ROLE_SALES:           ROLE_USER
    ROLE_BACKEND_USER:    ROLE_USER

When I log in as an ADMIN I can see that the I have inherited roles "ROLE_BACKEND_USER"; 当我以ADMIN身份登录时,可以看到我已经继承了角色“ ROLE_BACKEND_USER”; "ROLE_SALES" and "ROLE_USER". “ ROLE_SALES”和“ ROLE_USER”。

However, I cannot access the ROLE_SALES though I have inherited the Role. 但是,尽管我继承了角色,但无法访问ROLE_SALES。

if(!$this->getUser()->hasRole('ROLE_SALES')) {

 throw new AccessDeniedException('Cannot loggin Need ROLE_SALES ');

}

Also $this->get('security.authorization_checker')->isGranted('ROLE_CARMANDO') does work.. $this->get('security.authorization_checker')->isGranted('ROLE_CARMANDO')起作用。

PS: Iam using FOS Bundle too. PS:我也使用FOS Bundle。

This is because FOSUB hasRole method checks you explicitly have the role when isGranted checks the privileges. 这是因为FOSUB的hasRole方法会在isGranted检查特权时显式地检查您的角色。

Currently, you have the privileges of the ROLE_SALES but not the ROLE_SALES itself. 当前,您具有ROLE_SALES的特权,但没有ROLE_SALES本身的特权。 That's why isGranted works when hasRole does not 这就是为什么hasRole不起作用时isGranted起作用的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM