authentik.sources.scim.models
SCIM Source
1"""SCIM Source""" 2 3from typing import Any 4from uuid import uuid4 5 6from django.db import models 7from django.templatetags.static import static 8from django.utils.translation import gettext_lazy as _ 9from rest_framework.serializers import BaseSerializer, Serializer 10 11from authentik.core.models import Group, PropertyMapping, Source, Token, User 12from authentik.lib.models import InternallyManagedMixin, SerializerModel 13 14 15class SCIMSource(Source): 16 """System for Cross-domain Identity Management Source, allows for 17 cross-system user provisioning""" 18 19 token = models.ForeignKey(Token, on_delete=models.CASCADE, null=True, default=None) 20 21 @property 22 def service_account_identifier(self) -> str: 23 return f"ak-source-scim-{self.pk}" 24 25 @property 26 def component(self) -> str: 27 """Return component used to edit this object""" 28 return "ak-source-scim-form" 29 30 @property 31 def icon_url(self) -> str: 32 return static("authentik/sources/scim/light.svg") 33 34 @property 35 def serializer(self) -> BaseSerializer: 36 from authentik.sources.scim.api.sources import SCIMSourceSerializer 37 38 return SCIMSourceSerializer 39 40 @property 41 def property_mapping_type(self) -> type[PropertyMapping]: 42 return SCIMSourcePropertyMapping 43 44 def get_base_user_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 45 properties = {} 46 47 def get_email(data: list[dict]) -> str: 48 """Wrapper to get primary email or first email""" 49 for email in data: 50 if email.get("primary", False): 51 return email.get("value") 52 if len(data) < 1: 53 return "" 54 return data[0].get("value") 55 56 if "userName" in data: 57 properties["username"] = data.get("userName") 58 if "name" in data: 59 properties["name"] = data.get("name", {}).get("formatted", data.get("displayName")) 60 if "emails" in data: 61 properties["email"] = get_email(data.get("emails")) 62 if "active" in data: 63 properties["is_active"] = data.get("active") 64 65 return properties 66 67 def get_base_group_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 68 properties = {} 69 70 if "displayName" in data: 71 properties["name"] = data.get("displayName") 72 73 return properties 74 75 def __str__(self) -> str: 76 return f"SCIM Source {self.name}" 77 78 class Meta: 79 80 verbose_name = _("SCIM Source") 81 verbose_name_plural = _("SCIM Sources") 82 83 84class SCIMSourcePropertyMapping(PropertyMapping): 85 """Map SCIM properties to User or Group object attributes""" 86 87 expression_allowed_types = [dict] 88 89 @property 90 def component(self) -> str: 91 return "ak-property-mapping-source-scim-form" 92 93 @property 94 def serializer(self) -> type[Serializer]: 95 from authentik.sources.scim.api.property_mappings import ( 96 SCIMSourcePropertyMappingSerializer, 97 ) 98 99 return SCIMSourcePropertyMappingSerializer 100 101 class Meta: 102 verbose_name = _("SCIM Source Property Mapping") 103 verbose_name_plural = _("SCIM Source Property Mappings") 104 105 106class SCIMSourceUser(InternallyManagedMixin, SerializerModel): 107 """Mapping of a user and source to a SCIM user ID""" 108 109 id = models.TextField(primary_key=True, default=uuid4) 110 external_id = models.TextField() 111 user = models.ForeignKey(User, on_delete=models.CASCADE) 112 source = models.ForeignKey(SCIMSource, on_delete=models.CASCADE) 113 attributes = models.JSONField(default=dict) 114 last_update = models.DateTimeField(auto_now=True) 115 116 @property 117 def serializer(self) -> BaseSerializer: 118 from authentik.sources.scim.api.users import SCIMSourceUserSerializer 119 120 return SCIMSourceUserSerializer 121 122 class Meta: 123 unique_together = (("external_id", "source"),) 124 indexes = [ 125 models.Index(fields=["external_id"]), 126 ] 127 128 def __str__(self) -> str: 129 return f"SCIM User {self.user_id} to {self.source_id}" 130 131 132class SCIMSourceGroup(InternallyManagedMixin, SerializerModel): 133 """Mapping of a group and source to a SCIM user ID""" 134 135 id = models.TextField(primary_key=True, default=uuid4) 136 external_id = models.TextField() 137 group = models.ForeignKey(Group, on_delete=models.CASCADE) 138 source = models.ForeignKey(SCIMSource, on_delete=models.CASCADE) 139 attributes = models.JSONField(default=dict) 140 last_update = models.DateTimeField(auto_now=True) 141 142 @property 143 def serializer(self) -> BaseSerializer: 144 from authentik.sources.scim.api.groups import SCIMSourceGroupSerializer 145 146 return SCIMSourceGroupSerializer 147 148 class Meta: 149 unique_together = (("external_id", "source"),) 150 indexes = [ 151 models.Index(fields=["external_id"]), 152 ] 153 154 def __str__(self) -> str: 155 return f"SCIM Group {self.group_id} to {self.source_id}"
16class SCIMSource(Source): 17 """System for Cross-domain Identity Management Source, allows for 18 cross-system user provisioning""" 19 20 token = models.ForeignKey(Token, on_delete=models.CASCADE, null=True, default=None) 21 22 @property 23 def service_account_identifier(self) -> str: 24 return f"ak-source-scim-{self.pk}" 25 26 @property 27 def component(self) -> str: 28 """Return component used to edit this object""" 29 return "ak-source-scim-form" 30 31 @property 32 def icon_url(self) -> str: 33 return static("authentik/sources/scim/light.svg") 34 35 @property 36 def serializer(self) -> BaseSerializer: 37 from authentik.sources.scim.api.sources import SCIMSourceSerializer 38 39 return SCIMSourceSerializer 40 41 @property 42 def property_mapping_type(self) -> type[PropertyMapping]: 43 return SCIMSourcePropertyMapping 44 45 def get_base_user_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 46 properties = {} 47 48 def get_email(data: list[dict]) -> str: 49 """Wrapper to get primary email or first email""" 50 for email in data: 51 if email.get("primary", False): 52 return email.get("value") 53 if len(data) < 1: 54 return "" 55 return data[0].get("value") 56 57 if "userName" in data: 58 properties["username"] = data.get("userName") 59 if "name" in data: 60 properties["name"] = data.get("name", {}).get("formatted", data.get("displayName")) 61 if "emails" in data: 62 properties["email"] = get_email(data.get("emails")) 63 if "active" in data: 64 properties["is_active"] = data.get("active") 65 66 return properties 67 68 def get_base_group_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 69 properties = {} 70 71 if "displayName" in data: 72 properties["name"] = data.get("displayName") 73 74 return properties 75 76 def __str__(self) -> str: 77 return f"SCIM Source {self.name}" 78 79 class Meta: 80 81 verbose_name = _("SCIM Source") 82 verbose_name_plural = _("SCIM Sources")
System for Cross-domain Identity Management Source, allows for cross-system user provisioning
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
26 @property 27 def component(self) -> str: 28 """Return component used to edit this object""" 29 return "ak-source-scim-form"
Return component used to edit this object
35 @property 36 def serializer(self) -> BaseSerializer: 37 from authentik.sources.scim.api.sources import SCIMSourceSerializer 38 39 return SCIMSourceSerializer
Get serializer for this model
41 @property 42 def property_mapping_type(self) -> type[PropertyMapping]: 43 return SCIMSourcePropertyMapping
Return property mapping type used by this object
45 def get_base_user_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 46 properties = {} 47 48 def get_email(data: list[dict]) -> str: 49 """Wrapper to get primary email or first email""" 50 for email in data: 51 if email.get("primary", False): 52 return email.get("value") 53 if len(data) < 1: 54 return "" 55 return data[0].get("value") 56 57 if "userName" in data: 58 properties["username"] = data.get("userName") 59 if "name" in data: 60 properties["name"] = data.get("name", {}).get("formatted", data.get("displayName")) 61 if "emails" in data: 62 properties["email"] = get_email(data.get("emails")) 63 if "active" in data: 64 properties["is_active"] = data.get("active") 65 66 return properties
Get base properties for a user to build final properties upon.
68 def get_base_group_properties(self, data: dict[str, Any]) -> dict[str, Any | dict[str, Any]]: 69 properties = {} 70 71 if "displayName" in data: 72 properties["name"] = data.get("displayName") 73 74 return properties
Get base properties for a group to build final properties upon.
Accessor to the related object on the forward side of a one-to-one relation.
In the example::
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Restaurant.place is a ForwardOneToOneDescriptor instance.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children is a ReverseManyToOneDescriptor instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager() defined below.
Inherited Members
- authentik.core.models.Source
- MANAGED_INBUILT
- name
- slug
- user_path_template
- enabled
- promoted
- user_property_mappings
- group_property_mappings
- icon
- authentication_flow
- enrollment_flow
- user_matching_mode
- group_matching_mode
- objects
- get_icon_url
- get_icon_themed_urls
- icon_themed_urls
- get_user_path
- ui_user_settings
- managed
- authentication_flow_id
- enrollment_flow_id
- get_user_matching_mode_display
- get_group_matching_mode_display
- policybindingmodel_ptr_id
- policybindingmodel_ptr
- user_set
- usersourceconnection_set
- groupsourceconnection_set
- sourceuserpropertymapping_set
- sourcegrouppropertymapping_set
- kerberossource
- ldapsource
- oauthsource
- samlsource
- identificationstage_set
- identificationstagesource_set
- plexsource
- scimsource
- telegramsource
- sourcestage_set
- authentik.policies.models.PolicyBindingModel
- pbm_uuid
- policies
- policy_engine_mode
- supported_policy_binding_targets
- get_policy_engine_mode_display
- bindings
- application
- applicationentitlement
- source
- flow
- flowstagebinding
- notificationrule
- device
- deviceaccessgroup
- oauth2dynamicclientregistration
- userexpirationrule
- request_rule_bindings
- request_rule_child_bindings
- requestrulebinding
- request_rules
- requestrule
- grantrequest_set
- grantrequesttarget_set
The requested object does not exist
The query returned multiple objects when only one was expected.
85class SCIMSourcePropertyMapping(PropertyMapping): 86 """Map SCIM properties to User or Group object attributes""" 87 88 expression_allowed_types = [dict] 89 90 @property 91 def component(self) -> str: 92 return "ak-property-mapping-source-scim-form" 93 94 @property 95 def serializer(self) -> type[Serializer]: 96 from authentik.sources.scim.api.property_mappings import ( 97 SCIMSourcePropertyMappingSerializer, 98 ) 99 100 return SCIMSourcePropertyMappingSerializer 101 102 class Meta: 103 verbose_name = _("SCIM Source Property Mapping") 104 verbose_name_plural = _("SCIM Source Property Mappings")
Map SCIM properties to User or Group object attributes
94 @property 95 def serializer(self) -> type[Serializer]: 96 from authentik.sources.scim.api.property_mappings import ( 97 SCIMSourcePropertyMappingSerializer, 98 ) 99 100 return SCIMSourcePropertyMappingSerializer
Get serializer for this model
Accessor to the related object on the forward side of a one-to-one relation.
In the example::
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Restaurant.place is a ForwardOneToOneDescriptor instance.
Inherited Members
- authentik.core.models.PropertyMapping
- pm_uuid
- name
- expression
- objects
- evaluate
- managed
- provider_set
- source_userpropertymappings_set
- source_grouppropertymappings_set
- sourceuserpropertymapping_set
- sourcegrouppropertymapping_set
- providerpropertymapping_set
- notificationwebhookmapping
- kerberossourcepropertymapping
- ldapsourcepropertymapping
- oauthsourcepropertymapping
- scopemapping
- racpropertymapping
- radiusproviderpropertymapping
- samlsourcepropertymapping
- samlpropertymapping
- scimprovider_set
- scimprovidergrouppropertymapping_set
- scimmapping
- plexsourcepropertymapping
- scimsourcepropertymapping
- telegramsourcepropertymapping
- googleworkspaceprovider_set
- googleworkspaceproviderpropertymappingsgroup_set
- googleworkspaceprovidermapping
- microsoftentraprovider_set
- microsoftentraproviderpropertymappingsgroup_set
- microsoftentraprovidermapping
The requested object does not exist
The query returned multiple objects when only one was expected.
107class SCIMSourceUser(InternallyManagedMixin, SerializerModel): 108 """Mapping of a user and source to a SCIM user ID""" 109 110 id = models.TextField(primary_key=True, default=uuid4) 111 external_id = models.TextField() 112 user = models.ForeignKey(User, on_delete=models.CASCADE) 113 source = models.ForeignKey(SCIMSource, on_delete=models.CASCADE) 114 attributes = models.JSONField(default=dict) 115 last_update = models.DateTimeField(auto_now=True) 116 117 @property 118 def serializer(self) -> BaseSerializer: 119 from authentik.sources.scim.api.users import SCIMSourceUserSerializer 120 121 return SCIMSourceUserSerializer 122 123 class Meta: 124 unique_together = (("external_id", "source"),) 125 indexes = [ 126 models.Index(fields=["external_id"]), 127 ] 128 129 def __str__(self) -> str: 130 return f"SCIM User {self.user_id} to {self.source_id}"
Mapping of a user and source to a SCIM user ID
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
117 @property 118 def serializer(self) -> BaseSerializer: 119 from authentik.sources.scim.api.users import SCIMSourceUserSerializer 120 121 return SCIMSourceUserSerializer
Get serializer for this model
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.
133class SCIMSourceGroup(InternallyManagedMixin, SerializerModel): 134 """Mapping of a group and source to a SCIM user ID""" 135 136 id = models.TextField(primary_key=True, default=uuid4) 137 external_id = models.TextField() 138 group = models.ForeignKey(Group, on_delete=models.CASCADE) 139 source = models.ForeignKey(SCIMSource, on_delete=models.CASCADE) 140 attributes = models.JSONField(default=dict) 141 last_update = models.DateTimeField(auto_now=True) 142 143 @property 144 def serializer(self) -> BaseSerializer: 145 from authentik.sources.scim.api.groups import SCIMSourceGroupSerializer 146 147 return SCIMSourceGroupSerializer 148 149 class Meta: 150 unique_together = (("external_id", "source"),) 151 indexes = [ 152 models.Index(fields=["external_id"]), 153 ] 154 155 def __str__(self) -> str: 156 return f"SCIM Group {self.group_id} to {self.source_id}"
Mapping of a group and source to a SCIM user ID
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example::
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent is a ForwardManyToOneDescriptor instance.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
143 @property 144 def serializer(self) -> BaseSerializer: 145 from authentik.sources.scim.api.groups import SCIMSourceGroupSerializer 146 147 return SCIMSourceGroupSerializer
Get serializer for this model
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Inherited Members
The requested object does not exist
The query returned multiple objects when only one was expected.