|
2 | 2 |
|
3 | 3 | from .base import ResponseMicroService
|
4 | 4 | from ..exception import SATOSAAuthenticationError
|
5 |
| - |
6 |
| -def _filters(f, requester, provider): |
7 |
| - pf = f.get(provider, f.get("", f.get("default", {}))) |
8 |
| - rf = pf.get(requester, pf.get("", pf.get("default", {}))) |
9 |
| - return rf.items() |
| 5 | +from ..util import get_dict_defaults |
10 | 6 |
|
11 | 7 | class AttributeAuthorization(ResponseMicroService):
|
12 | 8 |
|
@@ -53,12 +49,12 @@ def __init__(self, config, *args, **kwargs):
|
53 | 49 | self.attribute_deny = config.get("attribute_deny", {})
|
54 | 50 |
|
55 | 51 | def _check_authz(self, context, attributes, requester, provider):
|
56 |
| - for attribute_name, attribute_filters in _filters(self.attribute_allow, requester, provider): |
| 52 | + for attribute_name, attribute_filters in get_dict_defaults(self.attribute_allow, requester, provider).items(): |
57 | 53 | if attribute_name in attributes:
|
58 | 54 | if not any([any(filter(re.compile(af).search, attributes[attribute_name])) for af in attribute_filters]):
|
59 | 55 | raise SATOSAAuthenticationError(context.state, "Permission denied")
|
60 | 56 |
|
61 |
| - for attribute_name, attribute_filters in _filters(self.attribute_deny, requester, provider): |
| 57 | + for attribute_name, attribute_filters in get_dict_defaults(self.attribute_deny, requester, provider).items(): |
62 | 58 | if attribute_name in attributes:
|
63 | 59 | if any([any(filter(re.compile(af).search, attributes[attribute_name])) for af in attribute_filters]):
|
64 | 60 | raise SATOSAAuthenticationError(context.state, "Permission denied")
|
|
0 commit comments