ZfcRbac 出于某种原因无法识别我的身份角色。我已经使用了几个小时,但它似乎无法从我的身份中获取角色,这很奇怪,因为它肯定可以从身份验证服务中询问。
\Zend\Debug\Debug::dump($authService->getIdentity());
以上转储以下内容:
object(Application\Entity\User)#405 (7) {
["role":protected] => object(Application\Role\Role)#448 (4) {
["id":protected] => string(1) "1"
["children":protected] => array(0) {
}
["name":protected] => string(5) "guest"
["permissions":protected] => array(0) {
}
}
["id":protected] => int(1)
["username":protected] => NULL
["email":protected] => string(35) "hetmfdm_huisky_1437140010@tfbnw.net"
["displayName":protected] => string(0) ""
["password":protected] => string(19) "facebookToLocalUser"
["state":protected] => NULL
}
现在确保这肯定是相同的身份验证服务:zfc_rbac.global.php
/**
* Key that is used to fetch the identity provider
*
* Please note that when an identity is found, it MUST implements thhe ZfcRbac\Identity\IdentityProviderInterface
* interface, otherwise it will throw an exception.
*/
'identity_provider' => 'zfcuser_auth_service',
模块.config.php
'factories' => [
'zfcuser_auth_service' => function ($sm) {
return new \Application\Authentication\AuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
},
],
'aliases' => [
'Zend\Authentication\AuthenticationService' => 'zfcuser_auth_service',
]
在控制器中
$authService = $this->zfcUserAuthentication()->getAuthService();
返回
string(48) "Application\Authentication\AuthenticationService"
其中 Application\Authentication\AuthenticationService 只不过是 Zend Authentication Service 的扩展,并实现了 IdentityProviderInterface。现在我知道这不是必需的,但我尝试了它只是为了确定。
namespace Application\Authentication;
class AuthenticationService extends \Zend\Authentication\AuthenticationService implements IdentityProviderInterface
{
}
到目前为止一切都很好(我认为)。
好的,我曾尝试发布图像,但我的声誉缺乏这种可能性。因此,我将确认 Zend Devveloper Toolbar 确实在最右侧的选项卡上显示了 RoleProvider 提供的所有角色。但在最左边,身份角色仍然是客人。这显然是错误的,因此没有任何效果。
我真的被困在这里,这是一个令人讨厌的障碍,因为我觉得我距离让我的 RBAC 正常工作只有一小步。
额外信息:我不使用 Doctrine。这是我自己制作的数据库/映射器系统,可提供 ZfcRbac 对我的任何要求。
我一起使用 ZfcUser 和 ZfcRbac。
版本:
"name": "zf-commons/zfc-user",
"version": "1.2.2",
"name": "zf-commons/zfc-rbac",
"version": "v2.5.2",
任何指示或帮助将不胜感激!