ZfcRbac无法识别我的登录用户角色

时间:2015-07-20 17:05:00

标签: php authentication zend-framework zfcuser zfc-rbac

由于某种原因,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',

module.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工具栏确实在最右边的选项卡上显示了RoleProvider提供的所有角色。但在最左边,身份角色仍然是客人。这显然是错误的,因为它没有任何作用。

我真的被困在这里,这是一个令人讨厌的障碍,因为我觉得我只是迈出了一小步,让我的RBAC功能正常。

额外信息: 我不使用Doctrine。它是一个数据库/映射器系统,我自己提供了我所需的ZfcRbac。

我一起使用ZfcUser和ZfcRbac。

版本:

 "name": "zf-commons/zfc-user",
"version": "1.2.2",

"name": "zf-commons/zfc-rbac",
"version": "v2.5.2",

非常感谢任何指示或帮助!

0 个答案:

没有答案