Skip to content

Commit 20ceeb9

Browse files
author
Roland Hedberg
committed
Refactored and improved attribute consumer service metadata construction.
1 parent 5e4ea50 commit 20ceeb9

File tree

1 file changed

+53
-39
lines changed

1 file changed

+53
-39
lines changed

src/saml2/metadata.py

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,58 @@ def do_endpoints(conf, endpoints):
435435
}
436436

437437

438+
def do_attribute_consuming_service(conf, spsso):
439+
440+
service_description = service_name = None
441+
requested_attributes = []
442+
acs = conf.attribute_converters
443+
req = conf.getattr("required_attributes", "sp")
444+
if req:
445+
requested_attributes.extend(do_requested_attribute(req, acs,
446+
is_required="true"))
447+
448+
opt = conf.getattr("optional_attributes", "sp")
449+
450+
if opt:
451+
requested_attributes.extend(do_requested_attribute(opt, acs))
452+
453+
try:
454+
if conf.description:
455+
try:
456+
(text, lang) = conf.description
457+
except ValueError:
458+
text = conf.description
459+
lang = "en"
460+
service_description = [md.ServiceDescription(text=text, lang=lang)]
461+
except KeyError:
462+
pass
463+
464+
try:
465+
if conf.name:
466+
try:
467+
(text, lang) = conf.name
468+
except ValueError:
469+
text = conf.name
470+
lang = "en"
471+
service_name = [md.ServiceName(text=text, lang=lang)]
472+
except KeyError:
473+
pass
474+
475+
# Must be both requested attributes and service name
476+
if requested_attributes:
477+
if not service_name:
478+
service_name = [md.ServiceName(text="", lang="en")]
479+
480+
ac_serv = md.AttributeConsumingService(
481+
index="1", service_name=service_name,
482+
requested_attribute=requested_attributes)
483+
484+
if service_description:
485+
ac_serv.service_description = service_description
486+
487+
spsso.attribute_consuming_service = [ac_serv]
488+
489+
438490
def do_spsso_descriptor(conf, cert=None):
439491
spsso = md.SPSSODescriptor()
440492
spsso.protocol_support_enumeration = samlp.NAMESPACE
@@ -479,46 +531,8 @@ def do_spsso_descriptor(conf, cert=None):
479531
except KeyError:
480532
setattr(spsso, key, DEFAULTS[key])
481533

482-
requested_attributes = []
483-
acs = conf.attribute_converters
484-
req = conf.getattr("required_attributes", "sp")
485-
if req:
486-
requested_attributes.extend(do_requested_attribute(req, acs,
487-
is_required="true"))
488-
534+
do_attribute_consuming_service(conf, spsso)
489535
_do_nameid_format(spsso, conf, "sp")
490-
491-
opt = conf.getattr("optional_attributes", "sp")
492-
493-
if opt:
494-
requested_attributes.extend(do_requested_attribute(opt, acs))
495-
496-
if requested_attributes:
497-
# endpoints that might publish requested attributes
498-
if spsso.attribute_consuming_service:
499-
for acs in spsso.attribute_consuming_service:
500-
if not acs.requested_attribute:
501-
acs.requested_attribute = requested_attributes
502-
else:
503-
spsso.attribute_consuming_service = [md.AttributeConsumingService(
504-
requested_attribute=requested_attributes,
505-
service_name=[md.ServiceName(lang="en", text=conf.name)],
506-
index="1",
507-
)]
508-
509-
# try:
510-
# if conf.description:
511-
# try:
512-
# (text, lang) = conf.description
513-
# except ValueError:
514-
# text = conf.description
515-
# lang = "en"
516-
# spsso.attribute_consuming_service[0].service_description = [
517-
# md.ServiceDescription(text=text,
518-
# lang=lang)]
519-
# except KeyError:
520-
# pass
521-
522536
return spsso
523537

524538

0 commit comments

Comments
 (0)