Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Zend] Acl i problem "resource ... not found"
popson
post 14.09.2012, 18:19:58
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 25.11.2011

Ostrzeżenie: (0%)
-----


Witam!

Mam problem z ACL'em. Otóż Gdy nie włączę wtyczki to podczas wbicia niepoprawnego adresu następuje przekierowanie na kontroler i akcję error z błędem ControllerNotFound. Jeżeli podepnę wtyczkę, to następuje error ale z błędem OtherError i w treści pisze resource "nazwa_kontrolera" not found. Próbowałem ustawić ręcznie akcję i kontroler przy warunku $acl->has($controller), ale wtedy aplikacja się zapętlała (zapewne przez funkcję preDispatch, zmiana na loopstartup nie przyniosła efektu). Co można zrobić ? kod plugina zamieszczam poniżej:

  1. <?php
  2.  
  3. class My_Plugins_Acl extends Zend_Controller_Plugin_Abstract
  4. {
  5. public function preDispatch(Zend_Controller_Request_Abstract $request)
  6. {
  7. $viewRenderer = Zend_Controller_Action_HelperBroker::getHelper( 'ViewRenderer' );
  8. $view = $viewRenderer->view;
  9. $view->ControllerName = $request->getControllerName();
  10. $view->ActionName = $request->getActionName();
  11. $view->baseUrl = $request->getBaseUrl();
  12. if($request->getControllerName() != 'logowanie' || $request->getActionName() != 'index'){
  13. setcookie('last_uri', $_SERVER['REQUEST_URI'], time()+3600*2);
  14. }
  15.  
  16. if (Zend_Auth::getInstance()->hasIdentity()){
  17. $role = Zend_Auth::getInstance()->getStorage()->read()->role;
  18. $ip = Zend_Auth::getInstance()->getStorage()->read()->ip;
  19. }else{
  20. $role = 'gosc';
  21. }
  22.  
  23. $acl = new Acl_Shop();
  24. if (!$acl->isAllowed($role, $request->getControllerName(), $request->getActionName())){
  25. $request->setModuleName('default')
  26. ->setControllerName('logowanie')
  27. ->setActionName('index')
  28. ->setDispatched(false);
  29.  
  30. }
  31.  
  32.  
  33. }
  34. }


Ten post edytował popson 14.09.2012, 18:24:41
Go to the top of the page
+Quote Post
Pilsener
post 14.09.2012, 18:56:37
Post #2





Grupa: Zarejestrowani
Postów: 1 590
Pomógł: 185
Dołączył: 19.04.2006
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


1. Musisz stworzyć drzewo uprawnień:
- defniujesz role, np. tak:
  1. $acl = new Zend_Acl();
  2. $acl->addRole('guest');

- potem zasoby, np. tak:
  1. //powiedzmy, że zasób będzie w postaci kontroler:akcja
  2. $acl->addResource('default:index');
  3. $acl->addResource('default:news');

- potem przypisujesz role do zasobów:
  1. $acl->allow('guest', 'default:index');
  2. $acl->allow('guest', 'default:news');


2. Potem wystarczy sprawdzić, czy dana rola ma dostęp do zasobu tak:
  1. $acl->isAllowed();


Błąd mówi wyraźnie, że próbujesz sprawdzić dostęp do nieistniejącego zasobu, masz dokumentację:
http://framework.zend.com/manual/1.12/en/z...l.refining.html
Go to the top of the page
+Quote Post
popson
post 14.09.2012, 18:58:53
Post #3





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 25.11.2011

Ostrzeżenie: (0%)
-----


Role i dostęp do zasobów mam już zdefiniowane w modelu:

  1. <?php
  2. class Acl_Shop extends Zend_Acl
  3. {
  4. public function __construct()
  5. {
  6. //Tworzymy role:
  7. $this->addRole(new Zend_Acl_Role('gosc'));
  8. $this->addRole(new Zend_Acl_Role('admin'));
  9.  
  10. $this->add(new Zend_Acl_Resource('admin'));
  11. $this->add(new Zend_Acl_Resource('logowanie'));
  12. $this->add(new Zend_Acl_Resource('error'));
  13. $this->add(new Zend_Acl_Resource('index'));
  14. $this->add(new Zend_Acl_Resource('logout'));
  15.  
  16.  
  17.  
  18. //Definiujemy reguly dostepu:
  19. $this->allow('gosc', array(
  20. 'index',
  21. 'error',
  22. 'logowanie',
  23. 'logout'
  24. ), null);
  25. $this->allow('gosc', array('index','logowanie','logout'), null);
  26. $this->allow('admin', null, null);
  27. }
  28. }
Go to the top of the page
+Quote Post
Pilsener
post 14.09.2012, 19:20:00
Post #4





Grupa: Zarejestrowani
Postów: 1 590
Pomógł: 185
Dołączył: 19.04.2006
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


Spróbuj odłączyć plugin i wywołać ACLa ręcznie z inita jakiegoś kontrolera, w ten sposób dowiemy się, czy model jest ok.
Go to the top of the page
+Quote Post
popson
post 15.09.2012, 14:48:47
Post #5





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 25.11.2011

Ostrzeżenie: (0%)
-----


Poniżej przedstawiam wycinek obiektu, gdzie są zapisane role, oraz zasoby. Wydaje mi się, ze z obiektem jest wszystko ok.


  1. Acl_Shop Object
  2. (
  3. [_roleRegistry:protected] => Zend_Acl_Role_Registry Object
  4. (
  5. [_roles:protected] => Array
  6. (
  7. [gosc] => Array
  8. (
  9. [instance] => Zend_Acl_Role Object
  10. (
  11. [_roleId:protected] => gosc
  12. )
  13.  
  14. [parents] => Array
  15. (
  16. )
  17.  
  18. [children] => Array
  19. (
  20. )
  21.  
  22. )
  23.  
  24. [admin] => Array
  25. (
  26. [instance] => Zend_Acl_Role Object
  27. (
  28. [_roleId:protected] => admin
  29. )
  30.  
  31. [parents] => Array
  32. (
  33. )
  34.  
  35. [children] => Array
  36. (
  37. )
  38.  
  39. )
  40.  
  41. )
  42.  
  43. )
  44.  
  45. [_resources:protected] => Array
  46. (
  47. [admin] => Array
  48. (
  49. [instance] => Zend_Acl_Resource Object
  50. (
  51. [_resourceId:protected] => admin
  52. )
  53.  
  54. [parent] =>
  55. [children] => Array
  56. (
  57. )
  58.  
  59. )
  60.  
  61. [logowanie] => Array
  62. (
  63. [instance] => Zend_Acl_Resource Object
  64. (
  65. [_resourceId:protected] => logowanie
  66. )
  67.  
  68. [parent] =>
  69. [children] => Array
  70. (
  71. )
  72.  
  73. )
  74.  
  75. [error] => Array
  76. (
  77. [instance] => Zend_Acl_Resource Object
  78. (
  79. [_resourceId:protected] => error
  80. )
  81.  
  82. [parent] =>
  83. [children] => Array
  84. (
  85. )
  86.  
  87. )
  88.  
  89. [index] => Array
  90. (
  91. [instance] => Zend_Acl_Resource Object
  92. (
  93. [_resourceId:protected] => index
  94. )
  95.  
  96. [parent] =>
  97. [children] => Array
  98. (
  99. )
  100.  
  101. )
  102.  
  103. [logout] => Array
  104. (
  105. [instance] => Zend_Acl_Resource Object
  106. (
  107. [_resourceId:protected] => logout
  108. )
  109.  
  110. [parent] =>
  111. [children] => Array
  112. (
  113. )
  114.  
  115. )
  116.  
  117. )
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.06.2025 - 09:09