ZfcRbac does not recognise my logged in user role

188 views Asked by At

ZfcRbac does not recognise my Identity role for some reason. I've been on it for hours but it can't seem to get the roles from my identity, which is strange because it can definitely be asked from the authentication service.

\Zend\Debug\Debug::dump($authService->getIdentity());

Above dumps the following:

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) "[email protected]"
  ["displayName":protected] => string(0) ""
  ["password":protected] => string(19) "facebookToLocalUser"
  ["state":protected] => NULL
}

Now to make sure this is surely the same authentication service: 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',
    ]

In a controller

$authService = $this->zfcUserAuthentication()->getAuthService();

returns

string(48) "Application\Authentication\AuthenticationService"

Where Application\Authentication\AuthenticationService is nothing more than an extend of the Zend Authentication Service and implements the IdentityProviderInterface. Now I know this wasn't necessary but I tried it just to be sure.

namespace Application\Authentication;

class AuthenticationService extends \Zend\Authentication\AuthenticationService implements IdentityProviderInterface
{
}

All good so far (I think).

OK I had tried to post images but my reputation lacks that possibility. So I'll confirm that Zend Devveloper Toolbar does show all my roles provided by RoleProvider on the right most tab. But at the left most, the identity role is still guest. This is obviously wrong and nothing works because of it.

I'm really stuck here and it's an annoying block because I feel like I am just a small step away of getting my RBAC functional as it is supposed to be.

Extra information: I do not use Doctrine. It's a database/mapper system I made myself providing whatever ZfcRbac required of me.

I use ZfcUser and ZfcRbac together.

Versions:

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

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

Any pointers or help would be greatly appreciated!

0

There are 0 answers