diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index cdae9f65c..c012b6671 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -807,6 +807,12 @@ providers like ldap, kerberos Default: `False` +##### strip_domain + +Strip domain from username + +Default: `False` + #### rights ##### type diff --git a/config b/config index 114820add..a9fe9da71 100644 --- a/config +++ b/config @@ -73,6 +73,8 @@ # Convert username to lowercase, must be true for case-insensitive auth providers #lc_username = False +# Strip domain name from username +#strip_domain = False [rights] diff --git a/radicale/auth/__init__.py b/radicale/auth/__init__.py index 15d91ec5f..296dbfa84 100644 --- a/radicale/auth/__init__.py +++ b/radicale/auth/__init__.py @@ -52,6 +52,7 @@ def load(configuration: "config.Configuration") -> "BaseAuth": class BaseAuth: _lc_username: bool + _strip_domain: bool def __init__(self, configuration: "config.Configuration") -> None: """Initialize BaseAuth. @@ -63,6 +64,7 @@ def __init__(self, configuration: "config.Configuration") -> None: """ self.configuration = configuration self._lc_username = configuration.get("auth", "lc_username") + self._strip_domain = configuration.get("auth", "strip_domain") def get_external_login(self, environ: types.WSGIEnviron) -> Union[ Tuple[()], Tuple[str, str]]: @@ -91,4 +93,8 @@ def _login(self, login: str, password: str) -> str: raise NotImplementedError def login(self, login: str, password: str) -> str: - return self._login(login, password).lower() if self._lc_username else self._login(login, password) + if self._lc_username: + login = login.lower() + if self._strip_domain: + login = login.split('@')[0] + return self._login(login, password) diff --git a/radicale/config.py b/radicale/config.py index 967580cb0..d1b66251a 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -191,6 +191,10 @@ def json_str(value: Any) -> dict: "value": "1", "help": "incorrect authentication delay", "type": positive_float}), + ("strip_domain", { + "value": "False", + "help": "strip domain from username", + "type": bool}), ("lc_username", { "value": "False", "help": "convert username to lowercase, must be true for case-insensitive auth providers", diff --git a/radicale/tests/test_auth.py b/radicale/tests/test_auth.py index 858e08279..3604e2f9c 100644 --- a/radicale/tests/test_auth.py +++ b/radicale/tests/test_auth.py @@ -115,6 +115,16 @@ def test_htpasswd_whitespace_password(self) -> None: def test_htpasswd_comment(self) -> None: self._test_htpasswd("plain", "#comment\n #comment\n \ntmp:bepo\n\n") + def test_htpasswd_lc_username(self) -> None: + self.configure({"auth": {"lc_username": "True"}}) + self._test_htpasswd("plain", "tmp:bepo", ( + ("tmp", "bepo", True), ("TMP", "bepo", True), ("tmp1", "bepo", False))) + + def test_htpasswd_strip_domain(self) -> None: + self.configure({"auth": {"strip_domain": "True"}}) + self._test_htpasswd("plain", "tmp:bepo", ( + ("tmp", "bepo", True), ("tmp@domain.example", "bepo", True), ("tmp1", "bepo", False))) + def test_remote_user(self) -> None: self.configure({"auth": {"type": "remote_user"}}) _, responses = self.propfind("/", """\