0

我已经安装了 ZendFramework bjyauthorize。我还安装了 zfcuser,但我不想使用它。我有我的其他身份验证模块。我想知道在用户通过身份验证后如何触发或加载 bjyauthorize 角色/ACL。

这是一个正确的提供者吗?

namespace Firewall\Provider\Identity;

//use BjyAuthorize\Provider\Identity;
//use BjyAuthorize\Exception\InvalidRoleException;
//use Zend\Db\Adapter\Adapter;
//use Zend\Db\Sql\Where;
//use Zend\Db\Sql\Sql;
//use Zend\Db\Sql\Select;
//use Zend\Permissions\Acl\Role\RoleInterface;
//use Zend\Authentication\Storage\Session as SessionStorage;
//use BjyAuthorize\Provider\Identity\ProviderInterface;
//use Zend\Db\TableGateway\TableGateway;
//use Zend\Db\Sql\Expression;
//use Zend\Authentication\AuthenticationService; 
//
//class Myprovider implements  ProviderInterface {
//    
//    
//
//public function setDbAdapter();
//public function getDbAdapter();
//public function getIdentityRoles();
//public function getDefaultRole();
//public function getRoles();
//
//}



use BjyAuthorize\Provider\Identity\ProviderInterface;
use Zend\Authentication\AuthenticationService;

class Myprovider 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 setAdapter($adapter)
    {
        return $this->authService->setAdapter($adapter);
    }        
    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();
    }
}
4

1 回答 1

0

bjyAuthorize 不直接与您的身份验证模块交互。它只需要当前登录用户的角色。它通过身份提供者获得。因此,您应该为身份提供者扩展 ProviderInterface 以返回属于当前登录用户的角色。

身份提供者接口

您可能还应该更改(或自己创建)默认角色提供程序以返回您为身份验证模块定义的角色

于 2015-09-18T12:07:31.900 回答