2013-08-19 1 views
1

입니다 작동하지구성 내 bjyauthorize.global.php 내용 여기

<?php 

return array(
'bjyauthorize' => array(

    // set the 'guest' role as default (must be defined in a role provider) 
    // 'default_role' => 'guest', 

    /* this module uses a meta-role that inherits from any roles that should 
    * be applied to the active user. the identity provider tells us which 
    * roles the "identity role" should inherit from. 
    * 
    * for ZfcUser, this will be your default identity provider 
    */ 
    'identity_provider' => 'BjyAuthorize\Provider\Identity\ZfcUserZendDb', 

    /* If you only have a default role and an authenticated role, you can 
    * use the 'AuthenticationIdentityProvider' to allow/restrict access 
    * with the guards based on the state 'logged in' and 'not logged in'. 
    */ 
     // 'default_role'  => 'guest',   // not authenticated 
     // 'authenticated_role' => 'user',   // authenticated 
     // 'identity_provider' => 'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider', 


    /* role providers simply provide a list of roles that should be inserted 
    * into the Zend\Acl instance. the module comes with two providers, one 
    * to specify roles in a config file and one to load roles using a 
    * Zend\Db adapter. 
    */ 
    'role_providers' => array(

     /* here, 'guest' and 'user are defined as top-level roles, with 
     * 'admin' inheriting from user 
     */ 
     'BjyAuthorize\Provider\Role\Config' => array(
      'admin' => array(), 
      'guest' => array() 
     ), 

     // this will load roles from the user_role table in a database 
     // format: user_role(role_id(varchar), parent(varchar)) 
     'BjyAuthorize\Provider\Role\ZendDb' => array(
      'table'    => 'user_role', 
      'role_id_field'  => 'roleId', 
      'parent_role_field' => 'parent_id', 
     ), 

     // this will load roles from the 'BjyAuthorize\Provider\Role\Doctrine' 
     // service 
     // 'BjyAuthorize\Provider\Role\Doctrine' => array(), 
    ), 

    // resource providers provide a list of resources that will be tracked 
    // in the ACL. like roles, they can be hierarchical 
    'resource_providers' => array(
     // 'BjyAuthorize\Provider\Resource\Config' => array(
     //  'pants' => array(), 
     //), 

     'BjyAuthorize\Provider\Resource\Config' => array(
      'Collections\Controller\CollectionsController' => array('admin'), 
     ), 
    ), 

    /* rules can be specified here with the format: 
    * array(roles (array), resource, [privilege (array|string), assertion]) 
    * assertions will be loaded using the service manager and must implement 
    * Zend\Acl\Assertion\AssertionInterface. 
    * *if you use assertions, define them using the service manager!* 
    */ 
    'rule_providers' => array(
     'BjyAuthorize\Provider\Rule\Config' => array(
      'allow' => array(
       // allow guests and users (and admins, through inheritance) 
       // the "wear" privilege on the resource "pants" 
       // array(array('guest', 'user'), 'pants', 'wear') 
       array(array('admin'), 'Collections\Controller\CollectionsController', 'index') 
      ), 

      // Don't mix allow/deny rules if you are using role inheritance. 
      // There are some weird bugs. 
      'deny' => array(
       // ... 
       // array(array('admin', 'guest'), 'collections', 'add') 
      ), 
     ), 
    ), 

    /* Currently, only controller and route guards exist 
    * 
    * Consider enabling either the controller or the route guard depending on your needs. 
    */ 
    'guards' => array(
     /* If this guard is specified here (i.e. it is enabled), it will block 
     * access to all controllers and actions unless they are specified here. 
     * You may omit the 'action' index to allow access to the entire controller 
     */ 
     'BjyAuthorize\Guard\Controller' => array(
      array('controller' => 'index', 'action' => 'index', 'roles' => array('admin','guest')), 
      array('controller' => 'index', 'action' => 'stuff', 'roles' => array('admin')), 
      array('controller' => 'Collections\Controller\CollectionsController', 'roles' => array('admin', 'guest')), 

      // You can also specify an array of actions or an array of controllers (or both) 
      // allow "guest" and "admin" to access actions "list" and "manage" on these "index", 
      // "static" and "console" controllers 
      // array(
      //  'controller' => array('index', 'static', 'console'), 
      //  'action' => array('list', 'manage'), 
      //  'roles' => array('guest', 'admin') 
      //), 
      array('controller' => 'zfcuser', 'roles' => array('admin', 'guest')), 
      // Below is the default index action used by the ZendSkeletonApplication 
      array('controller' => 'Application\Controller\Index', 'roles' => array('guest', 'admin')), 
     ), 

     /* If this guard is specified here (i.e. it is enabled), it will block 
     * access to all routes unless they are specified here. 
     */ 
     'BjyAuthorize\Guard\Route' => array(
      array('route' => 'zfcuser', 'roles' => array('admin', 'guest')), 
      array('route' => 'zfcuser/logout', 'roles' => array('admin', 'guest')), 
      array('route' => 'zfcuser/login', 'roles' => array('admin', 'guest')), 
      array('route' => 'zfcuser/register', 'roles' => array('guest', 'admin')), 
      // Below is the default index action used by the ZendSkeletonApplicationarray('route' => 'zfcuser/register', 'roles' => array('guest', 'admin')), 
      array('route' => 'collections/index', 'roles' => array('guest', 'admin')), 
      array('route' => 'home', 'roles' => array('guest', 'admin')), 
     ), 
    ), 
), 
); 

이 같은 데이터베이스 구조를 가지고 : 나는 사용자의 열을 수정 한

-- 
-- Table structure for table `user` 
-- 

CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, 
`username` varchar(255) DEFAULT NULL, 
`email` varchar(255) DEFAULT NULL, 
`display_name` varchar(50) DEFAULT NULL, 
`password` varchar(128) NOT NULL, 
`state` smallint(5) unsigned DEFAULT NULL, 
PRIMARY KEY (`id`), 
UNIQUE KEY `username` (`username`), 
UNIQUE KEY `email` (`email`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; 

-- 
-- Dumping data for table `user` 
-- 

INSERT INTO `user` (`id`, `username`, `email`, `display_name`, `password`, `state`) VALUES 
(1, NULL, '[email protected]', NULL, '$2y$14$fL.K0rieXO.kHsHfOogH8Oaf..C.1GsYqEB49A3Dmxy9ZiMhWHx7.', NULL); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `user_role` 
-- 

CREATE TABLE IF NOT EXISTS `user_role` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`roleId` varchar(255) NOT NULL, 
`is_default` tinyint(1) NOT NULL, 
`parent_id` varchar(255) DEFAULT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; 

-- 
-- Dumping data for table `user_role` 
-- 

INSERT INTO `user_role` (`id`, `roleId`, `is_default`, `parent_id`) VALUES 
(1, 'admin', 1, 'admin'), 
(2, 'guest', 1, 'admin'); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `user_role_linker` 
-- 

CREATE TABLE IF NOT EXISTS `user_role_linker` (
`user_id` int(11) unsigned NOT NULL, 
`role_id` int(11) NOT NULL, 
PRIMARY KEY (`user_id`,`role_id`), 
KEY `role_id` (`role_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

-- 
-- Dumping data for table `user_role_linker` 
-- 

INSERT INTO `user_role_linker` (`user_id`, `role_id`) VALUES 
(1, 1); 

을 이 issue에 따른 테이블. 그리고 나는 id에 user_id에 대한 ZfcUser의 Mapper를 수정했습니다. 그것은 오류를 보이지 않기 때문에 제대로 작동하고 있습니다.

오류가 없는데도 로그인하기 전에 로그인 페이지 (zfcuser/login)를 제외한 모든 모듈 (/ user 및/collections)에 대해 항상 "403 Forbidden"이 표시됩니다.

user_role_linker 테이블의 데이터에 대한 데이터베이스가 의심 스럽습니다. BjyAuth library에 user_role 테이블에 대한 역할 데이터를 입력하는 적절한 문서를 찾지 못했습니다. 나에게 거기에 설정 파일이나 데이터베이스 테이블이나 여기에 언급되지 않은 다른 어떤 잘못 구성이있다.

답변

0

기초가 올바르게 설정되어 있는지 알지 못하면 너무 많은 것을 시도 할 가능성이 있습니다. 완전한 대답은 아니지만 다음을 제안합니다.

  • 는 한 번 당신이 현재 가지고있는 역할 당신을 말할 것이다 페이지 하단에 툴바를 가지고 실행 젠드 프레임 워크 개발자 도구 ( https://github.com/zendframework/ZendDeveloperTools)를 설치합니다. 그것도 다른 것들의 무리에 유용합니다. 로그인 할 때 적절한 역할이 있다고 가정하면 만 한 번에 하나의 가드를 설정합니다. 즉. 당신은 현재 모두 "BjyAuthorize \ 가드 \ 컨트롤러"와 "BjyAuthorize \ 가드 \ 경로"설정이

  • 당신은 다음을 테스트 할 수 있습니다 실행 한 또는 시작이 다른, 그리고 당신이 하나를 실행할 수 있습니다 다른. bjyauthorize.global.php의 해당 섹션을 제거하거나 주석 처리하십시오.

주의 가드를 활성화하면 지정되지 않은 모든 항목이 차단됩니다.

컨트롤러와 경로를 보지 않고 위의 구성 중 일부가 맞는지는 모르겠지만 경로 이름을 다시 확인하고 완전한 컨트롤러 이름을 사용하는 것이 더 안전 할 수 있습니다. 대신

array('controller' => 'index', 

의 난이 도움이 희망

array('controller' => 'YourModuleName\Controller\IndexController', 

보십시오.

또한 어떤 지점에서 Doctrine ORM을 사용하게되면 https://github.com/manuakasam/SamUser은 BjyAuthorize, ZFcuser 및 Doctrine을 쉽게 결합 할 수있는 훌륭한 모듈입니다.

+0

내가 제안한 역할에 따라 구성 및 경로가 설정되었지만 출력은 여전히 ​​동일합니다. 젠드 프레임 워크 개발자 도구 모음을 보면서이 오류가 발생했습니다 : 오류 @ bjyoungblood의 Zend \ Db 프로필러를 설치하거나 사용 설정해야이 기능을 사용할 수 있습니다. 이것에 대한 어떤 생각? – regeint

+0

이 오류는 현재의 문제에 중요하지 않은 DB 프로파일 러에만 해당됩니다. 현재 가지고있는 사용자 역할을 나타내는 아이콘 오른쪽에 표시됩니까? 그렇지 않으면 설정이 올바르지 않을 수 있습니다. – Finbarr

+0

예 손님 레이블이있는 아이콘이 있습니다. 내가 아이콘을 질질 찌면, 다음과 같이 표시됩니다. ByjAuthorize Identity Roles -1 Role : 손님 Bu 현재 로그인 한 사용자의 역할이 guest가 아닌 관리자입니다. 게스트 로그인은 로그인 페이지에서 사용자가 로그인하지 않은 경우에도 항상 표시됩니다. – regeint

1

user_role_linker 테이블 문제 핀

의 feilds role_id 오히려 varchar 다음 int해야한다. 나는 같은 문제가 있었다. 샘플 데이터에 대해서는 다음 덤프를 확인하십시오.

CREATE TABLE IF NOT EXISTS `user_role_linker` (
`user_id` int(11) unsigned NOT NULL, 
`role_id` varchar(128) NOT NULL, 
PRIMARY KEY (`user_id`,`role_id`), 
KEY `role_id` (`role_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

-- 
-- Dumping data for table `user_role_linker` 
-- 

INSERT INTO `user_role_linker` (`user_id`, `role_id`) VALUES(1, 'admin');