aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2013-08-06 17:44:22 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2013-08-06 17:44:22 +0300
commit8e599abd2aa1af210992f97f8dea5727e18a1928 (patch)
tree17488d9a5fd583a4b8302a54771af1a0fa457774
parent57e3758f5e23a4bf87e060429741c6ce465cf4e4 (diff)
downloaddjango-crowd-rest-backend-8e599abd2aa1af210992f97f8dea5727e18a1928.tar.gz
Add support for group mapping, similar to supported by django-openid-backend.
AUTH_CROWD_GROUP_MAP config setting.
-rw-r--r--README.md8
-rw-r--r--crowdrest/backend.py5
2 files changed, 9 insertions, 4 deletions
diff --git a/README.md b/README.md
index a7e18ae..ef6913d 100644
--- a/README.md
+++ b/README.md
@@ -61,9 +61,11 @@ How to use it
already existing in Django will be considered (i.e. user group membership in
Django will be updated to intersection of user's Crowd groups and all available
Django groups).
-
- you'd rather have this as True (default). In particular, AUTH_CROWD_STAFF_GROUP
- & AUTH_CROWD_SUPERUSER_GROUP settings depend on this.
+
+ AUTH_CROWD_GROUP_MAP = {}
+ Allows to remap group names from Crowd to Django. This may be needed to migrate
+ existing applications to Crowd authentication, when group names between Django
+ and Crowd mismatch.
_Django user will get staff flag when Crowd user is in given Crowd group_
diff --git a/crowdrest/backend.py b/crowdrest/backend.py
index 30d1f96..6b3a3b3 100644
--- a/crowdrest/backend.py
+++ b/crowdrest/backend.py
@@ -111,7 +111,10 @@ class CrowdRestBackend(object):
def sync_groups(self, user):
data = self.crowdClient.get_user_groups(user.username)
- group_names = set([x["name"] for x in data["groups"]])
+ group_names = [x["name"] for x in data["groups"]]
+ group_map = getattr(settings, "AUTH_CROWD_GROUP_MAP", {})
+ group_names = [group_map.get(x, x) for x in group_names]
+ group_names = set(group_names)
if getattr(settings, "AUTH_CROWD_SUPERUSER_GROUP", None) in group_names:
user.is_superuser = True