Skip to content

Commit

Permalink
#135: Allow session IDs to not be overwritten in the database
Browse files Browse the repository at this point in the history
- This is done by creating a new client object each time users login. If the same object is used for every login, the session ID will just be overwritten, even if logging in as a different user
  • Loading branch information
MRichards99 committed Jul 13, 2020
1 parent 851166c commit 5195edb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions common/python_icat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ class PythonICATBackend(Backend):
"""

def __init__(self):
icat_server_url = config.get_icat_url()
self.client = icat.client.Client(icat_server_url, checkCert=config.get_icat_check_cert())
# Client object is created here as well as in login() to avoid uncaught exceptions
# where the object is None. This could happen where a user tries to use an endpoint before
# logging in. Also helps to give a bit of certainty to what's stored here
self.client = icat.client.Client(config.get_icat_url(), checkCert=config.get_icat_check_cert())

def login(self, credentials):
# Client object is re-created here so session IDs aren't overwritten in the database
self.client = icat.client.Client(config.get_icat_url(), checkCert=config.get_icat_check_cert())

# Syntax for Python ICAT
login_details = {'username': credentials['username'], 'password': credentials['password']}

try:
session_id = self.client.login(credentials["mechanism"], login_details)
return session_id
Expand Down

0 comments on commit 5195edb

Please sign in to comment.