mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
add auth/strip_domain option
This commit is contained in:
parent
f117fd06af
commit
13b1aaed39
5 changed files with 24 additions and 1 deletions
|
@ -795,6 +795,12 @@ providers like ldap, kerberos
|
||||||
|
|
||||||
Default: `False`
|
Default: `False`
|
||||||
|
|
||||||
|
##### strip_domain
|
||||||
|
|
||||||
|
Strip domain from username
|
||||||
|
|
||||||
|
Default: `False`
|
||||||
|
|
||||||
#### rights
|
#### rights
|
||||||
|
|
||||||
##### type
|
##### type
|
||||||
|
|
2
config
2
config
|
@ -73,6 +73,8 @@
|
||||||
# Convert username to lowercase, must be true for case-insensitive auth providers
|
# Convert username to lowercase, must be true for case-insensitive auth providers
|
||||||
#lc_username = False
|
#lc_username = False
|
||||||
|
|
||||||
|
# Strip domain name from username
|
||||||
|
#strip_domain = False
|
||||||
|
|
||||||
[rights]
|
[rights]
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ def load(configuration: "config.Configuration") -> "BaseAuth":
|
||||||
class BaseAuth:
|
class BaseAuth:
|
||||||
|
|
||||||
_lc_username: bool
|
_lc_username: bool
|
||||||
|
_strip_domain: bool
|
||||||
|
|
||||||
def __init__(self, configuration: "config.Configuration") -> None:
|
def __init__(self, configuration: "config.Configuration") -> None:
|
||||||
"""Initialize BaseAuth.
|
"""Initialize BaseAuth.
|
||||||
|
@ -63,6 +64,7 @@ class BaseAuth:
|
||||||
"""
|
"""
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
self._lc_username = configuration.get("auth", "lc_username")
|
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[
|
def get_external_login(self, environ: types.WSGIEnviron) -> Union[
|
||||||
Tuple[()], Tuple[str, str]]:
|
Tuple[()], Tuple[str, str]]:
|
||||||
|
@ -91,4 +93,8 @@ class BaseAuth:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def login(self, login: str, password: str) -> str:
|
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)
|
||||||
|
|
|
@ -191,6 +191,10 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
|
||||||
"value": "1",
|
"value": "1",
|
||||||
"help": "incorrect authentication delay",
|
"help": "incorrect authentication delay",
|
||||||
"type": positive_float}),
|
"type": positive_float}),
|
||||||
|
("strip_domain", {
|
||||||
|
"value": "False",
|
||||||
|
"help": "strip domain from username",
|
||||||
|
"type": bool}),
|
||||||
("lc_username", {
|
("lc_username", {
|
||||||
"value": "False",
|
"value": "False",
|
||||||
"help": "convert username to lowercase, must be true for case-insensitive auth providers",
|
"help": "convert username to lowercase, must be true for case-insensitive auth providers",
|
||||||
|
|
|
@ -120,6 +120,11 @@ class TestBaseAuthRequests(BaseTest):
|
||||||
self._test_htpasswd("plain", "tmp:bepo", (
|
self._test_htpasswd("plain", "tmp:bepo", (
|
||||||
("tmp", "bepo", True), ("TMP", "bepo", True), ("tmp1", "bepo", False)))
|
("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:
|
def test_remote_user(self) -> None:
|
||||||
self.configure({"auth": {"type": "remote_user"}})
|
self.configure({"auth": {"type": "remote_user"}})
|
||||||
_, responses = self.propfind("/", """\
|
_, responses = self.propfind("/", """\
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue