From 2cd567d13bce9adb71123ca188398cf703e2ba72 Mon Sep 17 00:00:00 2001
From: Emmanuel Cazenave <ecazenave@entrouvert.com>
Date: Mon, 22 Jun 2020 16:19:22 +0200
Subject: [PATCH] remove authentic2_auth_cas from plugin system (#44329)

---
 setup.py                           |  1 -
 src/authentic2/settings.py         |  1 +
 src/authentic2/urls.py             | 10 ++++++++
 src/authentic2_idp_cas/__init__.py | 34 +-------------------------
 src/authentic2_idp_cas/apps.py     | 38 ++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 34 deletions(-)
 create mode 100644 src/authentic2_idp_cas/apps.py

diff --git a/setup.py b/setup.py
index 74d61806..b9194cdd 100755
--- a/setup.py
+++ b/setup.py
@@ -169,7 +169,6 @@ setup(name="authentic2",
       },
       entry_points={
           'authentic2.plugin': [
-              'authentic2-idp-cas = authentic2_idp_cas:Plugin',
               'authentic2-idp-oidc = authentic2_idp_oidc:Plugin',
               'authentic2-provisionning-ldap = authentic2_provisionning_ldap:Plugin',
               'authentic2-auth-fc = authentic2_auth_fc:Plugin',
diff --git a/src/authentic2/settings.py b/src/authentic2/settings.py
index 833c9f0c..355b278f 100644
--- a/src/authentic2/settings.py
+++ b/src/authentic2/settings.py
@@ -131,6 +131,7 @@ INSTALLED_APPS = (
     'mellon',
     'authentic2_auth_saml',
     'authentic2_auth_oidc',
+    'authentic2_idp_cas',
     'authentic2.nonce',
     'authentic2.saml',
     'authentic2.idp',
diff --git a/src/authentic2/urls.py b/src/authentic2/urls.py
index fa002184..ad9c7b15 100644
--- a/src/authentic2/urls.py
+++ b/src/authentic2/urls.py
@@ -27,6 +27,7 @@ from . import plugins, views
 from authentic2.decorators import setting_enabled, required, lasso_required
 import authentic2_auth_oidc.urls
 import authentic2_auth_saml.urls
+import authentic2_idp_cas.app_settings
 import authentic2.idp.saml.app_settings
 
 
@@ -157,7 +158,16 @@ authentic2_idp_saml_urls = required(
     ),
     [url(r'^idp/saml2/', include('authentic2.idp.saml.urls'))]
 )
+
+authentic2_idp_cas_urls = required(
+    (
+        setting_enabled('ENABLE', settings=authentic2_idp_cas.app_settings),
+    ),
+    [url(r'^idp/cas/', include('authentic2_idp_cas.urls'))]
+)
+
 urlpatterns = (
+    authentic2_idp_cas_urls +
     authentic2_auth_oidc.urls.urlpatterns +
     authentic2_auth_saml.urls.urlpatterns +
     authentic2_idp_saml_urls +
diff --git a/src/authentic2_idp_cas/__init__.py b/src/authentic2_idp_cas/__init__.py
index 7e0b93b3..311d07e5 100644
--- a/src/authentic2_idp_cas/__init__.py
+++ b/src/authentic2_idp_cas/__init__.py
@@ -14,36 +14,4 @@
 # 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/>.
 
-from django.template.loader import render_to_string
-
-from .constants import SESSION_CAS_LOGOUTS
-
-
-class Plugin(object):
-    def get_before_urls(self):
-        from . import app_settings
-        from django.conf.urls import include, url
-        from authentic2.decorators import setting_enabled, required
-
-        return required(
-            (
-                setting_enabled('ENABLE', settings=app_settings),
-            ),
-            [url(r'^idp/cas/', include(__name__ + '.urls'))])
-
-    def get_apps(self):
-        return [__name__]
-
-    def logout_list(self, request):
-        fragments = []
-        cas_logouts = request.session.get(SESSION_CAS_LOGOUTS, [])
-        for name, url, use_iframe, use_iframe_timeout in cas_logouts:
-            ctx = {
-                'needs_iframe': use_iframe,
-                'name': name,
-                'url': url,
-                'iframe_timeout': use_iframe_timeout,
-            }
-            content = render_to_string('authentic2_idp_cas/logout_fragment.html', ctx)
-            fragments.append(content)
-        return fragments
+default_app_config = 'authentic2_idp_cas.apps.AppConfig'
diff --git a/src/authentic2_idp_cas/apps.py b/src/authentic2_idp_cas/apps.py
new file mode 100644
index 00000000..a4836a6b
--- /dev/null
+++ b/src/authentic2_idp_cas/apps.py
@@ -0,0 +1,38 @@
+# authentic2 - versatile identity manager
+# Copyright (C) 2010-2020 Entr'ouvert
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# 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/>.
+
+import django.apps
+from django.template.loader import render_to_string
+
+from .constants import SESSION_CAS_LOGOUTS
+
+
+class AppConfig(django.apps.AppConfig):
+    name = 'authentic2_idp_cas'
+
+    def logout_list(self, request):
+        fragments = []
+        cas_logouts = request.session.get(SESSION_CAS_LOGOUTS, [])
+        for name, url, use_iframe, use_iframe_timeout in cas_logouts:
+            ctx = {
+                'needs_iframe': use_iframe,
+                'name': name,
+                'url': url,
+                'iframe_timeout': use_iframe_timeout,
+            }
+            content = render_to_string('authentic2_idp_cas/logout_fragment.html', ctx)
+            fragments.append(content)
+        return fragments
-- 
2.20.1

