Skip to content

Commit 08bd514

Browse files
committed
fixed echo_Attributes template and null lenght of saml_attributes
1 parent 3a6fe8c commit 08bd514

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

djangosaml2/backends.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def _get_attribute_value(self, django_field: str, attributes: dict, attribute_ma
9494
logger.debug('attribute_mapping: %s', attribute_mapping)
9595
for saml_attr, django_fields in attribute_mapping.items():
9696
if django_field in django_fields and saml_attr in attributes:
97-
saml_attribute = attributes.get(saml_attr, [None])[0]
98-
if not saml_attribute:
97+
saml_attribute = attributes.get(saml_attr, [None])
98+
if not saml_attribute or not saml_attribute[0]:
9999
logger.error('attributes[saml_attr] attribute '
100100
'value is missing. Probably the user '
101101
'session is expired.')
102-
return saml_attribute
102+
return saml_attribute[0]
103103

104104
def authenticate(self, request, session_info=None, attribute_mapping=None, create_unknown_user=True, **kwargs):
105105
if session_info is None or attribute_mapping is None:

djangosaml2/views.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def get_next_path(self, request: HttpRequest) -> str:
124124
return next_path
125125

126126
def get(self, request, *args, **kwargs):
127-
logger.debug('Login process started')
128-
127+
logger.debug('Login process started')
129128
next_path = self.get_next_path(request)
130129

131130
# if the user is already authenticated that maybe because of two reasons:
@@ -320,7 +319,7 @@ def post(self, request, attribute_mapping=None, create_unknown_user=None):
320319
oq_cache = OutstandingQueriesCache(request.saml_session)
321320
oq_cache.sync()
322321
outstanding_queries = oq_cache.outstanding_queries()
323-
322+
324323
_exception = None
325324
try:
326325
response = client.parse_authn_request_response(request.POST['SAMLResponse'],
@@ -373,7 +372,7 @@ def post(self, request, attribute_mapping=None, create_unknown_user=None):
373372
attribute_mapping = attribute_mapping()
374373
if callable(create_unknown_user):
375374
create_unknown_user = create_unknown_user()
376-
375+
377376
logger.debug('Trying to authenticate the user. Session info: %s', session_info)
378377
user = auth.authenticate(request=request,
379378
session_info=session_info,

0 commit comments

Comments
 (0)