Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> RBAC, problem w zrozumieniu struktury DB
czachor
post
Post #1





Grupa: Zarejestrowani
Postów: 897
Pomógł: 40
Dołączył: 16.12.2003
Skąd: Warszawa

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


Witam,
implementuję u siebie kontrolę dostępu opartą na tym: http://www.sqlrecipes.com/database_design/..._rbac_system-3/
Mam pytanie, szczególnie do tych, którzy korzystali z tego (o ile tacy są). Próbuję zrozumieć, po kiego są domeny (tabela rbac_domains)? W załączonych tam plikach jest metoda IsAllowedTo():
  1. <?php
  2. Function IsAllowedTo($id, $action, $object, $conn = ''){
  3.  
  4. if (!is_object($conn)){
  5. if (!isset($this->mConn)){
  6. trigger_error('Must supply database connection.', E_USER_ERROR);
  7. }
  8. else{
  9. $conn = $this->mConn;
  10. }
  11. }
  12.  
  13. // Check whether answer is already in sessions.
  14. if (isset($_SESSION['rbac_bv'][$id][$action][$object])) {
  15. if ($_SESSION['rbac_bv'][$id][$action][$object]){ // Do not touch. This if statement must be inside the parent if statement.
  16. return TRUE;
  17. } else {
  18. return FALSE;
  19. }
  20. }
  21.  
  22. // We order the role by importance. The most important role will come first. There
    fore when we loop through the record we will ignore
  23. // all other roles.
  24. $_sql = "
  25. SELECT is_allowed, t2.name AS privilege, t2.is_singular AS is_privilege_singular
    , t4.name AS action, t5.name AS domain, t5.is_singular AS is_domain_singular, t7.
    name AS object, t8.name as role, t8.importance
  26. FROM rbac_roles_has_domain_privileges AS t1
  27. -- Privileges Joins --
  28. INNER JOIN rbac_privileges AS t2 ON t2.id = t1.privileges_id 
  29. INNER JOIN rbac_privileges_has_actions AS t3 ON t3.privileges_id = t2.id
  30. INNER JOIN rbac_actions AS t4 ON t4.id = t3.actions_id
  31. -- Domain Joins --
  32. INNER JOIN rbac_domains AS t5 ON t5.id = t1.domains_id
  33. INNER JOIN rbac_domains_has_objects AS t6 ON t6.domains_id = t5.id
  34. INNER JOIN rbac_objects AS t7 ON t7.id = t6.objects_id
  35. -- Roles to user Joins --
  36. INNER JOIN rbac_roles AS t8 ON t8.id = t1.roles_id
  37. INNER JOIN rbac_users_has_roles AS t9 ON t9.roles_id = t8.id
  38. WHERE users_id = $id AND t4.name = '$action' AND t7.name = '$object'
  39. ORDER BY t8.importance DESC, t8.name
  40. ";
  41.  
  42. $conn->GetAll($_sql);
  43.  
  44. //----------------
  45. // Initialise variables.
  46. $weight = -1; // Used to find out which privileges take precedence.
  47. $is_allowed = 0; // FALSE, initialise
  48. $prev_importance = '';
  49. $count = 0;
  50.  
  51. // Loop through all matches
  52. while ($conn->NextRow(FALSE)){
  53.  
  54. $importance = $conn->importance;
  55. $is_allowed = (int) $conn->is_allowed;
  56.  
  57. // We are only interested in the roles with the most importance (i.e. Some roles may have the same importance.)
  58. if ($count > 0 && $importance !== $prev_importance){
  59. break;
  60. }
  61.  
  62. $new_weight = (int) $conn->is_privilege_singular + (int) $conn->is_domain_singular;
  63.  
  64. if ($new_weight > $weight){
  65. $weight = $new_weight;
  66. }
  67. else if ($new_weight == $weight && (int) $is_allowed === 1 && (int) $is_allowed === 0){
  68.  
  69. // We always give more weight to denials.
  70. $weight = $new_weight;
  71. }
  72.  
  73. // echo "Role is $conn->role and weight is $new_weight and is_allowed $conn->is_allowed ($is_allowed)<br>";
  74.  
  75. $prev_importance = $importance;
  76. $count++;
  77.  
  78. }
  79.  
  80. //------------------------------
  81. // Store value in sessions for next time.
  82. $_SESSION['rbac_bv'][$id][$action][$object] = $is_allowed;
  83. //session_write_close();
  84.  
  85. //-------------
  86. // Return answer
  87. if ($is_allowed){
  88. return TRUE;
  89. } else {
  90. return FALSE;
  91. }
  92. }
  93. ?>


Sprawdzanie dostępu jak rozumiem polega na sprawdzeniu, czy $user_id ma pozwolenie (is_allowed) na wykonanie akcji (np. "edit") na danym obiekcie (np. "member_page"). W takim razie po co są domeny (domains) i uprawnienia (privileges)? Niby są sprawdzane, czy są pojedyncze czy nie, ale nie widzę, żeby miało to jakieś znaczenie... Albo czegoś nie widzę albo jest to niepotrzebne... Będę wdzięczny za wskazówki.
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 23.08.2025 - 04:50