Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ to `True`, as django-radius has functioned in earlier versions.
RADIUS_REMOTE_ROLES = True
```

The default behavior is for django-radius to bring groups in from RADIUS
when a user is authenticated. You may overwrite this behavior by setting the
following in settings.py of your Django project:

```python
RADIUS_IMPORT_GROUPS = False
```

This will still import the is_staff, is_superuser flags from RADIUS according
to the role assignment but ignore any group assignments, putting django
in charge of group to user assignment(s).

When a user is successfully authenticated via the RADIUS backend, a `User`
object is created in Django's built-in auth application with the same username.
This user's password is set to the password which they logged into the RADIUS
Expand Down
12 changes: 11 additions & 1 deletion radiusauth/backends/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ def get_django_user(self, username, password=None, groups=[], is_staff=False, is
user.set_password(password)

user.save()
user.groups.set(groups)

# If RADIUS_IMPORT_GROUPS is not set, configure it to default value False.
# False means that a user import from RADIUS to Django will NOT overwrite the group
# assignment of the user.
# The default is TRUE to mimic django-radius's current behavior pre Pull Request.
if not hasattr(settings, "RADIUS_IMPORT_GROUPS"):
settings.RADIUS_IMPORT_GROUPS = True

if settings.RADIUS_IMPORT_GROUPS:
user.groups.set(groups)

return user

def get_user_groups(self, group_names):
Expand Down