Skip to content

Commit ce24c34

Browse files
committed
Add support for exposing IdP supported attributes
- Adds support for exposing IdP supported attributes in IDPSSODescriptor as Attribute elements. Support is added in the config file under service->idp->provided_attributes. provided_attributes alread existed as a valid option for idp config but was not used. Supported attributes MUST be published as Attribute elements in the metadata of the eIDAS IdP as stated in eIDAS SAML Message Format v.1.2 spec document - Adds error validation rule in eIDASIdPConfig to ensure provided_attributes MUST be set - Adds test to verify the provided_attributes are exposed as Attribute elements under IDPSSODescriptor and for the error validation rule
1 parent d544328 commit ce24c34

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

src/saml2/config.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ def warning_validators(self):
739739
def error_validators(self):
740740
idp_error_validators = {
741741
"want_authn_requests_signed MUST be set to True":
742-
getattr(self, "_idp_want_authn_requests_signed", None) is True
742+
getattr(self, "_idp_want_authn_requests_signed", None) is True,
743+
"provided_attributes MUST be set to denote the supported attributes by "
744+
"the IdP":
745+
not_empty(getattr(self, "_idp_provided_attributes", None))
743746
}
744747
return {**super().error_validators, **idp_error_validators}
745748

src/saml2/metadata.py

+8
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,14 @@ def do_idpsso_descriptor(conf, cert=None, enc_cert=None):
594594
except KeyError:
595595
setattr(idpsso, key, DEFAULTS[key])
596596

597+
attributes = [
598+
Attribute(name=attribute.get("name", None),
599+
name_format=attribute.get("name_format", None),
600+
friendly_name=attribute.get("friendly_name", None))
601+
for attribute in conf.getattr("provided_attributes", "idp")
602+
]
603+
idpsso.attribute = attributes
604+
597605
return idpsso
598606

599607

tests/eidas/eidas_idp_conf.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,22 @@
3838
"node_country": "GR",
3939
"application_identifier": "CEF:eIDAS-ref:2.0",
4040
"protocol_version": [1.1, 2.2],
41-
"want_authn_requests_signed": True
41+
"want_authn_requests_signed": True,
42+
"provided_attributes": [
43+
{
44+
"name": "http://eidas.europa.eu/attributes/naturalperson/PersonIdentifier",
45+
"friendly_name": "PersonIdentifier",
46+
"name_format": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
47+
},
48+
{
49+
"name": "http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName",
50+
"friendly_name": "FamilyName",
51+
},
52+
{
53+
"name": "http://eidas.europa.eu/attributes/naturalperson/CurrentGivenName",
54+
"name_format": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
55+
}
56+
],
4257
},
4358
},
4459
"debug": 1,

tests/eidas/test_idp.py

+19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ def test_protocol_version_in_metadata(self, config):
7878
assert {str(conf._idp_protocol_version)} \
7979
== set([x.text for x in protocol_version.attribute_value])
8080

81+
def test_supported_attributes(self, config):
82+
entd = metadata.entity_descriptor(self.conf)
83+
attributes_published = [
84+
set(
85+
filter(lambda x: x is not None,
86+
[attribute.name, attribute.name_format, attribute.friendly_name]
87+
)
88+
)
89+
for attribute in entd.idpsso_descriptor.attribute
90+
]
91+
attributes_stated = [set(x.values()) for x
92+
in self.conf._idp_provided_attributes]
93+
assert attributes_published == attributes_stated
94+
8195

8296
class TestIdPConfig:
8397
@staticmethod
@@ -250,3 +264,8 @@ def test_want_authn_requests_signed_false(self, config):
250264
config["service"]["idp"]["want_authn_requests_signed"] = False
251265

252266
self.assert_validation_error(config)
267+
268+
def test_provided_attributes_unset(self, config):
269+
del config["service"]["idp"]["provided_attributes"]
270+
271+
self.assert_validation_error(config)

0 commit comments

Comments
 (0)