Zend ACL - 日志文件中的异常错误
这有点奇怪,因为我在日志文件中看到这些错误,但它们都不与我拥有的任何资源相对应。事实上,我什至不认识错误文件 Resource res、fcs、open 或 2127250264.html 中显示的任何资源
2010-12-26T12:19:46+00:00 ERR (3): Error Message Resource 'res' not found 2010-12-26T12:19:46+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('res') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'res', '2127250264.html') 2010-12-26T12:50:21+00:00 ERR (3): Error Message Resource 'fcs' not found 2010-12-26T12:50:21+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('fcs') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'fcs', 'ident2') 2010-12-26T12:50:22+00:00 ERR (3): Error Message Resource 'open' not found 2010-12-26T12:50:22+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('open') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'open', '1')
- 这些不是我的应用程序中的资源 - 所以我不确定这些错误意味着什么。
谁能告诉我如何调试这个。
编辑
class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract { private $_acl = null; public function __construct(Zend_Acl $acl) { $this->_acl = $acl; } public function preDispatch(Zend_Controller_Request_Abstract $request) { //As in the earlier example, authed users will have the role user $role = (Zend_Auth::getInstance()->hasIdentity()) ? 'user' : 'guest'; $controller = $request->getControllerName(); $action = $request->getActionName(); $requestUri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(); $session = new Zend_Session_Namespace('lastRequest'); // Temporary fix not to save view-image as last requested URL if(strpos($requestUri, 'snapshot')==false && $controller != 'register' && $controller != 'login' && $action != 'view-image' && $action != 'play-video' && $action != 'config') { //save the requested action only if it is not login $session->lastRequestUri = $requestUri; } if(!$this->_acl->isAllowed($role, $controller, $action)) { //If the user has no access we send him elsewhere by changing the request $request->setModuleName('default') ->setControllerName('login') ->setActionName('log'); } } }
这是我定义资源的类
class My_Acl extends Zend_Acl { public function __construct() { //Add a new role called "guest" $this->addRole(new Zend_Acl_Role('guest')); //Add a role called user, which inherits from guest $this->addRole(new Zend_Acl_Role('user'), 'guest'); //Add a resource called page $this->add(new Zend_Acl_Resource('video')); $this->add(new Zend_Acl_Resource('error')); $this->add(new Zend_Acl_Resource('index')); $this->add(new Zend_Acl_Resource('login')); $this->add(new Zend_Acl_Resource('register')); $this->add(new Zend_Acl_Resource('profile')); $this->add(new Zend_Acl_Resource('edit-profile')); $this->add(new Zend_Acl_Resource('css')); $this->add(new Zend_Acl_Resource('js')); $this->add(new Zend_Acl_Resource('images')); $this->add(new Zend_Acl_Resource('snapshots')); //Finally, we want to allow guests to view pages $this->allow('guest', 'css'); $this->allow('guest', 'js'); $this->allow('guest', 'snapshots'); $this->allow('guest', 'images'); $this->allow('guest', 'error'); $this->allow('guest', 'login'); $this->allow('guest', 'index'); $this->allow('guest', 'register'); $this->allow('guest', 'profile','view-profile'); $this->allow('guest', 'profile','view-image'); $this->allow('guest', 'profile','all-videos'); $this->allow('guest', 'profile','all-fans'); $this->allow('guest', 'profile','favorite-artists'); $this->allow('guest', 'profile','favorite-videos'); $this->allow('guest', 'video','display-thumb'); $this->allow('guest', 'video', 'config'); $this->allow('guest', 'video', 'play'); $this->allow('guest', 'video', 'play-video'); $this->allow('guest', 'video', 'new-videos'); $this->allow('guest', 'video', 'category'); $this->allow('guest', 'video', 'index'); $this->allow('guest', 'video', 'search'); $this->allow('user', 'video'); $this->allow('user', 'profile'); } }
This is a bit weird because I am seeing these bunch of errors in my log files and none of them correspond to any resources that I have. Infact I dont even recognize any of these resources that show up in the error files
2010-12-26T12:19:46+00:00 ERR (3): Error Message Resource 'res' not found 2010-12-26T12:19:46+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('res') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'res', '2127250264.html') 2010-12-26T12:50:21+00:00 ERR (3): Error Message Resource 'fcs' not found 2010-12-26T12:50:21+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('fcs') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'fcs', 'ident2') 2010-12-26T12:50:22+00:00 ERR (3): Error Message Resource 'open' not found 2010-12-26T12:50:22+00:00 ERR (3): Stack Trace #0 /var/www/application/library/Zend/Acl.php(691): Zend_Acl->get('open') #1 /var/www/application/library/My/Controller/Plugin/Acl.php(29): Zend_Acl->isAllowed('guest', 'open', '1')
Resource res, fcs, open or the 2127250264.html - these are not resources in my application - so I'm not sure what these errors mean.
Can anyone shed any light on how I can go about debugging this.
EDIT
class My_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract { private $_acl = null; public function __construct(Zend_Acl $acl) { $this->_acl = $acl; } public function preDispatch(Zend_Controller_Request_Abstract $request) { //As in the earlier example, authed users will have the role user $role = (Zend_Auth::getInstance()->hasIdentity()) ? 'user' : 'guest'; $controller = $request->getControllerName(); $action = $request->getActionName(); $requestUri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri(); $session = new Zend_Session_Namespace('lastRequest'); // Temporary fix not to save view-image as last requested URL if(strpos($requestUri, 'snapshot')==false && $controller != 'register' && $controller != 'login' && $action != 'view-image' && $action != 'play-video' && $action != 'config') { //save the requested action only if it is not login $session->lastRequestUri = $requestUri; } if(!$this->_acl->isAllowed($role, $controller, $action)) { //If the user has no access we send him elsewhere by changing the request $request->setModuleName('default') ->setControllerName('login') ->setActionName('log'); } } }
And this is the class where I have defined the resources
class My_Acl extends Zend_Acl { public function __construct() { //Add a new role called "guest" $this->addRole(new Zend_Acl_Role('guest')); //Add a role called user, which inherits from guest $this->addRole(new Zend_Acl_Role('user'), 'guest'); //Add a resource called page $this->add(new Zend_Acl_Resource('video')); $this->add(new Zend_Acl_Resource('error')); $this->add(new Zend_Acl_Resource('index')); $this->add(new Zend_Acl_Resource('login')); $this->add(new Zend_Acl_Resource('register')); $this->add(new Zend_Acl_Resource('profile')); $this->add(new Zend_Acl_Resource('edit-profile')); $this->add(new Zend_Acl_Resource('css')); $this->add(new Zend_Acl_Resource('js')); $this->add(new Zend_Acl_Resource('images')); $this->add(new Zend_Acl_Resource('snapshots')); //Finally, we want to allow guests to view pages $this->allow('guest', 'css'); $this->allow('guest', 'js'); $this->allow('guest', 'snapshots'); $this->allow('guest', 'images'); $this->allow('guest', 'error'); $this->allow('guest', 'login'); $this->allow('guest', 'index'); $this->allow('guest', 'register'); $this->allow('guest', 'profile','view-profile'); $this->allow('guest', 'profile','view-image'); $this->allow('guest', 'profile','all-videos'); $this->allow('guest', 'profile','all-fans'); $this->allow('guest', 'profile','favorite-artists'); $this->allow('guest', 'profile','favorite-videos'); $this->allow('guest', 'video','display-thumb'); $this->allow('guest', 'video', 'config'); $this->allow('guest', 'video', 'play'); $this->allow('guest', 'video', 'play-video'); $this->allow('guest', 'video', 'new-videos'); $this->allow('guest', 'video', 'category'); $this->allow('guest', 'video', 'index'); $this->allow('guest', 'video', 'search'); $this->allow('user', 'video'); $this->allow('user', 'profile'); } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜想(没有看到您的 My/Controller/Plugin/Acl.php)您从控制器/模块/操作名称中获取资源。有人访问了您不希望访问的 URL(可能来自您的应用程序的旧版本,该应用程序曾经具有不同的 URL)。
I would guess (without seeing your My/Controller/Plugin/Acl.php) that you derive your resources from controller/module/action name. And someone accessed URL that you would not expect to be visited (maybe from older version of you application, that used to have different URLs).
我最近也收到了同样奇怪的消息。正如 Tomáš 所建议的,我查看了 apache 访问日志,发现我的一张 css 表请求的文件丢失了。
因此,当您的公用文件夹中缺少文件时,您可能会收到类似
2011-02-22T02:44:49+03:00 DEBUG (7): Resource 'css' not find 的 错误
/usr/local/Zend/Acl.php(777): Zend_Acl->get('css')
/home/www/public_html/application/plugins/AccessControl.php(61): Zend_Acl->isAllowed('guest', 'css', 'img')
要解决这个问题 - 只需找到并删除以下请求css、html 等中缺少文件
I had the same strange messages recently. As Tomáš suggested, I looked through apache access logs and found that there were missing files that were requested by one of my css sheets.
So when you have a missing file in your public folder - you might get errors like
2011-02-22T02:44:49+03:00 DEBUG (7): Resource 'css' not found
/usr/local/Zend/Acl.php(777): Zend_Acl->get('css')
/home/www/public_html/application/plugins/AccessControl.php(61): Zend_Acl->isAllowed('guest', 'css', 'img')
To solve this - simply find and remove requests for missing files in your css, html etc