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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ PLUGINS_CONFIG = {
# Groups must be created beforehand in NetBox.
'GROUP_MAPPINGS': {
'saml-group3': 'netbox-group'
}
},
# Regex pattern to match groups for sync. Optional.
# Groups must be created beforehand in NetBox.
'GROUP_REGEX_PATTERN': r'^Netbox-.*'
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions django3_saml2_nbplugin/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def configure_user(self, request: WSGIRequest, user: User) -> User:
if saml_group in ident_groups:
user_groups.append(Group.objects.get(name=django_group))
user.groups.set(user_groups)
if "GROUP_REGEX_PATTERN" in be_settings and "GROUP_ATTR" in be_settings:
group_regex_pattern = be_settings["GROUP_REGEX_PATTERN"]
user_groups = []
for group_name in ident_groups:
if re.match(group_regex_pattern, group_name):
try:
user_groups.append(Group.objects.get(name=group_name))
except Group.DoesNotExist:
# Group does not exist in Netbox, skip it
continue
user.groups.set(user_groups)
user.save()

# call Netbox superclass for further processing of REMOTE_AUTH_xxx variables.
Expand Down