Skip to content

Commit

Permalink
Merge pull request #1470 from itglob/master
Browse files Browse the repository at this point in the history
added compatibility with a case-insensitive authentication provider
  • Loading branch information
pbiering authored Apr 18, 2024
2 parents 76dc9dc + a7882b9 commit 7340ddc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,13 @@ Message displayed in the client when a password is needed.

Default: `Radicale - Password Required`

##### lc_username

Сonvert username to lowercase, must be true for case-insensitive auth
providers like ldap, kerberos

Default: `False`

#### rights

##### type
Expand Down
3 changes: 3 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
# Message displayed in the client when a password is needed
#realm = Radicale - Password Required

# Сonvert username to lowercase, must be true for case-insensitive auth providers
#lc_username = 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 @@ -44,6 +44,8 @@ def load(configuration: "config.Configuration") -> "BaseAuth":

class BaseAuth:

_lc_username: bool

def __init__(self, configuration: "config.Configuration") -> None:
"""Initialize BaseAuth.
Expand All @@ -53,6 +55,7 @@ def __init__(self, configuration: "config.Configuration") -> None:
"""
self.configuration = configuration
self._lc_username = configuration.get("auth", "lc_username")

def get_external_login(self, environ: types.WSGIEnviron) -> Union[
Tuple[()], Tuple[str, str]]:
Expand All @@ -67,7 +70,7 @@ def get_external_login(self, environ: types.WSGIEnviron) -> Union[
"""
return ()

def login(self, login: str, password: str) -> str:
def _login(self, login: str, password: str) -> str:
"""Check credentials and map login to internal user
``login`` the login name
Expand All @@ -79,3 +82,6 @@ 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)
2 changes: 1 addition & 1 deletion radicale/auth/htpasswd.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _autodetect(self, hash_value: str, password: str) -> bool:
# assumed plaintext
return self._plain(hash_value, password)

def login(self, login: str, password: str) -> str:
def _login(self, login: str, password: str) -> str:
"""Validate credentials.
Iterate through htpasswd credential file until login matches, extract
Expand Down
2 changes: 1 addition & 1 deletion radicale/auth/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@

class Auth(auth.BaseAuth):

def login(self, login: str, password: str) -> str:
def _login(self, login: str, password: str) -> str:
return login
6 changes: 5 additions & 1 deletion radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def _convert_to_bool(value: Any) -> bool:
("delay", {
"value": "1",
"help": "incorrect authentication delay",
"type": positive_float})])),
"type": positive_float}),
("lc_username", {
"value": "False",
"help": "convert username to lowercase, must be true for case-insensitive auth providers",
"type": bool})])),
("rights", OrderedDict([
("type", {
"value": "owner_only",
Expand Down

0 comments on commit 7340ddc

Please sign in to comment.