Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion irods/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
import irods.session


__all__ = ["pam_interactive", "pam_password", "native"]
__all__ = ["pam_interactive", "pam_password", "native", "irods_scheme"]

Check failure on line 10 in irods/auth/__init__.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undefined-export

undefined-export: Undefined name `irods_scheme` in `__all__` [check:undefined-export]

Check failure on line 10 in irods/auth/__init__.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undefined-export

undefined-export: Undefined name `native` in `__all__` [check:undefined-export]

Check failure on line 10 in irods/auth/__init__.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undefined-export

undefined-export: Undefined name `pam_password` in `__all__` [check:undefined-export]

Check failure on line 10 in irods/auth/__init__.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undefined-export

undefined-export: Undefined name `pam_interactive` in `__all__` [check:undefined-export]

Check failure on line 10 in irods/auth/__init__.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff unsorted-dunder-all

unsorted-dunder-all: `__all__` is not sorted [check:unsorted-dunder-all]


# Schemes whose plugin module is not named after the scheme
# The `irods` scheme file (irods.py) would clash with the package name `irods`
# when irods.py get loaded into globals at runtime.
_PLUGIN_MODULE_FOR_SCHEME = {"irods": "irods_scheme"}


def plugin_module_name(scheme):
return _PLUGIN_MODULE_FOR_SCHEME.get(scheme, scheme)


AUTH_PLUGIN_PACKAGE = "irods.auth"
Expand Down
64 changes: 64 additions & 0 deletions irods/auth/irods_scheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import ssl

Check failure on line 1 in irods/auth/irods_scheme.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undocumented-public-module

undocumented-public-module: Missing docstring in public module [check:undocumented-public-module]

from . import (
__NEXT_OPERATION__,
CLIENT_GET_REQUEST_RESULT,
_auth_api_request,
authentication_base,
)
from .pam_password import ENSURE_SSL_IS_ACTIVE

_scheme = "irods"


def login(conn, **extra_opt):

Check failure on line 14 in irods/auth/irods_scheme.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff undocumented-public-function

undocumented-public-function: Missing docstring in public function [check:undocumented-public-function]
request = {
"user_name": conn.account.proxy_user,
"zone_name": conn.account.proxy_zone
}

Check failure on line 18 in irods/auth/irods_scheme.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-format

Ruff format

Improper formatting
request.update(extra_opt)
_irods_ClientAuthState(conn, scheme=_scheme).authenticate_client(initial_request=request)


class _irods_ClientAuthState(authentication_base):

Check failure on line 23 in irods/auth/irods_scheme.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff invalid-class-name

invalid-class-name: Class name `_irods_ClientAuthState` should use CapWords convention [check:invalid-class-name]
def auth_client_start(self, request):
self._token_result = request.pop(CLIENT_GET_REQUEST_RESULT, None)

if request.pop(ENSURE_SSL_IS_ACTIVE, True) and not isinstance(self.conn.socket, ssl.SSLSocket):
msg = "irods auth scheme requires secure communications (TLS/SSL) with the server."
raise RuntimeError(msg)

resp = request.copy()
resp[__NEXT_OPERATION__] = "client_init_auth_with_server"
return resp

def client_init_auth_with_server(self, request):
server_req = request.copy()
server_req[__NEXT_OPERATION__] = "server_prepare_auth_check"
resp = _auth_api_request(self.conn, server_req)

# set with set_auth_option_for_scheme("irods", "session_token", ...)
if "session_token" in resp:
resp[__NEXT_OPERATION__] = "client_auth_with_session_token"
else:
resp["password"] = self.conn.account.password or ""
resp[__NEXT_OPERATION__] = "client_auth_with_password"
return resp

def client_auth_with_password(self, request):
server_req = request.copy()
server_req[__NEXT_OPERATION__] = "server_auth_with_password"
resp = _auth_api_request(self.conn, server_req)

if isinstance(self._token_result, list):
self._token_result[:] = (resp["session_token"],)

resp[__NEXT_OPERATION__] = "client_auth_with_session_token"
return resp

def client_auth_with_session_token(self, request):
server_req = request.copy()
server_req[__NEXT_OPERATION__] = "server_auth_with_session_token"
resp = _auth_api_request(self.conn, server_req)
self.loggedIn = 1
return resp
5 changes: 3 additions & 2 deletions irods/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ def __init__(self, pool, account):

auth_module = None
# use client side "plugin" module: irods.auth.<scheme>
irods.auth.load_plugins(subset=[scheme])
auth_module = getattr(irods.auth, scheme, None)
module_name = irods.auth.plugin_module_name(scheme)
irods.auth.load_plugins(subset=[module_name])
auth_module = getattr(irods.auth, module_name, None)
if auth_module:
auth_module.login(self, **self.auth_options)
auth_type = auth_module.__name__
Expand Down
4 changes: 4 additions & 0 deletions irods/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ class SYS_NOT_ALLOWED(iRODSException):
code = -169000


class AUTHENTICATION_ERROR(iRODSException):
code = -178000


class UserInputException(iRODSException):
pass

Expand Down
Loading