Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made "su_staff" Class Attribute for role possible to set both is_superuser and is_staff to true in one step. Also fixes #23. #30

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ For each role (is_staff and is_superuser) and group mapping one RAIDUS Attribute
The syntax allows the following mappings:
* `role=staff` (sets is_staff=True in the User object)
* `role=superuser` (sets is_superuser=True for the User object)
* `role=su-staff` (sets both is_superuser and is_staff = True for the User object)
* `group=Group1` (add the User object to `Group1`)

To avoid namespace clashes in the RADIUS Attribute 25 values that may be
Expand Down
32 changes: 21 additions & 11 deletions radiusauth/backends/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,27 @@ def _perform_radius_auth(self, client, packet):
role_class_prefix = app_class_prefix + "role="

for cl in reply['Class']:
cl = cl.decode("utf-8")
if cl.lower().find(group_class_prefix) == 0:
groups.append(cl[len(group_class_prefix):])
elif cl.lower().find(role_class_prefix) == 0:
role = cl[len(role_class_prefix):]
if role == "staff":
is_staff = True
elif role == "superuser":
is_superuser = True
else:
logging.warning("RADIUS Attribute Class contains unknown role '%s'. Only roles 'staff' and 'superuser' are allowed" % cl)
try:
cl = cl.decode("utf-8")
if cl.lower().find(group_class_prefix) == 0:
groups.append(cl[len(group_class_prefix):])
elif cl.lower().find(role_class_prefix) == 0:
role = cl[len(role_class_prefix):]
if role == "staff":
is_staff = True
elif role == "superuser":
is_superuser = True
# Passing "su-staff" through the Class attribute from the RADIUS server
# will set both staff and superuser to true for the user.
elif role == "su-staff":
is_staff = True
is_superuser = True
else:
logging.warning("RADIUS Attribute Class contains unknown role '%s'. Only roles 'staff', "
"'su-staff' and 'superuser' are allowed" % cl)
except UnicodeDecodeError:
logging.warning("RADIUS Attribute Class contains non-unicode value '%s'. Only unicode values are "
"supported" % cl)
return groups, is_staff, is_superuser

def _radius_auth(self, server, username, password):
Expand Down