Skip to content

Commit 3ddbb1a

Browse files
author
Roland Hedberg
committed
Allow name_format for requested attributes to be set in the configuration.
1 parent 2be0571 commit 3ddbb1a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/saml2/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
from saml2.saml import NAME_FORMAT_URI
23

34
__author__ = 'rolandh'
45

@@ -93,6 +94,7 @@
9394
"ecp",
9495
"name_id_format",
9596
"logout_requests_signed",
97+
"requested_attribute_name_format"
9698
]
9799

98100
AA_IDP_ARGS = [
@@ -236,6 +238,7 @@ def __init__(self, homedir="."):
236238
self.extensions = {}
237239
self.attribute = []
238240
self.attribute_profile = []
241+
self.requested_attribute_name_format = NAME_FORMAT_URI
239242

240243
def setattr(self, context, attr, val):
241244
if context == "":

src/saml2/metadata.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,19 @@ def do_key_descriptor(cert=None, enc_cert=None, use="both"):
239239
return kd_list
240240

241241

242-
def do_requested_attribute(attributes, acs, is_required="false"):
242+
def do_requested_attribute(attributes, acs, is_required="false",
243+
name_format=NAME_FORMAT_URI):
243244
lista = []
244245
for attr in attributes:
245-
attr = from_local_name(acs, attr, NAME_FORMAT_URI)
246+
attr = from_local_name(acs, attr, name_format)
246247
args = {}
247-
for key in attr.keyswv():
248-
args[key] = getattr(attr, key)
248+
if isinstance(attr, six.string_types):
249+
args["name"] = attr
250+
else:
251+
for key in attr.keyswv():
252+
args[key] = getattr(attr, key)
249253
args["is_required"] = is_required
250-
args["name_format"] = NAME_FORMAT_URI
254+
args["name_format"] = name_format
251255
lista.append(md.RequestedAttribute(**args))
252256
return lista
253257

@@ -465,14 +469,21 @@ def do_attribute_consuming_service(conf, spsso):
465469
requested_attributes = []
466470
acs = conf.attribute_converters
467471
req = conf.getattr("required_attributes", "sp")
472+
473+
req_attr_name_format = conf.getattr("requested_attribute_name_format", "sp")
474+
if req_attr_name_format is None:
475+
req_attr_name_format = conf.requested_attribute_name_format
476+
468477
if req:
469-
requested_attributes.extend(do_requested_attribute(req, acs,
470-
is_required="true"))
478+
requested_attributes.extend(
479+
do_requested_attribute(req, acs, is_required="true",
480+
name_format=req_attr_name_format))
471481

472482
opt = conf.getattr("optional_attributes", "sp")
473483

474484
if opt:
475-
requested_attributes.extend(do_requested_attribute(opt, acs))
485+
requested_attributes.extend(
486+
do_requested_attribute(opt, acs, name_format=req_attr_name_format))
476487

477488
try:
478489
if conf.description:

0 commit comments

Comments
 (0)