orm - 登录时 BjyAuthorize 未检测到任何角色

标签 orm doctrine zend-framework2 zfcuser bjyauthorize

我正在使用 ZF2、Doctrine ORM 和 BjyAuthorize。

问题是当我登录时,身份的 getRoles 方法返回空。

class User implements UserInterface, ProviderInterface{

/**
     * @var \Doctrine\Common\Collections\Collection
     *
     * @ORM\ManyToMany(targetEntity="Application\Entity\Role", inversedBy="user")
     * @ORM\JoinTable(name="user_role_linker",
     *   joinColumns={
     *     @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="role_id", referencedColumnName="id")
     *   }
     * )
     */
    protected $roles;

    public function __construct() {
        $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
    }

 public function addRole(\Application\Entity\Role $role) {
        $this->roles[] = $role;

        return $this;
    }

    /**
     * Remove role
     *
     * @param \Application\Entity\Role $role
     */
    public function removeRole(\Application\Entity\Role $role) {
        $this->roles->removeElement($role);
    }

    /**
     * Get role
     *
     * @return \Doctrine\Common\Collections\Collection 
     */

    public function getRoles() {
        return $this->roles->getValues();
    }
}

另一方面,如果我在 Controller 中获取实体并使用 getRoles,我可以毫无问题地获取值。

你能告诉我哪一个可能是问题所在吗?

这是我的 zfc-user-doctrine-orm-global:

<?php
return array(
    'doctrine' => array(
        'driver' => array(
            // overriding zfc-user-doctrine-orm's config
            'zfcuser_entity' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'paths' => 'module\Application\src\Application\Entity',
            ),

            'orm_default' => array(
                'drivers' => array(
                    'Application' => 'zfcuser_entity',
                ),
            ),
        ),
    ),

    'zfcuser' => array(
        // telling ZfcUser to use our own class
        'user_entity_class'       => '\Application\Entity\User',
        // telling ZfcUserDoctrineORM to skip the entities it defines
        'enable_default_entities' => false,
    ),

    'bjyauthorize' => array(
        // Using the authentication identity provider, which basically reads the roles from the auth service's identity
        'identity_provider' => 'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider',

        'role_providers'        => array(
            // using an object repository (entity repository) to load all roles into our ACL
            'BjyAuthorize\Provider\Role\ObjectRepositoryProvider' => array(
                'object_manager'    => 'doctrine.entitymanager.orm_default',
                'role_entity_class' => 'Application\Entity\Role',
             ),
        ),
    ),
);

最佳答案

您是否在“role”表中定义了角色,在 user_role_linker 表中定义了 userid <-> roleid?

关于orm - 登录时 BjyAuthorize 未检测到任何角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18610247/

相关文章:

java - Hibernate 中的自然标识符是什么?

java - JPA 2 和 Hibernate 之间有什么关系?

java - 坚持的问题

mysql - Symfony2/ Doctrine 关系映射

zend-framework2 - ZF2 : DB\AbstractTableGateway: How to use JOIN?

c# - 尝试在 Entity Framework 核心中添加数据库迁移时,为什么会出现 contentRootPath null 异常?

php - 从数据库生成实体

doctrine - Doctrine ORM 中的 View

php - Zend 2 检查选择查询是否返回 NULL

php - MySQL 上的\Zend\Db\Metadata\Metadata 速度很慢