AclComponentTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /**
  3. * AclComponentTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake.tests.cases.libs.controller.components
  16. * @since CakePHP(tm) v 1.2.0.5435
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('AclComponent', 'Controller/Component');
  20. App::uses('AclNode', 'Model');
  21. class_exists('AclComponent');
  22. /**
  23. * AclNodeTwoTestBase class
  24. *
  25. * @package cake.tests.cases.libs.controller.components
  26. */
  27. class AclNodeTwoTestBase extends AclNode {
  28. /**
  29. * useDbConfig property
  30. *
  31. * @var string 'test'
  32. * @access public
  33. */
  34. public $useDbConfig = 'test';
  35. /**
  36. * cacheSources property
  37. *
  38. * @var bool false
  39. * @access public
  40. */
  41. public $cacheSources = false;
  42. }
  43. /**
  44. * AroTwoTest class
  45. *
  46. * @package cake.tests.cases.libs.controller.components
  47. */
  48. class AroTwoTest extends AclNodeTwoTestBase {
  49. /**
  50. * name property
  51. *
  52. * @var string 'AroTwoTest'
  53. * @access public
  54. */
  55. public $name = 'AroTwoTest';
  56. /**
  57. * useTable property
  58. *
  59. * @var string 'aro_twos'
  60. * @access public
  61. */
  62. public $useTable = 'aro_twos';
  63. /**
  64. * hasAndBelongsToMany property
  65. *
  66. * @var array
  67. * @access public
  68. */
  69. public $hasAndBelongsToMany = array('AcoTwoTest' => array('with' => 'PermissionTwoTest'));
  70. }
  71. /**
  72. * AcoTwoTest class
  73. *
  74. * @package cake.tests.cases.libs.controller.components
  75. */
  76. class AcoTwoTest extends AclNodeTwoTestBase {
  77. /**
  78. * name property
  79. *
  80. * @var string 'AcoTwoTest'
  81. * @access public
  82. */
  83. public $name = 'AcoTwoTest';
  84. /**
  85. * useTable property
  86. *
  87. * @var string 'aco_twos'
  88. * @access public
  89. */
  90. public $useTable = 'aco_twos';
  91. /**
  92. * hasAndBelongsToMany property
  93. *
  94. * @var array
  95. * @access public
  96. */
  97. public $hasAndBelongsToMany = array('AroTwoTest' => array('with' => 'PermissionTwoTest'));
  98. }
  99. /**
  100. * PermissionTwoTest class
  101. *
  102. * @package cake.tests.cases.libs.controller.components
  103. */
  104. class PermissionTwoTest extends CakeTestModel {
  105. /**
  106. * name property
  107. *
  108. * @var string 'PermissionTwoTest'
  109. * @access public
  110. */
  111. public $name = 'PermissionTwoTest';
  112. /**
  113. * useTable property
  114. *
  115. * @var string 'aros_aco_twos'
  116. * @access public
  117. */
  118. public $useTable = 'aros_aco_twos';
  119. /**
  120. * cacheQueries property
  121. *
  122. * @var bool false
  123. * @access public
  124. */
  125. public $cacheQueries = false;
  126. /**
  127. * belongsTo property
  128. *
  129. * @var array
  130. * @access public
  131. */
  132. public $belongsTo = array('AroTwoTest' => array('foreignKey' => 'aro_id'), 'AcoTwoTest' => array('foreignKey' => 'aco_id'));
  133. /**
  134. * actsAs property
  135. *
  136. * @var mixed null
  137. * @access public
  138. */
  139. public $actsAs = null;
  140. }
  141. /**
  142. * DbAclTwoTest class
  143. *
  144. * @package cake.tests.cases.libs.controller.components
  145. */
  146. class DbAclTwoTest extends DbAcl {
  147. /**
  148. * construct method
  149. *
  150. * @access private
  151. * @return void
  152. */
  153. function __construct() {
  154. $this->Aro = new AroTwoTest();
  155. $this->Aro->Permission = new PermissionTwoTest();
  156. $this->Aco = new AcoTwoTest();
  157. $this->Aro->Permission = new PermissionTwoTest();
  158. }
  159. }
  160. /**
  161. * Short description for class.
  162. *
  163. * @package cake.tests.cases.libs.controller.components
  164. */
  165. class AclComponentTest extends CakeTestCase {
  166. /**
  167. * setUp method
  168. *
  169. * @return void
  170. */
  171. function setUp() {
  172. parent::setUp();
  173. if (!class_exists('MockAclImplementation', false)) {
  174. $this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
  175. }
  176. Configure::write('Acl.classname', 'MockAclImplementation');
  177. $Collection = new ComponentCollection();
  178. $this->Acl = new AclComponent($Collection);
  179. }
  180. /**
  181. * tearDown method
  182. *
  183. * @return void
  184. */
  185. function tearDown() {
  186. parent::tearDown();
  187. unset($this->Acl);
  188. }
  189. /**
  190. * test that construtor throws an exception when Acl.classname is a
  191. * non-existant class
  192. *
  193. * @expectedException CakeException
  194. * @return void
  195. */
  196. function testConstrutorException() {
  197. Configure::write('Acl.classname', 'AclClassNameThatDoesNotExist');
  198. $Collection = new ComponentCollection();
  199. $acl = new AclComponent($Collection);
  200. }
  201. /**
  202. * test that adapter() allows control of the interal implementation AclComponent uses.
  203. *
  204. * @return void
  205. */
  206. function testAdapter() {
  207. $implementation = new MockAclImplementation();
  208. $implementation->expects($this->once())->method('initialize')->with($this->Acl);
  209. $this->assertNull($this->Acl->adapter($implementation));
  210. $this->assertEqual($this->Acl->adapter(), $implementation, 'Returned object is different %s');
  211. }
  212. /**
  213. * test that adapter() whines when the class is not an AclBase
  214. *
  215. * @expectedException CakeException
  216. * @return void
  217. */
  218. function testAdapterException() {
  219. $thing = new StdClass();
  220. $this->Acl->adapter($thing);
  221. }
  222. }
  223. /**
  224. * Test case for the IniAcl implementation
  225. *
  226. * @package cake.tests.cases.libs.controller.components
  227. */
  228. class IniAclTest extends CakeTestCase {
  229. /**
  230. * testIniCheck method
  231. *
  232. * @access public
  233. * @return void
  234. */
  235. function testCheck() {
  236. $iniFile = LIBS . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
  237. $Ini = new IniAcl();
  238. $Ini->config = $Ini->readConfigFile($iniFile);
  239. $this->assertFalse($Ini->check('admin', 'ads'));
  240. $this->assertTrue($Ini->check('admin', 'posts'));
  241. $this->assertTrue($Ini->check('jenny', 'posts'));
  242. $this->assertTrue($Ini->check('jenny', 'ads'));
  243. $this->assertTrue($Ini->check('paul', 'posts'));
  244. $this->assertFalse($Ini->check('paul', 'ads'));
  245. $this->assertFalse($Ini->check('nobody', 'comments'));
  246. }
  247. /**
  248. * check should accept a user array.
  249. *
  250. * @return void
  251. */
  252. function testCheckArray() {
  253. $iniFile = LIBS . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
  254. $Ini = new IniAcl();
  255. $Ini->config = $Ini->readConfigFile($iniFile);
  256. $Ini->userPath = 'User.username';
  257. $user = array(
  258. 'User' => array('username' => 'admin')
  259. );
  260. $this->assertTrue($Ini->check($user, 'posts'));
  261. }
  262. }
  263. /**
  264. * Test case for AclComponent using the DbAcl implementation.
  265. *
  266. * @package cake.tests.cases.libs.controller.components
  267. */
  268. class DbAclTest extends CakeTestCase {
  269. /**
  270. * fixtures property
  271. *
  272. * @var array
  273. * @access public
  274. */
  275. public $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two');
  276. /**
  277. * setUp method
  278. *
  279. * @return void
  280. */
  281. function setUp() {
  282. parent::setUp();
  283. Configure::write('Acl.classname', 'DbAclTwoTest');
  284. Configure::write('Acl.database', 'test');
  285. $Collection = new ComponentCollection();
  286. $this->Acl = new AclComponent($Collection);
  287. }
  288. /**
  289. * tearDown method
  290. *
  291. * @access public
  292. * @return void
  293. */
  294. function tearDown() {
  295. parent::tearDown();
  296. unset($this->Acl);
  297. }
  298. /**
  299. * testAclCreate method
  300. *
  301. * @access public
  302. * @return void
  303. */
  304. function testCreate() {
  305. $this->Acl->Aro->create(array('alias' => 'Chotchkey'));
  306. $this->assertTrue((bool)$this->Acl->Aro->save());
  307. $parent = $this->Acl->Aro->id;
  308. $this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
  309. $this->assertTrue((bool)$this->Acl->Aro->save());
  310. $this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
  311. $this->assertTrue((bool)$this->Acl->Aro->save());
  312. $root = $this->Acl->Aco->node('ROOT');
  313. $parent = $root[0]['AcoTwoTest']['id'];
  314. $this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
  315. $this->assertTrue((bool)$this->Acl->Aco->save());
  316. $this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
  317. $this->assertTrue((bool)$this->Acl->Aco->save());
  318. }
  319. /**
  320. * testAclCreateWithParent method
  321. *
  322. * @access public
  323. * @return void
  324. */
  325. function testCreateWithParent() {
  326. $parent = $this->Acl->Aro->findByAlias('Peter', null, null, -1);
  327. $this->Acl->Aro->create();
  328. $this->Acl->Aro->save(array(
  329. 'alias' => 'Subordinate',
  330. 'model' => 'User',
  331. 'foreign_key' => 7,
  332. 'parent_id' => $parent['AroTwoTest']['id']
  333. ));
  334. $result = $this->Acl->Aro->findByAlias('Subordinate', null, null, -1);
  335. $this->assertEqual($result['AroTwoTest']['lft'], 16);
  336. $this->assertEqual($result['AroTwoTest']['rght'], 17);
  337. }
  338. /**
  339. * testDbAclAllow method
  340. *
  341. * @access public
  342. * @return void
  343. */
  344. function testAllow() {
  345. $this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'read'));
  346. $this->assertTrue($this->Acl->allow('Micheal', 'tpsReports', array('read', 'delete', 'update')));
  347. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'update'));
  348. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'read'));
  349. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
  350. $this->assertFalse($this->Acl->check('Micheal', 'tpsReports', 'create'));
  351. $this->assertTrue($this->Acl->allow('Micheal', 'ROOT/tpsReports', 'create'));
  352. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'create'));
  353. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
  354. $this->assertTrue($this->Acl->allow('Micheal', 'printers', 'create'));
  355. // Michael no longer has his delete permission for tpsReports!
  356. $this->assertTrue($this->Acl->check('Micheal', 'tpsReports', 'delete'));
  357. $this->assertTrue($this->Acl->check('Micheal', 'printers', 'create'));
  358. $this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view'));
  359. $this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/view', '*'));
  360. $this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
  361. $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
  362. $this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
  363. $this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
  364. $this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
  365. $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
  366. // Samir should still have his tpsReports/view permissions, but does not
  367. $this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
  368. $this->expectError();
  369. $this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
  370. }
  371. /**
  372. * testAllowInvalidNode method
  373. *
  374. * @access public
  375. * @return void
  376. */
  377. public function testAllowInvalidNode() {
  378. $this->expectError();
  379. $this->Acl->allow('Homer', 'tpsReports', 'create');
  380. }
  381. /**
  382. * testDbAclCheck method
  383. *
  384. * @access public
  385. * @return void
  386. */
  387. function testCheck() {
  388. $this->assertTrue($this->Acl->check('Samir', 'print', 'read'));
  389. $this->assertTrue($this->Acl->check('Lumbergh', 'current', 'read'));
  390. $this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
  391. $this->assertFalse($this->Acl->check('Milton', 'current', 'update'));
  392. $this->assertFalse($this->Acl->check(null, 'printers', 'create'));
  393. $this->assertFalse($this->Acl->check('managers', null, 'read'));
  394. $this->assertTrue($this->Acl->check('Bobs', 'ROOT/tpsReports/view/current', 'read'));
  395. $this->assertFalse($this->Acl->check('Samir', 'ROOT/tpsReports/update', 'read'));
  396. $this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
  397. }
  398. /**
  399. * testCheckInvalidNode method
  400. *
  401. * @access public
  402. * @return void
  403. */
  404. public function testCheckInvalidNode() {
  405. $this->expectError();
  406. $this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
  407. }
  408. /**
  409. * testCheckInvalidPermission method
  410. *
  411. * @access public
  412. * @return void
  413. */
  414. public function testCheckInvalidPermission() {
  415. $this->expectError();
  416. $this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
  417. }
  418. /**
  419. * testCheckMissingPermission method
  420. *
  421. * @access public
  422. * @return void
  423. */
  424. public function testCheckMissingPermission() {
  425. $this->expectError();
  426. $this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
  427. }
  428. /**
  429. * testDbAclCascadingDeny function
  430. *
  431. * Setup the acl permissions such that Bobs inherits from admin.
  432. * deny Admin delete access to a specific resource, check the permisssions are inherited.
  433. *
  434. * @access public
  435. * @return void
  436. */
  437. function testAclCascadingDeny() {
  438. $this->Acl->inherit('Bobs', 'ROOT', '*');
  439. $this->assertTrue($this->Acl->check('admin', 'tpsReports', 'delete'));
  440. $this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'delete'));
  441. $this->Acl->deny('admin', 'tpsReports', 'delete');
  442. $this->assertFalse($this->Acl->check('admin', 'tpsReports', 'delete'));
  443. $this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'delete'));
  444. }
  445. /**
  446. * testDbAclDeny method
  447. *
  448. * @access public
  449. * @return void
  450. */
  451. function testDeny() {
  452. $this->assertTrue($this->Acl->check('Micheal', 'smash', 'delete'));
  453. $this->Acl->deny('Micheal', 'smash', 'delete');
  454. $this->assertFalse($this->Acl->check('Micheal', 'smash', 'delete'));
  455. $this->assertTrue($this->Acl->check('Micheal', 'smash', 'read'));
  456. $this->assertTrue($this->Acl->check('Micheal', 'smash', 'create'));
  457. $this->assertTrue($this->Acl->check('Micheal', 'smash', 'update'));
  458. $this->assertFalse($this->Acl->check('Micheal', 'smash', '*'));
  459. $this->assertTrue($this->Acl->check('Samir', 'refill', '*'));
  460. $this->Acl->deny('Samir', 'refill', '*');
  461. $this->assertFalse($this->Acl->check('Samir', 'refill', 'create'));
  462. $this->assertFalse($this->Acl->check('Samir', 'refill', 'update'));
  463. $this->assertFalse($this->Acl->check('Samir', 'refill', 'read'));
  464. $this->assertFalse($this->Acl->check('Samir', 'refill', 'delete'));
  465. $result = $this->Acl->Aro->Permission->find('all', array('conditions' => array('AroTwoTest.alias' => 'Samir')));
  466. $expected = '-1';
  467. $this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);
  468. $this->expectError();
  469. $this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
  470. }
  471. /**
  472. * testAclNodeLookup method
  473. *
  474. * @access public
  475. * @return void
  476. */
  477. function testAclNodeLookup() {
  478. $result = $this->Acl->Aro->node('root/users/Samir');
  479. $expected = array(
  480. array('AroTwoTest' => array('id' => '7', 'parent_id' => '4', 'model' => 'User', 'foreign_key' => 3, 'alias' => 'Samir')),
  481. array('AroTwoTest' => array('id' => '4', 'parent_id' => '1', 'model' => 'Group', 'foreign_key' => 3, 'alias' => 'users')),
  482. array('AroTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'root'))
  483. );
  484. $this->assertEqual($result, $expected);
  485. $result = $this->Acl->Aco->node('ROOT/tpsReports/view/current');
  486. $expected = array(
  487. array('AcoTwoTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'current')),
  488. array('AcoTwoTest' => array('id' => '3', 'parent_id' => '2', 'model' => null, 'foreign_key' => null, 'alias' => 'view')),
  489. array('AcoTwoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'tpsReports')),
  490. array('AcoTwoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT')),
  491. );
  492. $this->assertEqual($result, $expected);
  493. }
  494. /**
  495. * testDbInherit method
  496. *
  497. * @access public
  498. * @return void
  499. */
  500. function testInherit() {
  501. //parent doesn't have access inherit should still deny
  502. $this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
  503. $this->Acl->inherit('Milton', 'smash', 'delete');
  504. $this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
  505. //inherit parent
  506. $this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
  507. $this->Acl->inherit('Milton', 'smash', 'read');
  508. $this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
  509. }
  510. /**
  511. * testDbGrant method
  512. *
  513. * @access public
  514. * @return void
  515. */
  516. function testGrant() {
  517. $this->assertFalse($this->Acl->check('Samir', 'tpsReports', 'create'));
  518. $this->Acl->allow('Samir', 'tpsReports', 'create');
  519. $this->assertTrue($this->Acl->check('Samir', 'tpsReports', 'create'));
  520. $this->assertFalse($this->Acl->check('Micheal', 'view', 'read'));
  521. $this->Acl->allow('Micheal', 'view', array('read', 'create', 'update'));
  522. $this->assertTrue($this->Acl->check('Micheal', 'view', 'read'));
  523. $this->assertTrue($this->Acl->check('Micheal', 'view', 'create'));
  524. $this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
  525. $this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));
  526. $this->expectError();
  527. $this->assertFalse($this->Acl->allow('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
  528. }
  529. /**
  530. * testDbRevoke method
  531. *
  532. * @access public
  533. * @return void
  534. */
  535. function testRevoke() {
  536. $this->assertTrue($this->Acl->check('Bobs', 'tpsReports', 'read'));
  537. $this->Acl->deny('Bobs', 'tpsReports', 'read');
  538. $this->assertFalse($this->Acl->check('Bobs', 'tpsReports', 'read'));
  539. $this->assertTrue($this->Acl->check('users', 'printers', 'read'));
  540. $this->Acl->deny('users', 'printers', 'read');
  541. $this->assertFalse($this->Acl->check('users', 'printers', 'read'));
  542. $this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
  543. $this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));
  544. $this->expectError();
  545. $this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
  546. }
  547. /**
  548. * debug function - to help editing/creating test cases for the ACL component
  549. *
  550. * To check the overal ACL status at any time call $this->__debug();
  551. * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined
  552. * Only designed to work with the db based ACL
  553. *
  554. * @param bool $treesToo
  555. * @access private
  556. * @return void
  557. */
  558. function __debug ($printTreesToo = false) {
  559. $this->Acl->Aro->displayField = 'alias';
  560. $this->Acl->Aco->displayField = 'alias';
  561. $aros = $this->Acl->Aro->find('list', array('order' => 'lft'));
  562. $acos = $this->Acl->Aco->find('list', array('order' => 'lft'));
  563. $rights = array('*', 'create', 'read', 'update', 'delete');
  564. $permissions['Aros v Acos >'] = $acos;
  565. foreach ($aros as $aro) {
  566. $row = array();
  567. foreach ($acos as $aco) {
  568. $perms = '';
  569. foreach ($rights as $right) {
  570. if ($this->Acl->check($aro, $aco, $right)) {
  571. if ($right == '*') {
  572. $perms .= '****';
  573. break;
  574. }
  575. $perms .= $right[0];
  576. } elseif ($right != '*') {
  577. $perms .= ' ';
  578. }
  579. }
  580. $row[] = $perms;
  581. }
  582. $permissions[$aro] = $row;
  583. }
  584. foreach ($permissions as $key => $values) {
  585. array_unshift($values, $key);
  586. $values = array_map(array(&$this, '__pad'), $values);
  587. $permissions[$key] = implode (' ', $values);
  588. }
  589. $permisssions = array_map(array(&$this, '__pad'), $permissions);
  590. array_unshift($permissions, 'Current Permissions :');
  591. if ($printTreesToo) {
  592. debug(array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
  593. }
  594. debug(implode("\r\n", $permissions));
  595. }
  596. /**
  597. * pad function
  598. * Used by debug to format strings used in the data dump
  599. *
  600. * @param string $string
  601. * @param int $len
  602. * @access private
  603. * @return void
  604. */
  605. function __pad($string = '', $len = 14) {
  606. return str_pad($string, $len);
  607. }
  608. }