Skip to content

Commit 000b3ec

Browse files
d-w-moorealanking
authored andcommitted
[#290] only anonymous user can log in without password
Logins without a password (ie. when password='', or when the secrets file ".irodsA" is missing from the irods environment) should only be allowed for the anonymous user. The need for this fix was discovered when the demonstration script at: #315 (comment) ceased to trip the issue at hand (#315) when rebased to follow commit: 91b1ada ( [#290] allow skipping of password file in anonymous user case ) Note that prior to the two #290 related commits (ie. this and the above- mentioned one), instantiating an iRODSSession object from the user's client environment without the secrets file present would raise a FileNotFoundError. As of this change, attempts by any other user than `anonymous' to log in without auth credentials will instead raise an Exception of type: `NonAnonymousLoginWithoutPassword'
1 parent a887220 commit 000b3ec

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

irods/session.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
logger = logging.getLogger(__name__)
2121

22+
class NonAnonymousLoginWithoutPassword(RuntimeError): pass
23+
2224
class iRODSSession(object):
2325

2426
@property
@@ -113,7 +115,13 @@ def _configure_account(self, **kwargs):
113115
except KeyError:
114116
pass
115117

116-
creds['password'] = self.get_irods_password(session_ = self, **creds)
118+
missing_file_path = []
119+
error_args = []
120+
pw = creds['password'] = self.get_irods_password(session_ = self, file_path_if_not_found = missing_file_path, **creds)
121+
if not pw and creds.get('irods_user_name') != 'anonymous':
122+
if missing_file_path:
123+
error_args += ["Authentication file not found at {!r}".format(missing_file_path[0])]
124+
raise NonAnonymousLoginWithoutPassword(*error_args)
117125

118126
return iRODSAccount(**creds)
119127

@@ -201,7 +209,8 @@ def get_irods_env(env_file, session_ = None):
201209
return {}
202210

203211
@staticmethod
204-
def get_irods_password(session_ = None, **kwargs):
212+
def get_irods_password(session_ = None, file_path_if_not_found = (), **kwargs):
213+
path_memo = []
205214
try:
206215
irods_auth_file = kwargs['irods_authentication_file']
207216
except KeyError:
@@ -219,9 +228,13 @@ def get_irods_password(session_ = None, **kwargs):
219228
_retval = decode(f.read().rstrip('\n'), uid)
220229
return _retval
221230
except IOError as exc:
222-
if exc.errno != errno.ENOENT: raise # Auth file exists but can't be read
231+
if exc.errno != errno.ENOENT:
232+
raise # Auth file exists but can't be read
233+
path_memo = [ irods_auth_file ]
223234
return '' # No auth file (as with anonymous user)
224235
finally:
236+
if isinstance(file_path_if_not_found, list) and path_memo:
237+
file_path_if_not_found[:] = path_memo
225238
if session_ is not None and _retval:
226239
session_._auth_file = irods_auth_file
227240

0 commit comments

Comments
 (0)