Skip to content

Commit

Permalink
add auth/strip_domain option
Browse files Browse the repository at this point in the history
  • Loading branch information
pbiering committed Jul 18, 2024
1 parent f117fd0 commit 13b1aae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,12 @@ providers like ldap, kerberos

Default: `False`

##### strip_domain

Strip domain from username

Default: `False`

#### rights

##### type
Expand Down
2 changes: 2 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 7 additions & 1 deletion radicale/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]]:
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions radicale/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def test_htpasswd_lc_username(self) -> None:
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), ("[email protected]", "bepo", True), ("tmp1", "bepo", False)))

def test_remote_user(self) -> None:
self.configure({"auth": {"type": "remote_user"}})
_, responses = self.propfind("/", """\
Expand Down

0 comments on commit 13b1aae

Please sign in to comment.