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
@@ -414,13 +412,12 @@ def echo_attributes(request,
414412 config_loader_path = None ,
415413 template = 'djangosaml2/echo_attributes.html' ):
416414 """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 )
419416 conf = get_config (config_loader_path , request )
420417
421418 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 )
424421 try :
425422 identity = client .users .get_identity (subject_id ,
426423 check_not_on_or_after = False )
@@ -437,13 +434,12 @@ def logout(request, config_loader_path=None):
437434 This view initiates the SAML2 Logout request
438435 using the pysaml2 library to create the LogoutRequest.
439436 """
440- saml_session = get_saml_request_session (request )
441- state = StateCache (saml_session )
437+ state = StateCache (request .saml_session )
442438 conf = get_config (config_loader_path , request )
443439
444440 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 )
447443 if subject_id is None :
448444 logger .warning (
449445 '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
510506 logger .debug ('Logout service started' )
511507 conf = get_config (config_loader_path , request )
512508
513- saml_session = get_saml_request_session (request )
514- state = StateCache (saml_session )
509+ state = StateCache (request .saml_session )
515510 client = Saml2Client (conf , state_cache = state ,
516- identity_cache = IdentityCache (saml_session ))
511+ identity_cache = IdentityCache (request . saml_session ))
517512
518513 if 'SAMLResponse' in data : # we started the logout
519514 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
523518
524519 elif 'SAMLRequest' in data : # logout started by the IdP
525520 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 )
527522
528523 if subject_id is None :
529524 logger .warning (
0 commit comments