mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
11508 temp azure changes
This commit is contained in:
parent
eeb069048f
commit
635161bd38
@ -386,3 +386,40 @@ def user_default_groups_handler(backend, user, response, *args, **kwargs):
|
|||||||
user.groups.add(*group_list)
|
user.groups.add(*group_list)
|
||||||
else:
|
else:
|
||||||
logger.info(f"No valid group assignments for {user} - REMOTE_AUTH_DEFAULT_GROUPS may be incorrectly set?")
|
logger.info(f"No valid group assignments for {user} - REMOTE_AUTH_DEFAULT_GROUPS may be incorrectly set?")
|
||||||
|
|
||||||
|
|
||||||
|
class AuthFailed(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def azure_map_groups(response, user, backend, *args, **kwargs):
|
||||||
|
'''
|
||||||
|
Assign user to netbox group matching role
|
||||||
|
Also set is_superuser or is_staff for special roles 'superusers' and 'staff'
|
||||||
|
'''
|
||||||
|
print(f"response: {response}")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
roles = response['roles']
|
||||||
|
except KeyError:
|
||||||
|
user.groups.clear()
|
||||||
|
raise AuthFailed("No role assigned")
|
||||||
|
|
||||||
|
try:
|
||||||
|
user.is_superuser = False
|
||||||
|
user.is_staff = False
|
||||||
|
|
||||||
|
for role in roles:
|
||||||
|
if role == 'superusers':
|
||||||
|
user.is_superuser = True
|
||||||
|
user.save()
|
||||||
|
continue
|
||||||
|
if role == "staff":
|
||||||
|
user.is_staff = True
|
||||||
|
user.save()
|
||||||
|
continue
|
||||||
|
|
||||||
|
group, created = Group.objects.get_or_create(name=role)
|
||||||
|
group.user_set.add(user)
|
||||||
|
except Group.DoesNotExist:
|
||||||
|
pass
|
||||||
|
@ -553,6 +553,7 @@ SOCIAL_AUTH_PIPELINE = (
|
|||||||
'netbox.authentication.user_default_groups_handler',
|
'netbox.authentication.user_default_groups_handler',
|
||||||
'social_core.pipeline.social_auth.load_extra_data',
|
'social_core.pipeline.social_auth.load_extra_data',
|
||||||
'social_core.pipeline.user.user_details',
|
'social_core.pipeline.user.user_details',
|
||||||
|
'netbox.authentication.azure_map_groups',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load all SOCIAL_AUTH_* settings from the user configuration
|
# Load all SOCIAL_AUTH_* settings from the user configuration
|
||||||
|
Loading…
Reference in New Issue
Block a user