53
53
from .signals import post_authenticated
54
54
from .utils import (available_idps , fail_acs_response , get_custom_setting ,
55
55
get_idp_sso_supported_bindings , get_location ,
56
- validate_referral_url , get_saml_request_session )
56
+ validate_referral_url )
57
57
58
58
try :
59
59
from django .contrib .auth .views import LogoutView
@@ -246,9 +246,8 @@ def login(request,
246
246
else :
247
247
raise UnsupportedBinding ('Unsupported binding: %s' , binding )
248
248
249
- saml_session = get_saml_request_session (request )
250
249
# success, so save the session ID and return our response
251
- oq_cache = OutstandingQueriesCache (saml_session )
250
+ oq_cache = OutstandingQueriesCache (request . saml_session )
252
251
oq_cache .set (session_id , came_from )
253
252
logger .debug ('Saving the session_id "{}" in the OutstandingQueries cache' .format (oq_cache .__dict__ ))
254
253
return http_response
@@ -290,9 +289,8 @@ def post(self,
290
289
logger .warning ('Missing "SAMLResponse" parameter in POST data.' )
291
290
raise SuspiciousOperation
292
291
293
- saml_session = get_saml_request_session (request )
294
- client = Saml2Client (conf , identity_cache = IdentityCache (saml_session ))
295
- oq_cache = OutstandingQueriesCache (saml_session )
292
+ client = Saml2Client (conf , identity_cache = IdentityCache (request .saml_session ))
293
+ oq_cache = OutstandingQueriesCache (request .saml_session )
296
294
oq_cache .sync ()
297
295
outstanding_queries = oq_cache .outstanding_queries ()
298
296
@@ -321,8 +319,8 @@ def post(self,
321
319
logger .warning ("Missing Authentication Context from IdP." , exc_info = True )
322
320
return fail_acs_response (request , exception = e )
323
321
except MissingKey as e :
324
- logger .exception ("SAML Identity Provider is not configured "
325
- "correctly: certificate key is missing!" )
322
+ logger .exception ("SAML Identity Provider is not configured correctly: "
323
+ "certificate key is missing!" )
326
324
return fail_acs_response (request , exception = e )
327
325
except UnsolicitedResponse as e :
328
326
logger .exception ("Received SAMLResponse when no request has been made." )
@@ -354,7 +352,7 @@ def post(self,
354
352
return fail_acs_response (request , exception = PermissionDenied ('No user could be authenticated.' ))
355
353
356
354
auth .login (self .request , user )
357
- _set_subject_id (saml_session , session_info ['name_id' ])
355
+ _set_subject_id (request . saml_session , session_info ['name_id' ])
358
356
logger .debug ("User %s authenticated via SSO." , user )
359
357
logger .debug ('Sending the post_authenticated signal' )
360
358
@@ -414,13 +412,12 @@ def echo_attributes(request,
414
412
config_loader_path = None ,
415
413
template = 'djangosaml2/echo_attributes.html' ):
416
414
"""Example view that echo the SAML attributes of an user"""
417
- saml_session = get_saml_request_session (request )
418
- state = StateCache (saml_session )
415
+ state = StateCache (request .saml_session )
419
416
conf = get_config (config_loader_path , request )
420
417
421
418
client = Saml2Client (conf , state_cache = state ,
422
- identity_cache = IdentityCache (saml_session ))
423
- subject_id = _get_subject_id (saml_session )
419
+ identity_cache = IdentityCache (request . saml_session ))
420
+ subject_id = _get_subject_id (request . saml_session )
424
421
try :
425
422
identity = client .users .get_identity (subject_id ,
426
423
check_not_on_or_after = False )
@@ -437,13 +434,12 @@ def logout(request, config_loader_path=None):
437
434
This view initiates the SAML2 Logout request
438
435
using the pysaml2 library to create the LogoutRequest.
439
436
"""
440
- saml_session = get_saml_request_session (request )
441
- state = StateCache (saml_session )
437
+ state = StateCache (request .saml_session )
442
438
conf = get_config (config_loader_path , request )
443
439
444
440
client = Saml2Client (conf , state_cache = state ,
445
- identity_cache = IdentityCache (saml_session ))
446
- subject_id = _get_subject_id (saml_session )
441
+ identity_cache = IdentityCache (request . saml_session ))
442
+ subject_id = _get_subject_id (request . saml_session )
447
443
if subject_id is None :
448
444
logger .warning (
449
445
'The session does not contain the subject id for user %s' ,
@@ -510,10 +506,9 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
510
506
logger .debug ('Logout service started' )
511
507
conf = get_config (config_loader_path , request )
512
508
513
- saml_session = get_saml_request_session (request )
514
- state = StateCache (saml_session )
509
+ state = StateCache (request .saml_session )
515
510
client = Saml2Client (conf , state_cache = state ,
516
- identity_cache = IdentityCache (saml_session ))
511
+ identity_cache = IdentityCache (request . saml_session ))
517
512
518
513
if 'SAMLResponse' in data : # we started the logout
519
514
logger .debug ('Receiving a logout response from the IdP' )
@@ -523,7 +518,7 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
523
518
524
519
elif 'SAMLRequest' in data : # logout started by the IdP
525
520
logger .debug ('Receiving a logout request from the IdP' )
526
- subject_id = _get_subject_id (saml_session )
521
+ subject_id = _get_subject_id (request . saml_session )
527
522
528
523
if subject_id is None :
529
524
logger .warning (
0 commit comments