group: introduce type auth_type, extend for PAM module
This commit is contained in:
2
config
2
config
@@ -214,7 +214,7 @@
|
|||||||
[group]
|
[group]
|
||||||
|
|
||||||
# Group lookup method
|
# Group lookup method
|
||||||
# Value: none | htgroup
|
# Value: none | auth_type | htgroup
|
||||||
type = none
|
type = none
|
||||||
|
|
||||||
# Htgroup filename
|
# Htgroup filename
|
||||||
|
|||||||
@@ -598,14 +598,17 @@ class Application(ApplicationPartDelete, ApplicationPartHead,
|
|||||||
user = ""
|
user = ""
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
if self.configuration.get("group", "type") != "none":
|
group_type = self.configuration.get("group", "type")
|
||||||
|
if group_type in ["htgroup"]:
|
||||||
self._rights._user_groups = self._group.groups(login) if login else set([])
|
self._rights._user_groups = self._group.groups(login) if login else set([])
|
||||||
elif self.configuration.get("auth", "type") == "ldap":
|
elif group_type in ["auth_type"]:
|
||||||
try:
|
auth_type = self.configuration.get("auth", "type")
|
||||||
logger.debug("Groups received from LDAP: %r", ",".join(self._auth._ldap_groups))
|
if auth_type in ["ldap", "pam"]:
|
||||||
self._rights._user_groups = self._auth._ldap_groups
|
try:
|
||||||
except AttributeError:
|
logger.debug("Groups received from %r: %r", auth_type, ",".join(self._auth._groups))
|
||||||
pass
|
self._rights._user_groups = self._auth._groups
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Create principal collection
|
# Create principal collection
|
||||||
if user:
|
if user:
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class AuthContext:
|
|||||||
|
|
||||||
class BaseAuth:
|
class BaseAuth:
|
||||||
|
|
||||||
_ldap_groups: Set[str] = set([])
|
_groups: Set[str] = set([])
|
||||||
_urldecode_username: bool
|
_urldecode_username: bool
|
||||||
_lc_username: bool
|
_lc_username: bool
|
||||||
_uc_username: bool
|
_uc_username: bool
|
||||||
|
|||||||
@@ -381,8 +381,8 @@ class Auth(auth.BaseAuth):
|
|||||||
tmp.append(rdns[0][1])
|
tmp.append(rdns[0][1])
|
||||||
except Exception:
|
except Exception:
|
||||||
tmp.append(g)
|
tmp.append(g)
|
||||||
self._ldap_groups = set(tmp)
|
self._groups = set(tmp)
|
||||||
logger.debug("_login3 LDAP groups of user: %s", ",".join(self._ldap_groups))
|
logger.debug("_login3 LDAP groups of user: %s", ",".join(self._groups))
|
||||||
|
|
||||||
if self._ldap_user_attr:
|
if self._ldap_user_attr:
|
||||||
if user_entry['attributes'][self._ldap_user_attr]:
|
if user_entry['attributes'][self._ldap_user_attr]:
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ class Auth(auth.BaseAuth):
|
|||||||
else:
|
else:
|
||||||
logger.debug("PAM user %r belongs to the required group: %r" % (login, self._group_membership))
|
logger.debug("PAM user %r belongs to the required group: %r" % (login, self._group_membership))
|
||||||
|
|
||||||
|
# add groups
|
||||||
|
members.append(primary_group)
|
||||||
|
self._groups = set(members)
|
||||||
|
logger.debug("PAM groups of user: %s", ",".join(self._groups))
|
||||||
|
|
||||||
# Check the password
|
# Check the password
|
||||||
if self.pam_authenticate(login, password, service=self._service):
|
if self.pam_authenticate(login, password, service=self._service):
|
||||||
return login
|
return login
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from radicale import config, utils
|
|||||||
from radicale.log import logger
|
from radicale.log import logger
|
||||||
|
|
||||||
INTERNAL_TYPES: Sequence[str] = ("none",
|
INTERNAL_TYPES: Sequence[str] = ("none",
|
||||||
|
"auth_type",
|
||||||
"htgroup",
|
"htgroup",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class TestBaseGroupRequests(BaseTest):
|
|||||||
"type": auth_type,
|
"type": auth_type,
|
||||||
"oauth2_token": "dummy",
|
"oauth2_token": "dummy",
|
||||||
},
|
},
|
||||||
"group": {"type": "auth-type"}
|
"group": {"type": "auth_type"}
|
||||||
})
|
})
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
@@ -130,10 +130,9 @@ class TestBaseGroupRequests(BaseTest):
|
|||||||
{"auth": {
|
{"auth": {
|
||||||
"type": auth_type,
|
"type": auth_type,
|
||||||
},
|
},
|
||||||
"group": {"type": "auth-type"}
|
"group": {"type": "auth_type"}
|
||||||
})
|
})
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user