登录时,BjyAuthorize检测不到任何角色 [英] No role detected by BjyAuthorize when login

查看:156
本文介绍了登录时,BjyAuthorize检测不到任何角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with ZF2, Doctrine ORM and BjyAuthorize.

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

The problem is that when I got logged in the method getRoles of the identity returns empty.

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();
    }
}

另一方面,如果我把实体控制器和我使用getRoles,我得到的值没有任何问题。

In the other hand, if I get the entity in the controller and I use getRoles, I get the values without any problem.

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

Could you please tell me which one could be the problem?

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

This is my 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',
             ),
        ),
    ),
);


推荐答案

你在角色表中定义了你的角色,user_role_linker表中的userid< - > roleid?

Do you have your roles defined in 'role' table, and userid <-> roleid in user_role_linker table?

这篇关于登录时,BjyAuthorize检测不到任何角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆