mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-14 16:37:17 +00:00
ability to populate is_staff and is_superuser flags at LDAP authentication (#1335)
This commit is contained in:
commit
224df914ec
5 changed files with 33 additions and 0 deletions
|
@ -112,6 +112,7 @@ CONFIG_SCHEMA: Dict[str, ConfigDefaultDict] = {
|
||||||
'LDAP_FIRSTNAME_ATTR': {'type': str, 'default': None},
|
'LDAP_FIRSTNAME_ATTR': {'type': str, 'default': None},
|
||||||
'LDAP_LASTNAME_ATTR': {'type': str, 'default': None},
|
'LDAP_LASTNAME_ATTR': {'type': str, 'default': None},
|
||||||
'LDAP_EMAIL_ATTR': {'type': str, 'default': None},
|
'LDAP_EMAIL_ATTR': {'type': str, 'default': None},
|
||||||
|
'LDAP_CREATE_SUPERUSER': {'type': bool, 'default': False},
|
||||||
},
|
},
|
||||||
|
|
||||||
'ARCHIVE_METHOD_TOGGLES': {
|
'ARCHIVE_METHOD_TOGGLES': {
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
__package__ = 'archivebox.core'
|
__package__ = 'archivebox.core'
|
||||||
|
|
||||||
|
default_app_config = 'archivebox.core.apps.CoreConfig'
|
||||||
|
|
|
@ -5,3 +5,8 @@ class CoreConfig(AppConfig):
|
||||||
name = 'core'
|
name = 'core'
|
||||||
# WIP: broken by Django 3.1.2 -> 4.0 migration
|
# WIP: broken by Django 3.1.2 -> 4.0 migration
|
||||||
default_auto_field = 'django.db.models.UUIDField'
|
default_auto_field = 'django.db.models.UUIDField'
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
from .auth import register_signals
|
||||||
|
|
||||||
|
register_signals()
|
||||||
|
|
13
archivebox/core/auth.py
Normal file
13
archivebox/core/auth.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
from django.conf import settings
|
||||||
|
from ..config import (
|
||||||
|
LDAP
|
||||||
|
)
|
||||||
|
|
||||||
|
def register_signals():
|
||||||
|
|
||||||
|
if LDAP:
|
||||||
|
import django_auth_ldap.backend
|
||||||
|
from .auth_ldap import create_user
|
||||||
|
|
||||||
|
django_auth_ldap.backend.populate_user.connect(create_user)
|
12
archivebox/core/auth_ldap.py
Normal file
12
archivebox/core/auth_ldap.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from ..config import (
|
||||||
|
LDAP_CREATE_SUPERUSER
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_user(sender, user=None, ldap_user=None, **kwargs):
|
||||||
|
|
||||||
|
if not user.id and LDAP_CREATE_SUPERUSER:
|
||||||
|
user.is_superuser = True
|
||||||
|
|
||||||
|
user.is_staff = True
|
||||||
|
print(f'[!] WARNING: Creating new user {user} based on LDAP user {ldap_user} (is_staff={user.is_staff}, is_superuser={user.is_superuser})')
|
Loading…
Reference in a new issue