From dac83e2f0eeab798bd9178f1fdcd2fca0827faab Mon Sep 17 00:00:00 2001
From: Emmanuel Cazenave <ecazenave@entrouvert.com>
Date: Mon, 22 Jun 2020 14:54:25 +0200
Subject: [PATCH] remove authentic2_auth_saml from plugin system (#44320)

---
 setup.py                             |  1 -
 src/authentic2/settings.py           |  8 ++++++--
 src/authentic2/urls.py               |  3 ++-
 src/authentic2_auth_saml/__init__.py | 23 -----------------------
 src/authentic2_auth_saml/backends.py |  8 ++++++++
 5 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/setup.py b/setup.py
index c0662d0c..bede39a1 100755
--- a/setup.py
+++ b/setup.py
@@ -169,7 +169,6 @@ setup(name="authentic2",
       },
       entry_points={
           'authentic2.plugin': [
-              'authentic2-auth-saml = authentic2_auth_saml:Plugin',
               'authentic2-auth-oidc = authentic2_auth_oidc:Plugin',
               'authentic2-idp-cas = authentic2_idp_cas:Plugin',
               'authentic2-idp-oidc = authentic2_idp_oidc:Plugin',
diff --git a/src/authentic2/settings.py b/src/authentic2/settings.py
index c1b00de6..a192dabb 100644
--- a/src/authentic2/settings.py
+++ b/src/authentic2/settings.py
@@ -128,6 +128,8 @@ INSTALLED_APPS = (
     'django.contrib.humanize',
     'django_select2',
     'django_tables2',
+    'mellon',
+    'authentic2_auth_saml',
     'authentic2.nonce',
     'authentic2.saml',
     'authentic2.idp',
@@ -155,6 +157,7 @@ AUTHENTICATION_BACKENDS = (
     'authentic2.backends.ldap_backend.LDAPBackendPasswordLost',
     'authentic2.backends.models_backend.DummyModelBackend',
     'django_rbac.backends.DjangoRBACBackend',
+    'authentic2_auth_saml.backends.SAMLBackend',
 )
 AUTHENTICATION_BACKENDS = plugins.register_plugins_authentication_backends(AUTHENTICATION_BACKENDS)
 CSRF_FAILURE_VIEW = 'authentic2.views.csrf_failure_view'
@@ -173,8 +176,9 @@ ACCOUNT_ACTIVATION_DAYS = 2
 # Authentication settings
 ###########################
 AUTH_USER_MODEL = 'custom_user.User'
-AUTH_FRONTENDS = plugins.register_plugins_authenticators((
-    'authentic2.authenticators.LoginPasswordAuthenticator',))
+AUTH_FRONTENDS = ('authentic2_auth_saml.authenticators.SAMLAuthenticator',) + \
+    plugins.register_plugins_authenticators((
+        'authentic2.authenticators.LoginPasswordAuthenticator',))
 
 ###########################
 # RBAC settings
diff --git a/src/authentic2/urls.py b/src/authentic2/urls.py
index 2e084ef4..276ba837 100644
--- a/src/authentic2/urls.py
+++ b/src/authentic2/urls.py
@@ -25,6 +25,7 @@ from django.views.static import serve as media_serve
 
 from . import plugins, views
 from authentic2.decorators import setting_enabled, required, lasso_required
+import authentic2_auth_saml.urls
 import authentic2.idp.saml.app_settings
 
 
@@ -155,4 +156,4 @@ authentic2_idp_saml_urls = required(
     ),
     [url(r'^idp/saml2/', include('authentic2.idp.saml.urls'))]
 )
-urlpatterns = authentic2_idp_saml_urls + urlpatterns
+urlpatterns = authentic2_auth_saml.urls.urlpatterns + authentic2_idp_saml_urls + urlpatterns
diff --git a/src/authentic2_auth_saml/__init__.py b/src/authentic2_auth_saml/__init__.py
index 2e0c5eeb..0121e314 100644
--- a/src/authentic2_auth_saml/__init__.py
+++ b/src/authentic2_auth_saml/__init__.py
@@ -13,26 +13,3 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-
-class Plugin(object):
-    def get_before_urls(self):
-        from . import urls
-        return urls.urlpatterns
-
-    def get_apps(self):
-        return ['mellon', __name__]
-
-    def get_authentication_backends(self):
-        return ['authentic2_auth_saml.backends.SAMLBackend']
-
-    def get_authenticators(self):
-        return ['authentic2_auth_saml.authenticators.SAMLAuthenticator']
-
-    def redirect_logout_list(self, request, next_url=None):
-        from mellon.views import logout
-        if 'mellon_session' in request.session:
-            response = logout(request)
-            if 'Location' in response:
-                return [response['Location']]
-        return []
diff --git a/src/authentic2_auth_saml/backends.py b/src/authentic2_auth_saml/backends.py
index 93ea6083..31ab91be 100644
--- a/src/authentic2_auth_saml/backends.py
+++ b/src/authentic2_auth_saml/backends.py
@@ -38,3 +38,11 @@ class SAMLBackend(SAMLBackend):
 
         import lasso
         return lasso.SAML2_AUTHN_CONTEXT_PREVIOUS_SESSION
+
+    def redirect_logout_list(self, request, next_url=None):
+        from mellon.views import logout
+        if 'mellon_session' in request.session:
+            response = logout(request)
+            if 'Location' in response:
+                return [response['Location']]
+        return []
-- 
2.20.1

