summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjschneider <jschneider@3ed937ae-f919-0410-9a43-8e6f19e4ba6e>2009-09-17 11:48:45 (GMT)
committerjschneider <jschneider@3ed937ae-f919-0410-9a43-8e6f19e4ba6e>2009-09-17 11:48:45 (GMT)
commit08d498e6aa3326210495ff45eb366b0d347cea79 (patch)
tree1470d4486a5e8d15e2219cab014d6b22619ca464
parent033ff593d82aa2d107d7b10e971619a9bf84d232 (diff)
downloadlarpe-08d498e6aa3326210495ff45eb366b0d347cea79.zip
larpe-08d498e6aa3326210495ff45eb366b0d347cea79.tar.gz
larpe-08d498e6aa3326210495ff45eb366b0d347cea79.tar.bz2
Fix site authentification plugins management
* larpe/plugins/site_authentication_plugins.py: New site authentification plugin management git-svn-id: svn+ssh://labs.libre-entreprise.org/svnroot/larpe@474 3ed937ae-f919-0410-9a43-8e6f19e4ba6e
-rw-r--r--larpe/trunk/larpe/admin/hosts.ptl3
-rw-r--r--larpe/trunk/larpe/plugins/__init__.py3
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/agirhe.py8
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py7
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/concerto.py7
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/egroupware.py7
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication/sympa.py7
-rw-r--r--larpe/trunk/larpe/plugins/site_authentication_plugins.py28
-rw-r--r--larpe/trunk/larpe/site_authentication.ptl15
9 files changed, 56 insertions, 29 deletions
diff --git a/larpe/trunk/larpe/admin/hosts.ptl b/larpe/trunk/larpe/admin/hosts.ptl
index e4a5fff..06376cf 100644
--- a/larpe/trunk/larpe/admin/hosts.ptl
+++ b/larpe/trunk/larpe/admin/hosts.ptl
@@ -21,6 +21,7 @@ from larpe.admin.liberty_utils import *
from larpe.admin.apache import write_apache2_vhosts
from larpe.admin.forms_prefill import FormsDirectory
from larpe.Defaults import OUTPUT_FILTER_BASE
+from larpe.plugins import site_authentication_plugins
def check_basic_configuration(form):
get_publisher().reload_cfg()
@@ -1036,7 +1037,7 @@ back and check your settings.''') % { 'finish': _('Finish') }
# Default authentication mode
self.host.auth_mode = 'form'
- self.host.site_authentication_plugin = site_authentication.guess_site_authentication_class(page)
+ self.host.site_authentication_plugin = site_authentication_plugins.auto_detect(page)
self.parse_frames(page)
self.parse_forms(page)
if self.host.auth_form is not None:
diff --git a/larpe/trunk/larpe/plugins/__init__.py b/larpe/trunk/larpe/plugins/__init__.py
index e69de29..0233184 100644
--- a/larpe/trunk/larpe/plugins/__init__.py
+++ b/larpe/trunk/larpe/plugins/__init__.py
@@ -0,0 +1,3 @@
+from larpe.plugins.site_authentication_plugins import SiteAuthenticationPlugins
+
+site_authentication_plugins = SiteAuthenticationPlugins()
diff --git a/larpe/trunk/larpe/plugins/site_authentication/agirhe.py b/larpe/trunk/larpe/plugins/site_authentication/agirhe.py
index e131e95..d3c0f2b 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/agirhe.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/agirhe.py
@@ -8,9 +8,10 @@ from qommon.errors import ConnectionError
from qommon import get_logger
from larpe.qommon.misc import http_get_page
-import site_authentication
+from larpe.plugins import site_authentication_plugins
+from larpe.site_authentication import SiteAuthentication
-class AgirheSiteAuthentication(site_authentication.SiteAuthentication):
+class AgirheSiteAuthentication(SiteAuthentication):
plugin_name = 'agirhe'
def auto_detect_site(cls, html_doc):
@@ -138,5 +139,4 @@ class AgirheSiteAuthentication(site_authentication.SiteAuthentication):
except IndexError:
continue
-site_authentication.register_site_authentication_class(AgirheSiteAuthentication)
-
+site_authentication_plugins.register(AgirheSiteAuthentication)
diff --git a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
index 0d706da..d671ab3 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/ciril_net_rh.py
@@ -2,9 +2,10 @@ import re
from quixote import redirect
-import site_authentication
+from larpe.plugins import site_authentication_plugins
+from larpe.site_authentication import SiteAuthentication
-class CirilSiteAuthentication(site_authentication.SiteAuthentication):
+class CirilSiteAuthentication(SiteAuthentication):
plugin_name = 'ciril'
def auto_detect_site(cls, html_doc):
@@ -34,5 +35,5 @@ class CirilSiteAuthentication(site_authentication.SiteAuthentication):
return success, return_content
-site_authentication.register_site_authentication_class(CirilSiteAuthentication)
+site_authentication_plugins.register(CirilSiteAuthentication)
diff --git a/larpe/trunk/larpe/plugins/site_authentication/concerto.py b/larpe/trunk/larpe/plugins/site_authentication/concerto.py
index 0e60acf..83dcae7 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/concerto.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/concerto.py
@@ -5,9 +5,10 @@ from quixote import get_request, get_response, get_session
from qommon.misc import http_post_request
from qommon import get_logger
-import site_authentication
+from larpe.plugins import site_authentication_plugins
+from larpe.site_authentication import SiteAuthentication
-class ConcertoSiteAuthentication(site_authentication.SiteAuthentication):
+class ConcertoSiteAuthentication(SiteAuthentication):
plugin_name = 'concerto'
def auto_detect_site(cls, html_doc):
@@ -84,5 +85,5 @@ class ConcertoSiteAuthentication(site_authentication.SiteAuthentication):
else:
return response.status, data
-site_authentication.register_site_authentication_class(ConcertoSiteAuthentication)
+site_authentication_plugins.register(ConcertoSiteAuthentication)
diff --git a/larpe/trunk/larpe/plugins/site_authentication/egroupware.py b/larpe/trunk/larpe/plugins/site_authentication/egroupware.py
index bf0179a..9b58634 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/egroupware.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/egroupware.py
@@ -6,9 +6,10 @@ from quixote import get_request, get_response, get_session
from qommon.misc import http_post_request, http_get_page
from qommon import get_logger
-import site_authentication
+from larpe.plugins import site_authentication_plugins
+from larpe.site_authentication import SiteAuthentication
-class EgroupwareSiteAuthentication(site_authentication.SiteAuthentication):
+class EgroupwareSiteAuthentication(SiteAuthentication):
plugin_name = 'egroupware'
def auto_detect_site(cls, html_doc):
@@ -86,5 +87,5 @@ class EgroupwareSiteAuthentication(site_authentication.SiteAuthentication):
url, headers, self.host.use_proxy)
return data
-site_authentication.register_site_authentication_class(EgroupwareSiteAuthentication)
+site_authentication_plugins.register(EgroupwareSiteAuthentication)
diff --git a/larpe/trunk/larpe/plugins/site_authentication/sympa.py b/larpe/trunk/larpe/plugins/site_authentication/sympa.py
index 9e96e42..734ba23 100644
--- a/larpe/trunk/larpe/plugins/site_authentication/sympa.py
+++ b/larpe/trunk/larpe/plugins/site_authentication/sympa.py
@@ -3,9 +3,10 @@ import re
from quixote import get_response, redirect
from quixote.html import htmltext
-import site_authentication
+from larpe.plugins import site_authentication_plugins
+from larpe.site_authentication import SiteAuthentication
-class SympaSiteAuthentication(site_authentication.SiteAuthentication):
+class SympaSiteAuthentication(SiteAuthentication):
plugin_name = 'sympa'
def auto_detect_site(cls, html_doc):
@@ -41,4 +42,4 @@ class SympaSiteAuthentication(site_authentication.SiteAuthentication):
return success, return_content
-site_authentication.register_site_authentication_class(SympaSiteAuthentication)
+site_authentication_plugins.register(SympaSiteAuthentication)
diff --git a/larpe/trunk/larpe/plugins/site_authentication_plugins.py b/larpe/trunk/larpe/plugins/site_authentication_plugins.py
new file mode 100644
index 0000000..fd5ba11
--- /dev/null
+++ b/larpe/trunk/larpe/plugins/site_authentication_plugins.py
@@ -0,0 +1,28 @@
+
+class SiteAuthenticationPlugins:
+ """ This class manages the plugins for site authentification """
+
+ def __init__(self):
+ self.site_authentication_classes = dict()
+
+ def register(self, klass):
+ """ Register a custom SiteAuthentification instance """
+ self.site_authentication_classes[klass.plugin_name] = klass
+
+ def get(self, plugin_name):
+ """ Return a custom SiteAuthentification instance """
+ if self.site_authentication_classes.has_key(plugin_name):
+ return self.site_authentication_classes[plugin_name]
+ else:
+ return None
+
+ def auto_detect(self, html_doc):
+ """
+ Try to find automatically the right plugin name
+ Return the plugin name or None
+ """
+ for name, klass in self.site_authentication_classes.iteritems():
+ if klass.auto_detect_site(html_doc):
+ return klass.plugin_name
+ return None
+
diff --git a/larpe/trunk/larpe/site_authentication.ptl b/larpe/trunk/larpe/site_authentication.ptl
index 748b9c6..3343b02 100644
--- a/larpe/trunk/larpe/site_authentication.ptl
+++ b/larpe/trunk/larpe/site_authentication.ptl
@@ -19,6 +19,8 @@ from qommon.errors import ConnectionError, ConfigurationError, LoginError
from qommon.misc import http_post_request, http_get_page
from qommon.template import *
+from larpe.plugins import site_authentication_plugins
+
import misc
from users import User
from federations import Federation
@@ -309,19 +311,8 @@ class SiteAuthentication:
federation.remove_name_identifier(user.name_identifiers[0])
federation.store()
-site_authentication_classes = {}
-
-def register_site_authentication_class(klass):
- site_authentication_classes[klass.plugin_name] = klass
-
-def guess_site_authentication_class(html_doc):
- for name, klass in site_authentication_classes.iteritems():
- if klass.auto_detect_site(html_doc):
- return klass.plugin_name
- return None
-
def get_site_authentication(host):
if host.site_authentication_plugin is None:
return SiteAuthentication(host)
- return site_authentication_classes[host.site_authentication_plugin](host)
+ return site_authentication_plugins.get(host.site_authentication_plugin)(host)