Skip to content

Commit fca05ae

Browse files
committed
Fixed IndexError at /saml2/acs/ when session is expired
1 parent b893d0f commit fca05ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

djangosaml2/backends.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def authenticate(self, request, session_info=None, attribute_mapping=None,
8989
else:
9090
logger.error('The nameid is not available. Cannot find user without a nameid.')
9191
else:
92-
saml_user = self.get_attribute_value(django_user_main_attribute, attributes, attribute_mapping)
92+
saml_user = self.get_attribute_value(django_user_main_attribute,
93+
attributes,
94+
attribute_mapping)
9395

9496
if saml_user is None:
9597
logger.error('Could not find saml_user value')
@@ -111,7 +113,11 @@ def get_attribute_value(self, django_field, attributes, attribute_mapping):
111113
logger.debug('attribute_mapping: %s', attribute_mapping)
112114
for saml_attr, django_fields in attribute_mapping.items():
113115
if django_field in django_fields and saml_attr in attributes:
114-
saml_user = attributes[saml_attr][0]
116+
saml_user = attributes.get('saml_attr', [None])[0]
117+
if not saml_user:
118+
logger.error('attributes[saml_attr] attribute '
119+
'value is missing. Probably the user '
120+
'session is expired.')
115121
return saml_user
116122

117123
def is_authorized(self, attributes, attribute_mapping):

0 commit comments

Comments
 (0)