douxun3496 2010-11-30 21:02
浏览 29
已采纳

Zend_Auth的多个实例(2)

I have a CMS built on the Zend Framework. It uses Zend_Auth for "CMS User" authentication. CMS users have roles and permissions that are enforced with Zend_Acl. I am now trying to create "Site Users" for things like an online store. For simplicity sake I would like to use a separate instance of Zend_Auth for site users. Zend_Auth is written as a singleton, so I'm not sure how to accomplish this.

Reasons I don't want to accomplish this by roles:

  1. Pollution of the CMS Users with Site Users (visitors)
  2. A Site User could accidentally get elevated permissions
  3. The users are more accurately defined as different types than different roles
  4. The two user types are stored in separate databases/tables
  5. One user of each type could be signed in simultaneously
  6. Different types of information are needed for the two user types
  7. Refactoring that would need to take place on existing code
  • 写回答

4条回答 默认 最新

  • douxuqiao6394 2010-11-30 21:58
    关注

    In that case, you want to create your own 'Auth' class to extend and remove the 'singleton' design pattern that exists in Zend_Auth

    This is by no means complete, but you can create an instance and pass it a 'namespace'. The rest of Zend_Auth's public methods should be fine for you.

    <?php
    class My_Auth extends Zend_Auth
    {
    
        public function __construct($namespace) {
            $this->setStorage(new Zend_Auth_Storage_Session($namespace));
            // do other stuff
        }
        static function getInstance() {
            throw new Zend_Auth_Exception('I do not support getInstance');
        }  
    }
    

    Then where you want to use it, $auth = new My_Auth('CMSUser'); or $auth = new My_Auth('SiteUser');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'