12
12
13
13
from saml2 .entity import Entity
14
14
15
- import saml2 .attributemaps as attributemaps
16
-
17
15
from saml2 .mdstore import destinations
18
16
from saml2 .profile import paos , ecp
19
17
from saml2 .saml import NAMEID_FORMAT_TRANSIENT
24
22
from saml2 .samlp import AuthnRequest
25
23
from saml2 .samlp import Extensions
26
24
from 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
28
27
29
28
import saml2
30
29
from saml2 .soap import make_soap_enveloped_saml_thingy
@@ -235,7 +234,7 @@ def create_authn_request(self, destination, vorg="", scoping=None,
235
234
service_url_binding = None , message_id = 0 ,
236
235
consent = None , extensions = None , sign = None ,
237
236
allow_create = None , sign_prepare = False , sign_alg = None ,
238
- digest_alg = None , ** kwargs ):
237
+ digest_alg = None , requested_attributes = None , ** kwargs ):
239
238
""" Creates an authentication request.
240
239
241
240
:param destination: Where the request should be sent.
@@ -253,6 +252,9 @@ def create_authn_request(self, destination, vorg="", scoping=None,
253
252
:param allow_create: If the identity provider is allowed, in the course
254
253
of fulfilling the request, to create a new identifier to represent
255
254
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.
256
258
:param kwargs: Extra key word arguments
257
259
:return: either a tuple of request ID and <samlp:AuthnRequest> instance
258
260
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,
379
381
item = sp_type .SPType (text = conf_sp_type )
380
382
extensions .add_extension_element (item )
381
383
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 :
384
392
if not extensions :
385
393
extensions = Extensions ()
386
394
387
- attributemapsmods = []
388
- for modname in attributemaps .__all__ :
389
- attributemapsmods .append (getattr (attributemaps , modname ))
390
-
391
395
items = []
392
- for attr in requested_attrs :
396
+ for attr in requested_attributes :
393
397
friendly_name = attr .get ('friendly_name' )
394
398
name = attr .get ('name' )
395
399
name_format = attr .get ('name_format' )
@@ -401,34 +405,34 @@ def create_authn_request(self, destination, vorg="", scoping=None,
401
405
'name' , 'friendly_name' ))
402
406
403
407
if not name :
404
- for mod in attributemapsmods :
408
+ for converter in self . config . attribute_converters :
405
409
try :
406
- name = mod . MAP [ 'to' ][ friendly_name ]
410
+ name = converter . _to [ friendly_name . lower () ]
407
411
except KeyError :
408
412
continue
409
413
else :
410
414
if not name_format :
411
- name_format = mod . MAP [ 'identifier' ]
415
+ name_format = converter . name_format
412
416
break
413
417
414
418
if not friendly_name :
415
- for mod in attributemapsmods :
419
+ for converter in self . config . attribute_converters :
416
420
try :
417
- friendly_name = mod . MAP [ 'fro' ][ name ]
421
+ friendly_name = converter . _fro [ name . lower () ]
418
422
except KeyError :
419
423
continue
420
424
else :
421
425
if not name_format :
422
- name_format = mod . MAP [ 'identifier' ]
426
+ name_format = converter . name_format
423
427
break
424
428
425
- items .append (requested_attributes . RequestedAttribute (
429
+ items .append (RequestedAttribute (
426
430
is_required = is_required ,
427
431
name_format = name_format ,
428
432
friendly_name = friendly_name ,
429
433
name = name ))
430
434
431
- item = requested_attributes . RequestedAttributes (
435
+ item = RequestedAttributes (
432
436
extension_elements = items )
433
437
extensions .add_extension_element (item )
434
438
0 commit comments