Skip to content

Commit

Permalink
Merge pull request #1544 from pbiering/option-strip-domain-name-from-…
Browse files Browse the repository at this point in the history
…login

Option strip domain name from login
  • Loading branch information
pbiering authored Jul 18, 2024
2 parents 055489f + 13b1aae commit e5e80eb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,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
10 changes: 10 additions & 0 deletions radicale/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), ("[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 e5e80eb

Please sign in to comment.