Skip to content

Commit 3ff964b

Browse files
malexmavetwwd
authored andcommitted
Pull information about user profiles config from correct config
Signed-off-by: Max Maass <max.maass@iteratec.com>
1 parent bdf86da commit 3ff964b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

kcwarden/custom_types/keycloak_object.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22
from copy import deepcopy
3+
import json
34

45

56
class Dataclass(ABC):
@@ -56,7 +57,17 @@ def get_access_token_lifespan(self) -> int:
5657
return self._d["accessTokenLifespan"]
5758

5859
def get_unmanaged_attribute_policy(self) -> str | None:
59-
return self._d["attributes"].get("unmanagedAttributePolicy")
60+
try:
61+
attribute_config = json.loads(
62+
self._d["components"]
63+
.get("org.keycloak.userprofile.UserProfileProvider")[0]
64+
.get("config")
65+
.get("kc.user.profile.config")[0]
66+
)
67+
except TypeError: # Will be thrown if the UserProfileProvider wasn't found
68+
return None
69+
# Default value in Keycloak 26+ is "DISABLED", which will sometimes be omitted from the config file
70+
return attribute_config.get("unmanagedAttributePolicy", "DISABLED")
6071

6172
def has_declarative_user_profiles_enabled_legacy_option(self) -> bool:
6273
return self._d["attributes"].get("userProfileEnabled", "false") == "true"

0 commit comments

Comments
 (0)