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
-------
You just have to install the package in your virtualenv and relaunch, it will
be automatically loaded by authentic2.
You just have to install the package in your virtualenv and register the plugin :
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
containing the key for your service principal. See django-kerberos_

View File

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

View File

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

View File

@ -8,3 +8,12 @@ class Authentic2AuthKerberosConfig(AppConfig):
def ready(self):
# patch authentic2.backends.ldap_backend.LDAPBackend for keys specific to Kerberos support
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 authentic2_auth_kerberos
LANGUAGE_CODE = 'en'
DATABASES = {
@ -17,3 +19,9 @@ if 'postgres' in DATABASES['default']['ENGINE']:
ALLOWED_HOSTS = ['localhost']
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
)