diff --git a/.gitignore b/.gitignore index d859bad28..c6ba9ef97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.pyc /netbox/netbox/configuration.py /netbox/netbox/ldap_config.py +/netbox/netbox/saml_config.py /netbox/reports/* !/netbox/reports/__init__.py /netbox/static diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index a85a5d78e..e64d76f35 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -108,6 +108,27 @@ if LDAP_CONFIGURED: "netbox/ldap_config.py to disable LDAP." ) +# Attempt to import SAML configuration if it has been defined = False +try: + from netbox.saml_config import * + SAML_CONFIGURED = True +except ImportError: + SAML_CONFIGURED = False + +# SAML configuration (optional) +if SAML_CONFIGURED: + try: + import django_saml2_auth + # Enable logging for django_auth_ldap + saml_logger = logging.getLogger('django_auth_saml') + saml_logger.addHandler(logging.StreamHandler()) + saml_logger.setLevel(logging.DEBUG) + except ImportError: + raise ImproperlyConfigured( + "SAML authentication has been configured, but django_saml2_auth is not installed. You can remove " + "netbox/saml_config.py to disable SAML." + ) + # Database configuration.DATABASE.update({'ENGINE': 'django.db.backends.postgresql'}) DATABASES = { @@ -175,6 +196,10 @@ INSTALLED_APPS = [ if WEBHOOKS_ENABLED: INSTALLED_APPS.append('django_rq') +# Only load django_saml2_auth if it is configured +if SAML_CONFIGURED: + INSTALLED_APPS.append('django_saml2_auth') + # Middleware MIDDLEWARE = ( 'debug_toolbar.middleware.DebugToolbarMiddleware', diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index 45c99beb9..ff6716c6e 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -67,6 +67,12 @@ if settings.WEBHOOKS_ENABLED: url(r'^admin/webhook-backend-status/', include('django_rq.urls')), ] +if settings.SAML_CONFIGURED: + import django_saml2_auth.views + _patterns += [ + url(r'^saml2_auth/', include('django_saml2_auth.urls')), + ] + if settings.DEBUG: import debug_toolbar _patterns += [