pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='1CNOf'></tfoot>

          <bdo id='1CNOf'></bdo><ul id='1CNOf'></ul>

        <legend id='1CNOf'><style id='1CNOf'><dir id='1CNOf'><q id='1CNOf'></q></dir></style></legend>
      1. <i id='1CNOf'><tr id='1CNOf'><dt id='1CNOf'><q id='1CNOf'><span id='1CNOf'><b id='1CNOf'><form id='1CNOf'><ins id='1CNOf'></ins><ul id='1CNOf'></ul><sub id='1CNOf'></sub></form><legend id='1CNOf'></legend><bdo id='1CNOf'><pre id='1CNOf'><center id='1CNOf'></center></pre></bdo></b><th id='1CNOf'></th></span></q></dt></tr></i><div class="swkcqyq" id='1CNOf'><tfoot id='1CNOf'></tfoot><dl id='1CNOf'><fieldset id='1CNOf'></fieldset></dl></div>

        <small id='1CNOf'></small><noframes id='1CNOf'>

        Zend ACL 是否適合我的需求?

        Does Zend ACL suit my needs?(Zend ACL 是否適合我的需求?)

            <bdo id='DEaYh'></bdo><ul id='DEaYh'></ul>

              <small id='DEaYh'></small><noframes id='DEaYh'>

                <tbody id='DEaYh'></tbody>
              <tfoot id='DEaYh'></tfoot>

                  <legend id='DEaYh'><style id='DEaYh'><dir id='DEaYh'><q id='DEaYh'></q></dir></style></legend>
                  <i id='DEaYh'><tr id='DEaYh'><dt id='DEaYh'><q id='DEaYh'><span id='DEaYh'><b id='DEaYh'><form id='DEaYh'><ins id='DEaYh'></ins><ul id='DEaYh'></ul><sub id='DEaYh'></sub></form><legend id='DEaYh'></legend><bdo id='DEaYh'><pre id='DEaYh'><center id='DEaYh'></center></pre></bdo></b><th id='DEaYh'></th></span></q></dt></tr></i><div class="02kq2se" id='DEaYh'><tfoot id='DEaYh'></tfoot><dl id='DEaYh'><fieldset id='DEaYh'></fieldset></dl></div>
                  本文介紹了Zend ACL 是否適合我的需求?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的應用程序基于 Zend 框架.我正在使用 Zend_Auth 進行身份驗證,但我不確定 Zend_Acl 是否適合我,因為坦率地說,我所看到的示例對于我的需求來說太簡單了或者讓我困惑.

                  I have based my application upon the Zend Framework. I am using Zend_Auth for authentication, but I'm not sure if Zend_Acl will work for me because, frankly, the examples I've seen are either too simplistic for my needs or confuse me.

                  我將應用程序中的元素視為資源,并且這些資源可以擁有特權.包含資源特權的角色是動態定義的,分配給用戶.我將此信息存儲在規范化表中.

                  I'm thinking of elements in my application as Resources and these Resources can have have Privileges. Roles containing Resource Privileges are dynamically defined assigned to users. I'm storing this information in normalized tables.

                  1. 用戶有角色
                  2. 一個角色可以有多個資源
                  3. 資源可以有多個權限

                  角色實際上只是沒有層次結構的資源權限的集合.資源的一個例子是頁面".每個人都可以查看頁面,但經過身份驗證的用戶需要添加"、編輯"或刪除"權限才能對頁面執行任何其他操作.

                  Roles are really just collections of Resource Privileges with no hierarchy. An example of a Resource would be 'Page'. Everyone can view the pages, but a authenticated user would need 'add', 'edit', or 'delete' privileges to do anything else with pages.

                  這是否與 Zend ACL 匹配?我是否會以一種會給我帶來問題的方式考慮 ACL?

                  Does this mesh with Zend ACL? Am I thinking ACL in a way that's going to create problems for me?

                  我的解決方案

                  Typeonerror 值得稱贊,但這是我的具體解決方案.

                  Typeonerror gets the credit, but here's my specific solution.

                  我擴展了 Zend_Acl 以簡化我的使用,因為我只加載當前用戶的角色:

                  I extended Zend_Acl to simplify my usage because I only load the role of the current user:

                  class My_Acl extends Zend_Acl
                  {
                      protected $_role_id;
                  
                      public function setRole($role_id)
                      {
                          $this->_role_id = $role_id;
                          return $this->addRole($role_id);
                      }
                  
                      public function getRole()
                      {
                          return $this->_role_id;
                      }
                  
                      public function deny($resource, $privilege)
                      {
                          return parent::deny($this->_role_id, $resource, $privilege);
                      }
                  
                      public function allow($resource, $privilege)
                      {
                          return parent::allow($this->_role_id, $resource, $privilege);
                      }
                  
                      public function isAllowed($resource, $privilege)
                      {
                          return parent::isAllowed($this->_role_id, $resource, $privilege);
                      }
                  }
                  

                  為了填充 ACL,我執行了一個返回 resourceprivilegerole_id 列的查詢.如果用戶的角色沒有該權限,則結果集中的 role_id 列為空.

                  To populate the the ACL I execute a query which returns resource, privilege, and role_id columns. The role_id column is null in the result set if the user's role does not have that privilege.

                  $acl = new My_Acl();
                  
                  $auth = Zend_Auth::getInstance();
                  if ($auth->hasIdentity()) {
                      $userInfo = $auth->getStorage()->read();
                      $acl->setRole($userInfo->role_id);
                  } else {
                      $acl->setRole('');
                  }
                  
                  // QUERY HERE
                  
                  foreach ($privileges as $privilege) {
                      if (!$acl->has($privilege['resource'])) {
                          $acl->addResource($privilege['resource']);
                      }
                      if (is_null($privilege['role_id'])) {
                          $acl->deny($privilege['resource'], $privilege['privilege']);
                      } else {
                          $acl->allow($privilege['resource'], $privilege['privilege']);
                      }
                  }
                  

                  推薦答案

                  這正是它的工作原理,我認為您正在以一種準確的方式考慮它.您可以添加資源,然后添加權限以允許某些用戶角色訪問它們.例如,在我的 CMS 中,我有開發人員"、管理員"和用戶".在下面的代碼中,我添加了一般訪問權限,然后從某些用戶的訪問權限中刪除了一些操作和特定方法.當然,這非常特定于我的應用程序,但基本上,您必須從 auth->getIdentity()(或類似的)獲取用戶的角色,然后從數據庫中添加您的角色/資源.

                  That's exactly how it works and I think you're thinking about it in an accurate way. You can add your resources and then add privileges to allow certain user roles to access them. For example, in my CMS, I have "developers", "admins", and "users". In the code below I add general access and then remove some actions and specific methods from certain user's access. Of course this is pretty specific to my application but basically, you'd have to get the user's role from auth->getIdentity() (or similar) and then add your roles/resources from the database.

                  <?php
                  
                  /**
                   * @author     Benjamin Borowski <ben.borowski@typeoneerror.com>
                   * @copyright  Copyright (c) Typeoneerror Studios http://typeoneerror.com
                   * @version    $Id$
                   * @category   Typeoneerror
                   * @package    Acl
                   */
                  
                  /**
                   * Defines basic roles and resources for an application as
                   * well as a Content Management System (CMS).
                   *
                   * Zend_Acl provides a lightweight and flexible access control list
                   * (ACL) implementation for privileges management.
                   *
                   * {@inheritdoc}
                   *
                   * @author     Benjamin Borowski <ben.borowski@typeoneerror.com>
                   * @copyright  Copyright (c) Typeoneerror Studios http://typeoneerror.com
                   * @version    $Id$
                   * @category   Typeoneerror
                   * @package    Acl
                   */
                  class Typeoneerror_Acl extends Zend_Acl
                  {
                      /**
                       * Constructor function.
                       *
                       * Creates basic roles and resources and adds them to Acl.
                       *
                       * {@inheritdoc}
                       *
                       * @return Typeoneerror_Acl
                       */
                      public function __construct()
                      {
                          //---------------------------------------
                          // ROLES
                          //---------------------------------------
                  
                          $this->_addRole("guest")
                               ->_addRole("member", "guest")
                               ->_addRole("admin", "member")
                               ->_addRole("developer", "admin");
                  
                          //---------------------------------------
                          // FRONT-END RESOURCES
                          //---------------------------------------
                  
                          $this->_add("default");
                  
                          //---------------------------------------
                          // BACK-END RESOURCES
                          //---------------------------------------
                  
                          $this->_add("cms")
                               ->_add("cms:articles", "cms")
                               ->_add("cms:auth", "cms")
                               ->_add("cms:bug-report", "cms")
                               ->_add("cms:calendar", "cms")
                               ->_add("cms:categories", "cms")
                               ->_add("cms:comments", "cms")
                               ->_add("cms:error", "cms")
                               ->_add("cms:galleries", "cms")
                               ->_add("cms:pages", "cms")
                               ->_add("cms:photos", "cms")
                               ->_add("cms:tags", "cms")
                               ->_add("cms:users", "cms");
                  
                          //---------------------------------------
                          // GUEST PERMISSIONS
                          //---------------------------------------
                  
                          $this->allow("guest", "default")
                               ->allow("guest", "cms:auth")           // -- guests can attempt to log-in
                               ->allow("guest", "cms:error")          // -- guests can break stuff
                               ->allow("guest", "cms:bug-report");    // -- guests can report bugs
                  
                          //---------------------------------------
                          // ADMIN PERMISSIONS
                          //---------------------------------------
                  
                          $this->allow("admin")
                               ->deny("admin", null, "purge")                       // -- admins cannot purge (normally)
                               ->deny("admin", "cms:comments", "create");           // -- only devs can create a comment
                  
                          //---------------------------------------
                          // DEVELOPER PERMISSIONS
                          //---------------------------------------
                  
                          $this->allow("developer");             // -- unrestricted access
                  
                          return $this;
                      }
                  
                      /**
                       * Adds a Resource having an identifier unique to the ACL.
                       *
                       * @param Zend_Acl_Resource_Interface $resource       The resource to add
                       * @param Zend_Acl_Resource_Interface|string $parent  A parent resource it inherits from
                       * @return Typeoneerror_Acl                           Reference to Acl class
                       */
                      protected function _add($resource, $parent = null)
                      {
                          $this->add(new Zend_Acl_Resource($resource), $parent);
                  
                          return $this;
                      }
                  
                      /**
                       * Wrapper for <code>addRole</code>
                       *
                       * @param Zend_Acl_Resource_Interface $resource        The resource to add
                       * @param Zend_Acl_Resource_Interface|string $parents  Parent resources it inherits from
                       * @return Typeoneerror_Acl                            Reference to Acl class
                       */
                      protected function _addRole($role, $parents = null)
                      {
                          $this->addRole(new Zend_Acl_Role($role, $parents));
                  
                          return $this;
                      }
                  
                  }
                  

                  編輯

                  我想我還應該解釋一下,我有一個 Typeoneerror_Controller_Plugin_Acl,每當請求任何資源時都會使用它.在這里,我創建了請求資源制作的標簽"并檢查用戶是否有權訪問該標簽:

                  Guess I should also explain that I have an Typeoneerror_Controller_Plugin_Acl which is used whenever any resource is requested. Here I create the "tag" that the requested resource makes and check whether the user has access to that tag:

                      $controller = $request->controller;
                      $action = $request->action;
                      $module = (empty($request->module)) ? "default" : $request->module;
                  
                      // -- this ends up like "cms:articles" just like my resources
                      $resource = $module . ":" . $controller;
                  
                      if (!$this->__acl->has($resource))
                      {
                          $resource = $module;
                      }
                  
                      // -- the good stuff. check if the user's role can access the resource and action
                      if (!$this->__acl->isAllowed($role, $resource, $action))
                      {
                          //more code 
                      }
                  

                  這篇關于Zend ACL 是否適合我的需求?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tbody id='Noyeo'></tbody>
                  <tfoot id='Noyeo'></tfoot>

                      1. <small id='Noyeo'></small><noframes id='Noyeo'>

                          <i id='Noyeo'><tr id='Noyeo'><dt id='Noyeo'><q id='Noyeo'><span id='Noyeo'><b id='Noyeo'><form id='Noyeo'><ins id='Noyeo'></ins><ul id='Noyeo'></ul><sub id='Noyeo'></sub></form><legend id='Noyeo'></legend><bdo id='Noyeo'><pre id='Noyeo'><center id='Noyeo'></center></pre></bdo></b><th id='Noyeo'></th></span></q></dt></tr></i><div class="kcqqe2o" id='Noyeo'><tfoot id='Noyeo'></tfoot><dl id='Noyeo'><fieldset id='Noyeo'></fieldset></dl></div>
                            <bdo id='Noyeo'></bdo><ul id='Noyeo'></ul>
                          • <legend id='Noyeo'><style id='Noyeo'><dir id='Noyeo'><q id='Noyeo'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 焊接减速机箱体,减速机箱体加工-淄博博山泽坤机械厂 | KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 碳纤维布-植筋胶-灌缝胶-固特嘉加固材料公司 | 100_150_200_250_300_350_400公斤压力空气压缩机-舰艇航天配套厂家 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 蔡司三坐标-影像测量机-3D扫描仪-蔡司显微镜-扫描电镜-工业CT-ZEISS授权代理商三本工业测量 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 贴片电容代理-三星电容-村田电容-风华电容-国巨电容-深圳市昂洋科技有限公司 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 北京中创汇安科贸有限公司| 雪花制冰机(实验室雪花制冰机)百科 | 中矗模型-深圳中矗模型设计有限公司| 北京工业设计公司-产品外观设计-产品设计公司-千策良品工业设计 北京翻译公司-专业合同翻译-医学标书翻译收费标准-慕迪灵 | 大功率金属激光焊接机价格_不锈钢汽车配件|光纤自动激光焊接机设备-东莞市正信激光科技有限公司 定制奶茶纸杯_定制豆浆杯_广东纸杯厂_[绿保佳]一家专业生产纸杯碗的厂家 | 电动球阀_不锈钢电动球阀_电动三通球阀_电动调节球阀_上海湖泉阀门有限公司 | 蓄电池在线监测系统|SF6在线监控泄露报警系统-武汉中电通电力设备有限公司 | 高精度-恒温冷水机-螺杆式冰水机-蒸发冷冷水机-北京蓝海神骏科技有限公司 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 实验室隔膜泵-无油防腐蚀隔膜泵-耐腐蚀隔膜真空泵-杭州景程仪器 电杆荷载挠度测试仪-电杆荷载位移-管桩测试仪-北京绿野创能机电设备有限公司 | 不锈钢丸厂家,铝丸,铸钢丸-淄博智源铸造材料有限公司 | 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 睿婕轻钢别墅_钢结构别墅_厂家设计施工报价 | 企小优-企业数字化转型服务商_网络推广_网络推广公司 | 校园文化空间设计-数字化|中医文化空间设计-党建|法治廉政主题文化空间施工-山东锐尚文化传播公司 | 玻璃钢罐_玻璃钢储罐_盐酸罐厂家-河北华盛节能设备有限公司 | 空气能暖气片,暖气片厂家,山东暖气片,临沂暖气片-临沂永超暖通设备有限公司 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 磨煤机配件-高铬辊套-高铬衬板-立磨辊套-盐山县宏润电力设备有限公司 | 北京燃气公司 用户服务中心 | 温泉机设备|温泉小镇规划设计|碳酸泉设备 - 大连连邦温泉科技 | 上海质量认证办理中心| 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 短信通106短信接口验证码接口群发平台_国际短信接口验证码接口群发平台-速度网络有限公司 | 江苏大隆凯科技有限公司| 一体化污水处理设备,一体化污水设备厂家-宜兴市福源水处理设备有限公司 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 北京印刷厂_北京印刷_北京印刷公司_北京印刷厂家_北京东爵盛世印刷有限公司 |