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
@@ -437,13 +435,12 @@ def logout(request, config_loader_path=None):
437
435
This view initiates the SAML2 Logout request
438
436
using the pysaml2 library to create the LogoutRequest.
439
437
"""
440
- saml_session = get_saml_request_session (request )
441
- state = StateCache (saml_session )
438
+ state = StateCache (request .saml_session )
442
439
conf = get_config (config_loader_path , request )
443
440
444
441
client = Saml2Client (conf , state_cache = state ,
445
- identity_cache = IdentityCache (saml_session ))
446
- subject_id = _get_subject_id (saml_session )
442
+ identity_cache = IdentityCache (request . saml_session ))
443
+ subject_id = _get_subject_id (request . saml_session )
447
444
if subject_id is None :
448
445
logger .warning (
449
446
'The session does not contain the subject id for user %s' ,
@@ -510,10 +507,9 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
510
507
logger .debug ('Logout service started' )
511
508
conf = get_config (config_loader_path , request )
512
509
513
- saml_session = get_saml_request_session (request )
514
- state = StateCache (saml_session )
510
+ state = StateCache (request .saml_session )
515
511
client = Saml2Client (conf , state_cache = state ,
516
- identity_cache = IdentityCache (saml_session ))
512
+ identity_cache = IdentityCache (request . saml_session ))
517
513
518
514
if 'SAMLResponse' in data : # we started the logout
519
515
logger .debug ('Receiving a logout response from the IdP' )
@@ -523,7 +519,7 @@ def do_logout_service(request, data, binding, config_loader_path=None, next_page
523
519
524
520
elif 'SAMLRequest' in data : # logout started by the IdP
525
521
logger .debug ('Receiving a logout request from the IdP' )
526
- subject_id = _get_subject_id (saml_session )
522
+ subject_id = _get_subject_id (request . saml_session )
527
523
528
524
if subject_id is None :
529
525
logger .warning (
0 commit comments