mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Add: option [auth] uc_username for uppercase conversion (similar to existing lc_username)
This commit is contained in:
parent
0d29de6db9
commit
3ebe51a4cb
5 changed files with 30 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
* Improve: avoid automatically invalid cache on upgrade in case no change on cache structure
|
* Improve: avoid automatically invalid cache on upgrade in case no change on cache structure
|
||||||
* Improve: log important module versions on startup
|
* Improve: log important module versions on startup
|
||||||
* Improve: auth.ldap config shown on startup, terminate in case no password is supplied for bind user
|
* Improve: auth.ldap config shown on startup, terminate in case no password is supplied for bind user
|
||||||
|
* Add: option [auth] uc_username for uppercase conversion (similar to existing lc_username)
|
||||||
|
|
||||||
## 3.3.1
|
## 3.3.1
|
||||||
|
|
||||||
|
|
|
@ -923,6 +923,17 @@ providers like ldap, kerberos
|
||||||
|
|
||||||
Default: `False`
|
Default: `False`
|
||||||
|
|
||||||
|
Note: cannot be enabled together with `uc_username`
|
||||||
|
|
||||||
|
##### uc_username
|
||||||
|
|
||||||
|
Сonvert username to uppercase, must be true for case-insensitive auth
|
||||||
|
providers like ldap, kerberos
|
||||||
|
|
||||||
|
Default: `False`
|
||||||
|
|
||||||
|
Note: cannot be enabled together with `lc_username`
|
||||||
|
|
||||||
##### strip_domain
|
##### strip_domain
|
||||||
|
|
||||||
Strip domain from username
|
Strip domain from username
|
||||||
|
|
|
@ -55,6 +55,7 @@ class BaseAuth:
|
||||||
|
|
||||||
_ldap_groups: Set[str] = set([])
|
_ldap_groups: Set[str] = set([])
|
||||||
_lc_username: bool
|
_lc_username: bool
|
||||||
|
_uc_username: bool
|
||||||
_strip_domain: bool
|
_strip_domain: bool
|
||||||
|
|
||||||
def __init__(self, configuration: "config.Configuration") -> None:
|
def __init__(self, configuration: "config.Configuration") -> None:
|
||||||
|
@ -67,7 +68,13 @@ 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._uc_username = configuration.get("auth", "uc_username")
|
||||||
self._strip_domain = configuration.get("auth", "strip_domain")
|
self._strip_domain = configuration.get("auth", "strip_domain")
|
||||||
|
logger.info("auth.strip_domain: %s", self._strip_domain)
|
||||||
|
logger.info("auth.lc_username: %s", self._lc_username)
|
||||||
|
logger.info("auth.uc_username: %s", self._uc_username)
|
||||||
|
if self._lc_username is True and self._uc_username is True:
|
||||||
|
raise RuntimeError("auth.lc_username and auth.uc_username cannot be enabled together")
|
||||||
|
|
||||||
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]]:
|
||||||
|
@ -98,6 +105,8 @@ class BaseAuth:
|
||||||
def login(self, login: str, password: str) -> str:
|
def login(self, login: str, password: str) -> str:
|
||||||
if self._lc_username:
|
if self._lc_username:
|
||||||
login = login.lower()
|
login = login.lower()
|
||||||
|
if self._uc_username:
|
||||||
|
login = login.upper()
|
||||||
if self._strip_domain:
|
if self._strip_domain:
|
||||||
login = login.split('@')[0]
|
login = login.split('@')[0]
|
||||||
return self._login(login, password)
|
return self._login(login, password)
|
||||||
|
|
|
@ -247,6 +247,10 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([
|
||||||
"value": "False",
|
"value": "False",
|
||||||
"help": "strip domain from username",
|
"help": "strip domain from username",
|
||||||
"type": bool}),
|
"type": bool}),
|
||||||
|
("uc_username", {
|
||||||
|
"value": "False",
|
||||||
|
"help": "convert username to uppercase, must be true for case-insensitive auth providers",
|
||||||
|
"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",
|
||||||
|
|
|
@ -121,6 +121,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_uc_username(self) -> None:
|
||||||
|
self.configure({"auth": {"uc_username": "True"}})
|
||||||
|
self._test_htpasswd("plain", "TMP:bepo", (
|
||||||
|
("tmp", "bepo", True), ("TMP", "bepo", True), ("TMP1", "bepo", False)))
|
||||||
|
|
||||||
def test_htpasswd_strip_domain(self) -> None:
|
def test_htpasswd_strip_domain(self) -> None:
|
||||||
self.configure({"auth": {"strip_domain": "True"}})
|
self.configure({"auth": {"strip_domain": "True"}})
|
||||||
self._test_htpasswd("plain", "tmp:bepo", (
|
self._test_htpasswd("plain", "tmp:bepo", (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue