Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from mavericm1/django-backend-fix
Browse files Browse the repository at this point in the history
removed utf8 encoding and exception message
  • Loading branch information
crisidev committed Jul 31, 2023
2 parents b12a6ab + cde88d7 commit 0107fb7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/django-backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# TACACSPLUS_AUTH_PROTOCOL = 'ascii'
#

class TACACSPlusBackend(object):
class TACACSPlusBackend:
'''
Custom TACACS+ auth backend for Django
'''
Expand All @@ -31,21 +31,21 @@ def _get_or_set_user(self, username, password):
logger.debug("Created TACACS+ user %s" % (username,))
return user

def authenticate(self, username, password):
def authenticate(self, request, username=None, password=None):
if not settings.TACACSPLUS_HOST:
return None
try:
auth = TACACSClient(
settings.TACACSPLUS_HOST.encode('utf-8'),
settings.TACACSPLUS_HOST,
settings.TACACSPLUS_PORT,
settings.TACACSPLUS_SECRET.encode('utf-8'),
settings.TACACSPLUS_SECRET,
timeout=settings.TACACSPLUS_SESSION_TIMEOUT,
).authenticate(
username.encode('utf-8'), password.encode('utf-8'),
username, password,
TAC_PLUS_AUTHEN_TYPES[settings.TACACSPLUS_AUTH_PROTOCOL],
)
except Exception as e:
logger.exception("TACACS+ Authentication Error: %s" % (e.message,))
logger.exception("TACACS+ Authentication Error: %s" % (e,))
return None
if auth.valid:
return self._get_or_set_user(username, password)
Expand All @@ -59,4 +59,4 @@ def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
return None

0 comments on commit 0107fb7

Please sign in to comment.