do no rely on pkg_resources to get loaded (#48762)

This commit is contained in:
Emmanuel Cazenave 2020-11-23 17:31:08 +01:00 committed by Benjamin Dauvergne
parent d351e0c1c0
commit 78d2be055a
5 changed files with 40 additions and 18 deletions

9
README
View File

@ -9,8 +9,13 @@ The django-kerberos_ project is used as a basis for this plugin.
Install Install
------- -------
You just have to install the package in your virtualenv and relaunch, it will You just have to install the package in your virtualenv and register the plugin :
be automatically loaded by authentic2.
import authentic2_auth_kerberos
INSTALLED_APPS, TENANT_APPS, AUTHENTICATION_BACKENDS, AUTH_FRONTENDS = authentic2_auth_kerberos.register(
INSTALLED_APPS, TENANT_APPS, AUTHENTICATION_BACKENDS, AUTH_FRONTENDS
)
You must define the KRB5_KTNAME environment to the path of a keytab file You must define the KRB5_KTNAME environment to the path of a keytab file
containing the key for your service principal. See django-kerberos_ containing the key for your service principal. See django-kerberos_

View File

@ -73,9 +73,4 @@ setup(
'authentic2', 'authentic2',
'django-kerberos', 'django-kerberos',
], ],
entry_points={
'authentic2.plugin': [
'authentic2-auth-kerberos = authentic2_auth_kerberos:Plugin',
],
},
cmdclass={'sdist': version_sdist}) cmdclass={'sdist': version_sdist})

View File

@ -1,17 +1,22 @@
default_app_config = 'authentic2_auth_kerberos.apps.Authentic2AuthKerberosConfig' default_app_config = 'authentic2_auth_kerberos.apps.Authentic2AuthKerberosConfig'
class Plugin(object): def register(installed_apps, tenant_apps, authentication_backends, auth_frontends):
def get_before_urls(self): apps = []
from . import urls for app in ('authentic2_auth_kerberos', 'django_kerberos'):
return urls.urlpatterns if app not in installed_apps:
apps.append(app)
if apps:
installed_apps += tuple(apps)
tenant_apps += tuple(apps)
def get_apps(self): for backend in [
return [__name__, 'django_kerberos'] 'authentic2_auth_kerberos.backends.A2LdapKerberosBackend',
'authentic2_auth_kerberos.backends.A2KerberosBackend']:
if backend not in authentication_backends:
authentication_backends += (backend,)
def get_authentication_backends(self): if 'authentic2_auth_kerberos.authenticators.KerberosAuthenticator' not in auth_frontends:
return ['authentic2_auth_kerberos.backends.A2LdapKerberosBackend', auth_frontends += ('authentic2_auth_kerberos.authenticators.KerberosAuthenticator',)
'authentic2_auth_kerberos.backends.A2KerberosBackend']
def get_authenticators(self): return installed_apps, tenant_apps, authentication_backends, auth_frontends
return ['authentic2_auth_kerberos.authenticators.KerberosAuthenticator']

View File

@ -8,3 +8,12 @@ class Authentic2AuthKerberosConfig(AppConfig):
def ready(self): def ready(self):
# patch authentic2.backends.ldap_backend.LDAPBackend for keys specific to Kerberos support # patch authentic2.backends.ldap_backend.LDAPBackend for keys specific to Kerberos support
from . import backends from . import backends
def get_a2_plugin(self):
return Plugin()
class Plugin(object):
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -1,4 +1,6 @@
import os import os
import authentic2_auth_kerberos
LANGUAGE_CODE = 'en' LANGUAGE_CODE = 'en'
DATABASES = { DATABASES = {
@ -17,3 +19,9 @@ if 'postgres' in DATABASES['default']['ENGINE']:
ALLOWED_HOSTS = ['localhost'] ALLOWED_HOSTS = ['localhost']
A2_AUTH_KERBEROS_ENABLE = True A2_AUTH_KERBEROS_ENABLE = True
TENANT_APPS = []
INSTALLED_APPS, TENANT_APPS, AUTHENTICATION_BACKENDS, AUTH_FRONTENDS = authentic2_auth_kerberos.register(
INSTALLED_APPS, TENANT_APPS, AUTHENTICATION_BACKENDS, AUTH_FRONTENDS
)