PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/config/permissions.php

http://github.com/CakeDC/users
PHP | 139 lines | 79 code | 3 blank | 57 comment | 2 complexity | f8a2dd614eb386973edd8f386c36c0e0 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
  4. *
  5. * Licensed under The MIT License
  6. * Redistributions of files must retain the above copyright notice.
  7. *
  8. * @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com)
  9. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  10. */
  11. /*
  12. * IMPORTANT:
  13. * This is an example configuration file. Copy this file into your config directory and edit to
  14. * setup your app permissions.
  15. *
  16. * This is a quick roles-permissions implementation
  17. * Rules are evaluated top-down, first matching rule will apply
  18. * Each line define
  19. * [
  20. * 'role' => 'role' | ['roles'] | '*'
  21. * 'prefix' => 'Prefix' | , (default = null)
  22. * 'plugin' => 'Plugin' | , (default = null)
  23. * 'controller' => 'Controller' | ['Controllers'] | '*',
  24. * 'action' => 'action' | ['actions'] | '*',
  25. * 'allowed' => true | false | callback (default = true)
  26. * ]
  27. * You could use '*' to match anything
  28. * 'allowed' will be considered true if not defined. It allows a callable to manage complex
  29. * permissions, like this
  30. * 'allowed' => function (array $user, $role, Request $request) {}
  31. *
  32. * Example, using allowed callable to define permissions only for the owner of the Posts to edit/delete
  33. *
  34. * (remember to add the 'uses' at the top of the permissions.php file for Hash, TableRegistry and Request
  35. [
  36. 'role' => ['user'],
  37. 'controller' => ['Posts'],
  38. 'action' => ['edit', 'delete'],
  39. 'allowed' => function(array $user, $role, Request $request) {
  40. $postId = Hash::get($request->params, 'pass.0');
  41. $post = TableRegistry::getTableLocator()->get('Posts')->get($postId);
  42. $userId = Hash::get($user, 'id');
  43. if (!empty($post->user_id) && !empty($userId)) {
  44. return $post->user_id === $userId;
  45. }
  46. return false;
  47. }
  48. ],
  49. */
  50. return [
  51. 'CakeDC/Auth.permissions' => [
  52. //all bypass
  53. [
  54. 'prefix' => false,
  55. 'plugin' => 'CakeDC/Users',
  56. 'controller' => 'Users',
  57. 'action' => [
  58. // LoginTrait
  59. 'socialLogin',
  60. 'login',
  61. 'logout',
  62. 'socialEmail',
  63. 'verify',
  64. // RegisterTrait
  65. 'register',
  66. 'validateEmail',
  67. // PasswordManagementTrait used in RegisterTrait
  68. 'changePassword',
  69. 'resetPassword',
  70. 'requestResetPassword',
  71. // UserValidationTrait used in PasswordManagementTrait
  72. 'resendTokenValidation',
  73. 'linkSocial',
  74. //U2F actions
  75. 'u2f',
  76. 'u2fRegister',
  77. 'u2fRegisterFinish',
  78. 'u2fAuthenticate',
  79. 'u2fAuthenticateFinish',
  80. ],
  81. 'bypassAuth' => true,
  82. ],
  83. [
  84. 'prefix' => false,
  85. 'plugin' => 'CakeDC/Users',
  86. 'controller' => 'SocialAccounts',
  87. 'action' => [
  88. 'validateAccount',
  89. 'resendValidation',
  90. ],
  91. 'bypassAuth' => true,
  92. ],
  93. //admin role allowed to all the things
  94. [
  95. 'role' => 'admin',
  96. 'prefix' => '*',
  97. 'extension' => '*',
  98. 'plugin' => '*',
  99. 'controller' => '*',
  100. 'action' => '*',
  101. ],
  102. //specific actions allowed for the all roles in Users plugin
  103. [
  104. 'role' => '*',
  105. 'plugin' => 'CakeDC/Users',
  106. 'controller' => 'Users',
  107. 'action' => ['profile', 'logout', 'linkSocial', 'callbackLinkSocial'],
  108. ],
  109. [
  110. 'role' => '*',
  111. 'plugin' => 'CakeDC/Users',
  112. 'controller' => 'Users',
  113. 'action' => 'resetOneTimePasswordAuthenticator',
  114. 'allowed' => function (array $user, $role, \Cake\Http\ServerRequest $request) {
  115. $userId = \Cake\Utility\Hash::get($request->getAttribute('params'), 'pass.0');
  116. if (!empty($userId) && !empty($user)) {
  117. return $userId === $user['id'];
  118. }
  119. return false;
  120. }
  121. ],
  122. //all roles allowed to Pages/display
  123. [
  124. 'role' => '*',
  125. 'controller' => 'Pages',
  126. 'action' => 'display',
  127. ],
  128. [
  129. 'role' => '*',
  130. 'plugin' => 'DebugKit',
  131. 'controller' => '*',
  132. 'action' => '*',
  133. 'bypassAuth' => true,
  134. ],
  135. ]
  136. ];