You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2017 Marcos Pereira <marcospereira.mpj@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. class Permission:
  18. """
  19. Consider this simple and very common permission:
  20. A permission associates the object being protected with the policies that must be evaluated to determine whether access is granted.
  21. X CAN DO Y ON RESOURCE Z
  22. where
  23. X represents one or more users, roles, or groups, or a combination of them. You can
  24. also use claims and context here.
  25. Y represents an action to be performed, for example, write, view, and so on.
  26. Z represents a protected resource, for example, "/accounts".
  27. https://keycloak.gitbooks.io/documentation/authorization_services/topics/permission/overview.html
  28. """
  29. def __init__(self, name, type, logic, decision_strategy):
  30. self._name = name
  31. self._type = type
  32. self._logic = logic
  33. self._decision_strategy = decision_strategy
  34. self._resources = []
  35. self._scopes = []
  36. def __repr__(self):
  37. return "<Permission: %s (%s)>" % (self.name, self.type)
  38. def __str__(self):
  39. return "Permission: %s (%s)" % (self.name, self.type)
  40. @property
  41. def name(self):
  42. return self._name
  43. @name.setter
  44. def name(self, value):
  45. self._name = value
  46. @property
  47. def type(self):
  48. return self._type
  49. @type.setter
  50. def type(self, value):
  51. self._type = value
  52. @property
  53. def logic(self):
  54. return self._logic
  55. @logic.setter
  56. def logic(self, value):
  57. self._logic = value
  58. @property
  59. def decision_strategy(self):
  60. return self._decision_strategy
  61. @decision_strategy.setter
  62. def decision_strategy(self, value):
  63. self._decision_strategy = value
  64. @property
  65. def resources(self):
  66. return self._resources
  67. @resources.setter
  68. def resources(self, value):
  69. self._resources = value
  70. @property
  71. def scopes(self):
  72. return self._scopes
  73. @scopes.setter
  74. def scopes(self, value):
  75. self._scopes = value