From 91306aeedb202810296050616d89da127becb6e4 Mon Sep 17 00:00:00 2001 From: Lars Meijers Date: Fri, 15 Mar 2024 14:44:05 +0100 Subject: [PATCH] cleanup and small improvement --- dojo/group/utils.py | 5 +++-- dojo/pipeline.py | 6 +----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dojo/group/utils.py b/dojo/group/utils.py index e0167bc0192..b61e422a0b5 100644 --- a/dojo/group/utils.py +++ b/dojo/group/utils.py @@ -2,7 +2,7 @@ from django.contrib.auth.models import Group from django.db.models.signals import post_save, post_delete from django.dispatch import receiver -from dojo.models import Dojo_Group, Dojo_Group_Member, Role +from dojo.models import Dojo_Group, Dojo_Group_Member, Role, Dojo_User from django.conf import settings @@ -41,7 +41,8 @@ def group_post_save_handler(sender, **kwargs): group.save() user = get_current_user() - if user and not settings.AZUREAD_TENANT_OAUTH2_GET_GROUPS and not settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS: + if user and isinstance(user, Dojo_User): + #if user and not settings.AZUREAD_TENANT_OAUTH2_GET_GROUPS and not settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS: # Add the current user as the owner of the group member = Dojo_Group_Member() member.user = user diff --git a/dojo/pipeline.py b/dojo/pipeline.py index 2868e587148..fba14699410 100644 --- a/dojo/pipeline.py +++ b/dojo/pipeline.py @@ -68,15 +68,11 @@ def modify_permissions(backend, uid, user=None, social=None, *args, **kwargs): def update_keycloak_groups(backend, uid, user=None, social=None, *args, **kwargs): if settings.KEYCLOAK_OAUTH2_ENABLED and settings.KEYCLOAK_TENANT_OAUTH2_GET_GROUPS and isinstance(backend, OpenIdConnectAuth): - soc = user.social_auth.order_by("-created").first() - token = soc.extra_data['access_token'] - #print("accesstoken: " + str(token)) - #print("response raw: " + str(kwargs['response'])) group_names = [] if 'groups' not in kwargs['response'] or kwargs['response']['groups'] == "": logger.warning("No groups in response. Stopping to update groups of user based on azureAD") return - group_ids = kwargs['response']['groups'] # probably need another setting with a regex ? + group_ids = kwargs['response']['groups'] for group_from_response in group_ids: if settings.KEYCLOAK_TENANT_OAUTH2_GROUPS_FILTER == "" or re.search(settings.KEYCLOAK_TENANT_OAUTH2_GROUPS_FILTER, group_from_response): group_names.append(group_from_response)