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
This commit is contained in:
parent
033ff593d8
commit
08d498e6aa
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from larpe.plugins.site_authentication_plugins import SiteAuthenticationPlugins
|
||||
|
||||
site_authentication_plugins = SiteAuthenticationPlugins()
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
Reference in New Issue