5353from .signals import post_authenticated
5454from .utils import (available_idps , fail_acs_response , get_custom_setting ,
5555 get_idp_sso_supported_bindings , get_location ,
56- validate_referral_url , get_saml_request_session )
56+ validate_referral_url )
5757
5858try :
5959 from django .contrib .auth .views import LogoutView
@@ -246,9 +246,8 @@ def login(request,
246246 else :
247247 raise UnsupportedBinding ('Unsupported binding: %s' , binding )
248248
249- saml_session = get_saml_request_session (request )
250249 # success, so save the session ID and return our response
251- oq_cache = OutstandingQueriesCache (saml_session )
250+ oq_cache = OutstandingQueriesCache (request . saml_session )
252251 oq_cache .set (session_id , came_from )
253252 logger .debug ('Saving the session_id "{}" in the OutstandingQueries cache' .format (oq_cache .__dict__ ))
254253 return http_response
@@ -290,9 +289,8 @@ def post(self,
290289 logger .warning ('Missing "SAMLResponse" parameter in POST data.' )
291290 raise SuspiciousOperation
292291
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 )
296294 oq_cache .sync ()
297295 outstanding_queries = oq_cache .outstanding_queries ()
298296
@@ -321,8 +319,8 @@ def post(self,
321319 logger .warning ("Missing Authentication Context from IdP." , exc_info = True )
322320 return fail_acs_response (request , exception = e )
323321 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!" )
326324 return fail_acs_response (request , exception = e )
327325 except UnsolicitedResponse as e :
328326 logger .exception ("Received SAMLResponse when no request has been made." )
@@ -354,7 +352,7 @@ def post(self,
354352 return fail_acs_response (request , exception = PermissionDenied ('No user could be authenticated.' ))
355353
356354 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' ])
358356 logger .debug ("User %s authenticated via SSO." , user )
359357 logger .debug ('Sending the post_authenticated signal' )
360358
@@ -437,13 +435,12 @@ def logout(request, config_loader_path=None):
437435 This view initiates the SAML2 Logout request
438436 using the pysaml2 library to create the LogoutRequest.
439437 """
440- saml_session = get_saml_request_session (request )
441- state = StateCache (saml_session )
438+ state = StateCache (request .saml_session )
442439 conf = get_config (config_loader_path , request )
443440
444441 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 )
447444 if subject_id is None :
448445 logger .warning (
449446 '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
510507 logger .debug ('Logout service started' )
511508 conf = get_config (config_loader_path , request )
512509
513- saml_session = get_saml_request_session (request )
514- state = StateCache (saml_session )
510+ state = StateCache (request .saml_session )
515511 client = Saml2Client (conf , state_cache = state ,
516- identity_cache = IdentityCache (saml_session ))
512+ identity_cache = IdentityCache (request . saml_session ))
517513
518514 if 'SAMLResponse' in data : # we started the logout
519515 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
523519
524520 elif 'SAMLRequest' in data : # logout started by the IdP
525521 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 )
527523
528524 if subject_id is None :
529525 logger .warning (
0 commit comments