Zend_Auth的多个实例(二)
我有一个基于 Zend Framework 构建的 CMS。它使用 Zend_Auth
进行“CMS 用户”身份验证。 CMS 用户具有通过 Zend_Acl
强制执行的角色和权限。我现在正在尝试为在线商店等内容创建“站点用户”。为了简单起见,我想为站点用户使用一个单独的 Zend_Auth
实例。 Zend_Auth
是作为单例编写的,所以我不确定如何实现这一点。
我不想通过角色来实现此目的的原因:
- 站点用户(访问者)对 CMS 用户的污染
- 站点用户可能会意外获得提升的权限 用户
- 被更准确地定义为不同的类型而不是不同的角色
- 两种用户类型存储在单独的数据库/表
- 每种类型的一个用户可以同时登录
- 两种用户类型需要不同类型的信息
- 需要对现有代码进行重构
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:
- Pollution of the CMS Users with Site Users (visitors)
- A Site User could accidentally get elevated permissions
- The users are more accurately defined as different types than different roles
- The two user types are stored in separate databases/tables
- One user of each type could be signed in simultaneously
- Different types of information are needed for the two user types
- Refactoring that would need to take place on existing code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这种情况下,您想要创建自己的“Auth”类来扩展和删除 Zend_Auth 中存在的“单例”设计模式
。这绝不是完整的,但您可以创建一个实例并向其传递一个“命名空间”。 Zend_Auth 的其余公共方法应该适合您。
然后在您想要使用它的地方,
$auth = new My_Auth('CMSUser');
或$auth = new My_Auth('SiteUser');
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.
Then where you want to use it,
$auth = new My_Auth('CMSUser');
or$auth = new My_Auth('SiteUser');
试试这个,只需要在各处使用 App_Auth 而不是 Zend_Auth,或者在管理区域使用 App_auth,在前面使用 Zend_Auth
Try this one , just will need to use App_Auth instead of Zend_Auth everywhere, or App_auth on admin's area, Zend_Auth on front
这是我的建议:
我认为你应该动态计算 ACL、资源、角色,
例如 {md5(siteuser 或 cmsuser + module + control)= 每个角色的随机数 }
和一个简单的插件将允许此角色对此资源
或者你可以像unix权限风格一样构建,但我想这个想法需要大量的测试
有一天我会在采埃孚建造一个类似的:)
我希望我的想法对你有帮助
that is my suggestion :
i think you are in case that you should calculate ACL , recourses , roles dynamically ,
example {md5(siteuser or cmsuser + module + controller)= random number for each roles }
and a simple plugin would this role is allowed to this recourse
or you can build like unix permission style but i guess this idea need alot of testing
one day i will build one like it in ZF :)
i hope my idea helps you
你正在混合问题。 (并不是说我第一次面对 id 时没有)
Zend_Auth 回答了“那个用户是他声称的那个人”的问题吗?您可以做的就是向持久性对象添加更多信息。最简单的选择是 在数据库中再添加一列并将其添加到结果。
You're mixing problems. (not that I didn't when I first faced id)
Zend_Auth answers the question "is that user who he claims to be"? What you can do is to add some more info to your persistence object. Easiest option is to add one more column into your DB and add it to result.