acl.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * This is the PHP base ACL configuration file.
  4. *
  5. * Use it to configure access control of your CakePHP application.
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @package app.Config
  17. * @since CakePHP(tm) v 2.1
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  19. */
  20. /**
  21. * Example
  22. * -------
  23. *
  24. * Assumptions:
  25. *
  26. * 1. In your application you created a User model with the following properties:
  27. * username, group_id, password, email, firstname, lastname and so on.
  28. * 2. You configured AuthComponent to authorize actions via
  29. * $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...)
  30. *
  31. * Now, when a user (i.e. jeff) authenticates successfully and requests a controller action (i.e. /invoices/delete)
  32. * that is not allowed by default (e.g. via $this->Auth->allow('edit') in the Invoices controller) then AuthComponent
  33. * will ask the configured ACL interface if access is granted. Under the assumptions 1. and 2. this will be
  34. * done via a call to Acl->check() with
  35. *
  36. * array('User' => array('username' => 'jeff', 'group_id' => 4, ...))
  37. *
  38. * as ARO and
  39. *
  40. * '/controllers/invoices/delete'
  41. *
  42. * as ACO.
  43. *
  44. * If the configured map looks like
  45. *
  46. * $config['map'] = array(
  47. * 'User' => 'User/username',
  48. * 'Role' => 'User/group_id',
  49. * );
  50. *
  51. * then PhpAcl will lookup if we defined a role like User/jeff. If that role is not found, PhpAcl will try to
  52. * find a definition for Role/4. If the definition isn't found then a default role (Role/default) will be used to
  53. * check rules for the given ACO. The search can be expanded by defining aliases in the alias configuration.
  54. * E.g. if you want to use a more readable name than Role/4 in your definitions you can define an alias like
  55. *
  56. * $config['alias'] = array(
  57. * 'Role/4' => 'Role/editor',
  58. * );
  59. *
  60. * In the roles configuration you can define roles on the lhs and inherited roles on the rhs:
  61. *
  62. * $config['roles'] = array(
  63. * 'Role/admin' => null,
  64. * 'Role/accountant' => null,
  65. * 'Role/editor' => null,
  66. * 'Role/manager' => 'Role/editor, Role/accountant',
  67. * 'User/jeff' => 'Role/manager',
  68. * );
  69. *
  70. * In this example manager inherits all rules from editor and accountant. Role/admin doesn't inherit from any role.
  71. * Lets define some rules:
  72. *
  73. * $config['rules'] = array(
  74. * 'allow' => array(
  75. * '*' => 'Role/admin',
  76. * 'controllers/users/(dashboard|profile)' => 'Role/default',
  77. * 'controllers/invoices/*' => 'Role/accountant',
  78. * 'controllers/articles/*' => 'Role/editor',
  79. * 'controllers/users/*' => 'Role/manager',
  80. * 'controllers/invoices/delete' => 'Role/manager',
  81. * ),
  82. * 'deny' => array(
  83. * 'controllers/invoices/delete' => 'Role/accountant, User/jeff',
  84. * 'controllers/articles/(delete|publish)' => 'Role/editor',
  85. * ),
  86. * );
  87. *
  88. * Ok, so as jeff inherits from Role/manager he's matched every rule that references User/jeff, Role/manager,
  89. * Role/editor, Role/accountant and Role/default. However, for jeff, rules for User/jeff are more specific than
  90. * rules for Role/manager, rules for Role/manager are more specific than rules for Role/editor and so on.
  91. * This is important when allow and deny rules match for a role. E.g. Role/accountant is allowed
  92. * controllers/invoices/* but at the same time controllers/invoices/delete is denied. But there is a more
  93. * specific rule defined for Role/manager which is allowed controllers/invoices/delete. However, the most specific
  94. * rule denies access to the delete action explicitly for User/jeff, so he'll be denied access to the resource.
  95. *
  96. * If we would remove the role definition for User/jeff, then jeff would be granted access as he would be resolved
  97. * to Role/manager and Role/manager has an allow rule.
  98. */
  99. /**
  100. * The role map defines how to resolve the user record from your application
  101. * to the roles you defined in the roles configuration.
  102. */
  103. $config['map'] = array(
  104. 'User' => 'User/username',
  105. 'Role' => 'User/group_id',
  106. );
  107. /**
  108. * define aliases to map your model information to
  109. * the roles defined in your role configuration.
  110. */
  111. $config['alias'] = array(
  112. 'Role/4' => 'Role/editor',
  113. );
  114. /**
  115. * role configuration
  116. */
  117. $config['roles'] = array(
  118. 'Role/admin' => null,
  119. );
  120. /**
  121. * rule configuration
  122. */
  123. $config['rules'] = array(
  124. 'allow' => array(
  125. '*' => 'Role/admin',
  126. ),
  127. 'deny' => array(),
  128. );