Php 需要Zend Framework 1.9中身份验证/授权/访问控制的完整示例

Php 需要Zend Framework 1.9中身份验证/授权/访问控制的完整示例,php,zend-framework,Php,Zend Framework,我有一些Zend Framework应用正在运行,是时候添加用户访问限制了。我坚信,您应该尽可能避免使用自己的安全基础设施,因此我一直在尝试找出如何使用Zend_Auth和Zend_Acl来实现它,但迄今为止没有成功 我已经在网上搜索过了,至少有一本书,但我找不到一个如何把所有部分串在一起的例子。我找到了一个身份验证的例子,授权/访问控制的老例子,以及未来的建议,但我对ZF的了解还不够透彻,无法将它们全部放在一起 我需要的是:一个简单的公开示例或教程,完全详细说明[作为可下载和可运行的代码]如何

我有一些Zend Framework应用正在运行,是时候添加用户访问限制了。我坚信,您应该尽可能避免使用自己的安全基础设施,因此我一直在尝试找出如何使用Zend_Auth和Zend_Acl来实现它,但迄今为止没有成功

我已经在网上搜索过了,至少有一本书,但我找不到一个如何把所有部分串在一起的例子。我找到了一个身份验证的例子,授权/访问控制的老例子,以及未来的建议,但我对ZF的了解还不够透彻,无法将它们全部放在一起

我需要的是:一个简单的公开示例或教程,完全详细说明[作为可下载和可运行的代码]如何使用当前的Zend Framework版本(1.9.5,无“建议”或“实验室”)管理三个不同角色的三个用户(及其密码)的身份验证/授权/访问控制(例如guest、member、administrator)保护默认模块中的三个不同控制器。该示例应尽可能多地使用当前ZF库。不,这不是家庭作业;风险更大:-(

如果它存在的地方,我还没有找到它。任何帮助感谢。我想这将是非常有帮助的新来者采埃孚

披露:我有一个关于ZF的社区维基问题,因为我想知道我是否会继续。但我真的需要现在就运行我的应用程序!

,第8章对此进行了很好的处理。除了preDispatch方法外,他的大多数方法与我使用的方法非常相似。在进行身份验证时,我有preDispatch redi我还保留了为使用登录操作而请求的Url

class SitePluginAuth extends Zend_Controller_Plugin_Abstract { private $_auth; private $_acl; private $_noauthPath = '/account/log-in/'; private $_noacl = array('module' => 'default', 'controller' => 'error', 'action' => 'denied'); public function __construct($auth, $acl) { $this->_auth = $auth; $this->_acl = $acl; } public function preDispatch($request) { $resource = $request->controller; if (!$this->_acl->has($resource)) return; $controller = $request->controller; $action = $request->action; $module = $request->module; if ($this->_auth->hasIdentity()) { $identity = $this->_auth->getIdentity(); $role = 'member'; } else { $role = 'guest'; } /* * Remember to URL encode the parameter value. Also, when you are processing the value of the * redirect URL, make sure that it is a URL on your site or a relative URL to avoid any security * attacks like a phishing scheme. Otherwise, a third party can target your site's login page and * then redirect back to their site and might have access to the user's secured session. * * The reason I don't use the session to store the URL, is that search engine spiders can end up * creating sessions as they hit links on your site that are secured and require login. Since they * have no credentials, the session is created only to timeout 30 minutes later. */ if (!$this->_acl->isAllowed($role, $resource, $action)) { if (!$this->_auth->hasIdentity()) { $requestedUrl = substr($request->getRequestUri(), strlen($request->getBaseUrl())); // relative url $loginUrl = $this->_noauthPath.'?requestedUrl='.urlencode($requestedUrl); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoUrl($loginUrl); } else { $request->setModuleName($this->_noacl['module']); $request->setControllerName($this->_noacl['controller']); $request->setActionName($this->_noacl['action']); } } } } 类SitePluginuth扩展了Zend\u控制器\u插件\u抽象 { 私有$_auth; 私有$acl; private$_noauthPath='/account/log-in/'; 私有$_noacl=array('module'=>'default','controller'=>'error','action'=>'denied'); 公共函数构造($auth,$acl) { $this->_auth=$auth; $this->_acl=$acl; } 公共职能预分配($request) { $resource=$request->controller; 如果(!$this->\u acl->has($resource))返回; $controller=$request->controller; $action=$request->action; $module=$request->module; 如果($this->\u auth->hasintity()){ $identity=$this->_auth->getIdentity(); $role='member'; } 否则{ $role='guest'; } /* *记住对参数值进行URL编码 *重定向URL,确保它是站点上的URL或相对URL,以避免任何安全性 *类似网络钓鱼计划的攻击。否则,第三方可能会以您网站的登录页面为目标,并 *然后重定向回他们的站点,可能可以访问用户的安全会话。 * *我不使用会话来存储URL的原因是搜索引擎爬行器最终可能会 *正在创建会话,因为它们会在您的站点上访问安全的链接,并且需要登录。因为 *如果没有凭据,则仅在30分钟后创建会话超时。 */ 如果(!$this->\u acl->isAllowed($role、$resource、$action)){ 如果(!$this->\u auth->hasintity()){ $requestedUrl=substr($request->getRequestUri(),strlen($request->getBaseUrl());//相对url $loginUrl=$this->\u noauthPath'?requestedUrl='.urlencode($requestedUrl); $redirector=Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotour($loginUrl); } 否则{ $request->setModuleName($this->_noacl['module']); $request->setControllerName($this->_noacl['controller']); $request->setActionName($this->_noacl['action']); } } } } 我将此应用程序用作示例:。它是一个完整的工作应用程序。但该网站现在已关闭。请尝试搜索“Dodo task management ZF sample”或类似内容。也许您可以找到源代码。