diff --git a/README b/README index 28a765d..8c7644c 100644 --- a/README +++ b/README @@ -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_ diff --git a/setup.py b/setup.py index dc81cbf..a339462 100755 --- a/setup.py +++ b/setup.py @@ -73,9 +73,4 @@ setup( 'authentic2', 'django-kerberos', ], - entry_points={ - 'authentic2.plugin': [ - 'authentic2-auth-kerberos = authentic2_auth_kerberos:Plugin', - ], - }, cmdclass={'sdist': version_sdist}) diff --git a/src/authentic2_auth_kerberos/__init__.py b/src/authentic2_auth_kerberos/__init__.py index fee6255..b94d1b5 100644 --- a/src/authentic2_auth_kerberos/__init__.py +++ b/src/authentic2_auth_kerberos/__init__.py @@ -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 diff --git a/src/authentic2_auth_kerberos/apps.py b/src/authentic2_auth_kerberos/apps.py index 25b9654..abc0fb4 100644 --- a/src/authentic2_auth_kerberos/apps.py +++ b/src/authentic2_auth_kerberos/apps.py @@ -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 diff --git a/tests/settings.py b/tests/settings.py index e47edda..a4a5e72 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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 +)