Skip to content

Commit 0e5afd4

Browse files
Merge pull request #99 from leifj/attribute-filter-config
enable defaults for custom attribute release using '' or 'default' key
2 parents 085a547 + f5622e1 commit 0e5afd4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

doc/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ config:
242242
idp-entity-id1
243243
sp-entity-id1:
244244
exclude: ["givenName"]
245+
246+
247+
The custom_attribute_release mechanism supports defaults based on idp and sp entity Id by specifying "" or "default"
248+
as the key in the dict. For instance in order to exclude givenName for any sp or idp do this:
249+
250+
```yaml
251+
config:
252+
config: [...]
253+
custom_attribute_release:
254+
"default":
255+
"":
256+
exclude: ["givenName"]
245257

246258

247259
#### Backend

src/satosa/frontends/saml2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ..response import Response
2222
from ..response import ServiceError
2323
from ..saml_util import make_saml_response
24+
from ..util import get_dict_defaults
2425

2526
logger = logging.getLogger(__name__)
2627

@@ -274,8 +275,7 @@ def _handle_authn_response(self, context, internal_response, idp):
274275
auth_info["authn_auth"] = internal_response.auth_info.issuer
275276

276277
if self.custom_attribute_release:
277-
custom_release_per_idp = self.custom_attribute_release.get(internal_response.auth_info.issuer, {})
278-
custom_release = custom_release_per_idp.get(resp_args["sp_entity_id"], {})
278+
custom_release = get_dict_defaults(self.custom_attribute_release, internal_response.auth_info.issuer, resp_args["sp_entity_id"])
279279
attributes_to_remove = custom_release.get("exclude", [])
280280
for k in attributes_to_remove:
281281
ava.pop(k, None)

src/satosa/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
logger = logging.getLogger(__name__)
99

10+
def get_dict_defaults(d, *keys):
11+
for key in keys:
12+
d = d.get(key, d.get("", d.get("default", {})))
13+
return d
1014

1115
def rndstr(size=16, alphabet=""):
1216
"""

0 commit comments

Comments
 (0)