1212
1313from saml2 .entity import Entity
1414
15- import saml2 .attributemaps as attributemaps
16-
1715from saml2 .mdstore import destinations
1816from saml2 .profile import paos , ecp
1917from saml2 .saml import NAMEID_FORMAT_TRANSIENT
2422from saml2 .samlp import AuthnRequest
2523from saml2 .samlp import Extensions
2624from saml2 .extension import sp_type
27- from saml2 .extension import requested_attributes
25+ from saml2 .extension .requested_attributes import RequestedAttribute
26+ from saml2 .extension .requested_attributes import RequestedAttributes
2827
2928import saml2
3029from saml2 .soap import make_soap_enveloped_saml_thingy
@@ -235,7 +234,7 @@ def create_authn_request(self, destination, vorg="", scoping=None,
235234 service_url_binding = None , message_id = 0 ,
236235 consent = None , extensions = None , sign = None ,
237236 allow_create = None , sign_prepare = False , sign_alg = None ,
238- digest_alg = None , ** kwargs ):
237+ digest_alg = None , requested_attributes = None , ** kwargs ):
239238 """ Creates an authentication request.
240239
241240 :param destination: Where the request should be sent.
@@ -253,6 +252,9 @@ def create_authn_request(self, destination, vorg="", scoping=None,
253252 :param allow_create: If the identity provider is allowed, in the course
254253 of fulfilling the request, to create a new identifier to represent
255254 the principal.
255+ :param requested_attributes: A list of dicts which contain attributes
256+ to be appended to the requested_attributes config option. The
257+ dicts format is similar to the requested_attributes config option.
256258 :param kwargs: Extra key word arguments
257259 :return: either a tuple of request ID and <samlp:AuthnRequest> instance
258260 or a tuple of request ID and str when sign is set to True
@@ -379,17 +381,19 @@ def create_authn_request(self, destination, vorg="", scoping=None,
379381 item = sp_type .SPType (text = conf_sp_type )
380382 extensions .add_extension_element (item )
381383
382- requested_attrs = self .config .getattr ('requested_attributes' , 'sp' )
383- if requested_attrs :
384+ if requested_attributes :
385+ requested_attributes += \
386+ self .config .getattr ('requested_attributes' , 'sp' )
387+ else :
388+ requested_attributes = \
389+ self .config .getattr ('requested_attributes' , 'sp' )
390+
391+ if requested_attributes :
384392 if not extensions :
385393 extensions = Extensions ()
386394
387- attributemapsmods = []
388- for modname in attributemaps .__all__ :
389- attributemapsmods .append (getattr (attributemaps , modname ))
390-
391395 items = []
392- for attr in requested_attrs :
396+ for attr in requested_attributes :
393397 friendly_name = attr .get ('friendly_name' )
394398 name = attr .get ('name' )
395399 name_format = attr .get ('name_format' )
@@ -401,34 +405,34 @@ def create_authn_request(self, destination, vorg="", scoping=None,
401405 'name' , 'friendly_name' ))
402406
403407 if not name :
404- for mod in attributemapsmods :
408+ for converter in self . config . attribute_converters :
405409 try :
406- name = mod . MAP [ 'to' ][ friendly_name ]
410+ name = converter . _to [ friendly_name . lower () ]
407411 except KeyError :
408412 continue
409413 else :
410414 if not name_format :
411- name_format = mod . MAP [ 'identifier' ]
415+ name_format = converter . name_format
412416 break
413417
414418 if not friendly_name :
415- for mod in attributemapsmods :
419+ for converter in self . config . attribute_converters :
416420 try :
417- friendly_name = mod . MAP [ 'fro' ][ name ]
421+ friendly_name = converter . _fro [ name . lower () ]
418422 except KeyError :
419423 continue
420424 else :
421425 if not name_format :
422- name_format = mod . MAP [ 'identifier' ]
426+ name_format = converter . name_format
423427 break
424428
425- items .append (requested_attributes . RequestedAttribute (
429+ items .append (RequestedAttribute (
426430 is_required = is_required ,
427431 name_format = name_format ,
428432 friendly_name = friendly_name ,
429433 name = name ))
430434
431- item = requested_attributes . RequestedAttributes (
435+ item = RequestedAttributes (
432436 extension_elements = items )
433437 extensions .add_extension_element (item )
434438
0 commit comments