doctrine2 - PHP Zend2 bjyauthorize doctrine Where set default role if no identity is given -
i'm pretty new zend 2, doctrine , stuff
in project implement bjyauthorize module zend 2 via doctrine. have done stuff - implement , configured except default role, if no identitiy given (new user visting, or after logout example).
role , user classes blueprints bjyauthorize
this identity provider class defined in bjyauthorize.global.php
'identity_provider' => 'application\provider\identity\identityprovider',
code:
namespace application\provider\identity; use bjyauthorize\provider\identity\providerinterface; use zend\authentication\authenticationservice; class identityprovider implements providerinterface { // public function getdefaultrole() // { // $atest = "test"; // return new debug(); // } public function getidentityroles() { $oidentity = $this->getidentity(); $aroles = []; if(!empty($oidentity)) { $aroles = $oidentity->getroles(); } return $aroles; } protected $authservice; public function __construct(authenticationservice $authservice) { $this->authservice = $authservice; } public function getadapter() { return $this->authservice->getadapter(); } public function getstorage() { return $this->authservice->getstorage(); } public function getidentity() { return $this->authservice->getidentity(); } public function clearidentity() { return $this->authservice->clearidentity(); } }
the role provider set to
'role_providers' => [ // load roles // 'bjyauthorize\provider\role\objectrepositoryprovider' service "bjyauthorize\provider\role\objectrepositoryprovider" => [ // class name of entity representing role 'role_entity_class' => 'application\tables\role', // service name of object manager 'object_manager' => 'doctrine.entitymanager.orm_default', ], ],
the thing missing want set default role (from db, role "guest") if new user visiting page. after reading , googling can't find hint , how set default role.
i tried method "getdefaultrole" in identityprovider, method seems not fired.
i see fetch default role in "getidentityroles" if no identity set.
but archiv have doctrine entity manager , more stuff include - way?
edit: in "byauthorize.global.php" can see following lines:
// set 'guest' role default (must defined in role provider) 'default_role' => 'guest',
but not know i have define default role in role provider ... :-/
kindly regards
the 'default_role'
setting used shipped authenticationidentityprovider
of bjyauthorize (and its factory).
when implementing own identityprovider
, must implement bjyauthorize\provider\identity\providerinterface#getidentityroles()
falls identity of choice when none given.
Comments
Post a Comment