@@ -380,19 +380,35 @@ Learn more about Django profile models at:
380
380
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
381
381
382
382
383
+ Custom user attributes processing
384
+ ---------------------------------
385
+
383
386
Sometimes you need to use special logic to update the user object
384
387
depending on the SAML2 attributes and the mapping described above
385
388
is simply not enough. For these cases djangosaml2 provides hooks _
386
- that can be overriden with custom functionality. For example::
389
+ that can be overriden with custom functionality.
390
+
391
+ First of all reference the modified Saml2Backend in settings.py file::
392
+
393
+
394
+ AUTHENTICATION_BACKENDS = [
395
+ 'your_package.authentication.ModifiedSaml2Backend',
396
+ ]
397
+
398
+
399
+ For example::
400
+
401
+ from djangosaml2.backends import Saml2Backend
387
402
388
- from djangosaml2.backends import Saml2Backend
403
+ class ModifiedSaml2Backend(Saml2Backend):
404
+ def save_user(self, user, *args, **kwargs):
405
+ user.save()
406
+ user_group = Group.objects.get(name='Default')
407
+ user.groups.add(user_group)
408
+ return super().save_user(user, *args, **kwargs)
389
409
390
- class MySaml2Backend(Saml2Backend):
391
- def save_user(self, user, *args, **kwargs):
392
- # Add custom logic here
393
- return super().save_user(user, *args, **kwargs)
410
+ .. _hooks : https://github.com/identitypython/djangosaml2/blob/master/djangosaml2/backends.py#L181
394
411
395
- .. _hooks : https://github.com/knaperek/djangosaml2/blob/master/djangosaml2/backends.py#L181
396
412
397
413
398
414
URLs
0 commit comments