PHP Zend2 bjyauthorize原则,如果未提供标识,则设置默认角色
我是Zend 2的新手,信条之类的 在我的项目中,我想通过条令从zend 2实现BjyAuthorize模块。 我已经做了一些工作-我成功地实现并配置了除了默认角色之外的所有功能,如果没有提供标识(例如,新用户正在访问或注销后) 角色和用户类是BjyAuthorize的蓝图 这是在bjyauthorize.global.php中定义的身份提供程序类PHP Zend2 bjyauthorize原则,如果未提供标识,则设置默认角色,php,doctrine-orm,zend-framework2,bjyauthorize,Php,Doctrine Orm,Zend Framework2,Bjyauthorize,我是Zend 2的新手,信条之类的 在我的项目中,我想通过条令从zend 2实现BjyAuthorize模块。 我已经做了一些工作-我成功地实现并配置了除了默认角色之外的所有功能,如果没有提供标识(例如,新用户正在访问或注销后) 角色和用户类是BjyAuthorize的蓝图 这是在bjyauthorize.global.php中定义的身份提供程序类 'identity_provider' => 'Application\Provider\Identity\IdentityProvider'
'identity_provider' => 'Application\Provider\Identity\IdentityProvider',
代码:
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();
}
}
角色提供程序已成功设置为
'role_providers' => [
// this will load roles from
// the 'BjyAuthorize\Provider\Role\ObjectRepositoryProvider' service
"BjyAuthorize\Provider\Role\ObjectRepositoryProvider" => [
// class name of the entity representing the role
'role_entity_class' => 'Application\Tables\Role',
// service name of the object manager
'object_manager' => 'doctrine.entitymanager.orm_default',
],
],
现在唯一缺少的是,如果新用户正在访问页面,我想设置一个默认角色(来自db,角色“guest”)。在阅读和谷歌搜索之后,我找不到任何关于在哪里以及如何设置默认角色的提示
我已经在IdentityProvider中尝试了方法“getDefaultRole”,但是这个方法似乎没有被激发
我现在只看到在没有设置标识的情况下获取“getIdentityRoles”中的默认角色
但要做到这一点,我必须让条令实体经理和更多的东西包括在内——这是唯一的方法吗
编辑:
在“byauthorize.global.php”中,我可以看到以下几行:
// set the 'guest' role as default (must be defined in a role provider)
'default_role' => 'guest',
但我不知道我必须在角色提供程序中定义默认角色的位置…:-/
请注意,“默认角色”设置仅由BjyAuthorize(和)的发货人使用
当实现您自己的
IdentityProvider
时,您只需实现,以便在未提供任何标识时,它返回到您选择的标识。但是在这种早期状态下(在我自己的IdentityProvider类中),如何通过条令从数据库访问默认角色。或者我在这里漏唱了什么,从db获取默认类是完全错误的。。很抱歉,5月n00b的问题,这是我的第一个zend 2项目..我刚刚得到它。。在你的“ZfcUserZendDb”中看到了。返回字符串,因为角色是所需的全部。。谢谢