|
1 | 1 | from collections.abc import Mapping |
2 | | -from typing import Mapping as MappingType, Optional |
| 2 | +from typing import Mapping as MappingType |
3 | 3 | from typing import Sequence, Union |
4 | 4 |
|
5 | 5 | from .authorization import AuthorizationContext, Policy, Requirement |
@@ -64,36 +64,3 @@ def handle(self, context: AuthorizationContext): |
64 | 64 | else: |
65 | 65 | if all(identity.has_claim(name) for name in self.required_claims): |
66 | 66 | context.succeed(self) |
67 | | - |
68 | | - |
69 | | -class RolesRequirement(Requirement): |
70 | | - """ |
71 | | - Requires an identity with certain roles. |
72 | | - Supports defining sufficient roles (any one is enough), and required roles (all |
73 | | - must be present). |
74 | | - """ |
75 | | - |
76 | | - __slots__ = ("_roles", "_required_roles") |
77 | | - |
78 | | - def __init__( |
79 | | - self, |
80 | | - roles: Optional[Sequence[str]] = None, |
81 | | - required_roles: Optional[Sequence[str]] = None, |
82 | | - ): |
83 | | - self._required_roles = list(required_roles) if required_roles else None |
84 | | - self._roles = list(roles) if roles else None |
85 | | - |
86 | | - def handle(self, context: AuthorizationContext): |
87 | | - identity = context.identity |
88 | | - |
89 | | - if not identity: |
90 | | - context.fail("Missing identity") |
91 | | - return |
92 | | - |
93 | | - if self._roles: |
94 | | - if any(identity.has_role(name) for name in self._roles): |
95 | | - context.succeed(self) |
96 | | - |
97 | | - if self._required_roles: |
98 | | - if all(identity.has_role(name) for name in self._required_roles): |
99 | | - context.succeed(self) |
0 commit comments