Commit a535186e authored by Łukasz Nowak's avatar Łukasz Nowak

Generalise class to allow more backends.

parent 2948a479
...@@ -54,14 +54,11 @@ def addVifibFacebookServerExtractionPlugin(dispatcher, id, title=None, REQUEST=N ...@@ -54,14 +54,11 @@ def addVifibFacebookServerExtractionPlugin(dispatcher, id, title=None, REQUEST=N
'VifibFacebookServerExtractionPlugin+added.' 'VifibFacebookServerExtractionPlugin+added.'
% dispatcher.absolute_url()) % dispatcher.absolute_url())
class VifibFacebookServerExtractionPlugin(BasePlugin): class VifibCookieHashExtractionPlugin(BasePlugin):
""" """
Plugin to authenicate as machines. Plugin to authenicate as machines.
""" """
meta_type = "Vifib Facebook Server Extraction Plugin"
# cache_fatory_name proposal to begin configurable
cache_factory_name = 'facebook_server_auth_token_cache_factory'
security = ClassSecurityInfo() security = ClassSecurityInfo()
def __init__(self, id, title=None): def __init__(self, id, title=None):
...@@ -88,13 +85,6 @@ class VifibFacebookServerExtractionPlugin(BasePlugin): ...@@ -88,13 +85,6 @@ class VifibFacebookServerExtractionPlugin(BasePlugin):
raise KeyError raise KeyError
return cache_factory return cache_factory
def setFacebookToken(self, key, body):
cache_factory = self._getCacheFactory()
cache_duration = cache_factory.cache_duration
for cache_plugin in cache_factory.getCachePluginList():
cache_plugin.set(key, DEFAULT_CACHE_SCOPE,
body, cache_duration=cache_duration)
def getKey(self, key): def getKey(self, key):
cache_factory = self._getCacheFactory() cache_factory = self._getCacheFactory()
for cache_plugin in cache_factory.getCachePluginList(): for cache_plugin in cache_factory.getCachePluginList():
...@@ -108,16 +98,16 @@ class VifibFacebookServerExtractionPlugin(BasePlugin): ...@@ -108,16 +98,16 @@ class VifibFacebookServerExtractionPlugin(BasePlugin):
#################################### ####################################
security.declarePrivate('extractCredentials') security.declarePrivate('extractCredentials')
def extractCredentials(self, request): def extractCredentials(self, request):
""" Extract facebook credentials from the request header. """ """ Extract CookieHash credentials from the request header. """
creds = {} creds = {}
facebook_cookie = request.get('__ac_facebook_hash') cookie_hash = request.get(self.cookie_name)
if facebook_cookie is not None: if cookie_hash is not None:
try: try:
facebook_dict = self.getKey(facebook_cookie) user_dict = self.getKey(cookie_hash)
except KeyError: except KeyError:
return DumbHTTPExtractor().extractCredentials(request) return DumbHTTPExtractor().extractCredentials(request)
if 'login' in facebook_dict: if 'login' in user_dict:
creds['external_login'] = facebook_dict['login'] creds['external_login'] = user_dict['login']
creds['remote_host'] = request.get('REMOTE_HOST', '') creds['remote_host'] = request.get('REMOTE_HOST', '')
try: try:
creds['remote_address'] = request.getClientAddr() creds['remote_address'] = request.getClientAddr()
...@@ -126,10 +116,10 @@ class VifibFacebookServerExtractionPlugin(BasePlugin): ...@@ -126,10 +116,10 @@ class VifibFacebookServerExtractionPlugin(BasePlugin):
return creds return creds
return DumbHTTPExtractor().extractCredentials(request) return DumbHTTPExtractor().extractCredentials(request)
manage_editVifibFacebookServerExtractionPluginForm = PageTemplateFile( class VifibFacebookServerExtractionPlugin(VifibCookieHashExtractionPlugin):
'www/Vifib_editVifibFacebookServerExtractionPlugin', cache_factory_name = 'facebook_server_auth_token_cache_factory'
globals(), cookie_name = '__ac_facebook_hash'
__name__='manage_editVifibFacebookServerExtractionPluginForm') meta_type = "Vifib Facebook Server Extraction Plugin"
#List implementation of class #List implementation of class
classImplements( VifibFacebookServerExtractionPlugin, classImplements( VifibFacebookServerExtractionPlugin,
......
...@@ -43,7 +43,7 @@ from Products.PluggableAuthService.PluggableAuthService import registerMultiPlug ...@@ -43,7 +43,7 @@ from Products.PluggableAuthService.PluggableAuthService import registerMultiPlug
import VifibMachineAuthenticationPlugin import VifibMachineAuthenticationPlugin
import VifibShadowAuthenticationPlugin import VifibShadowAuthenticationPlugin
import VifibFacebookServerExtractionPlugin import VifibCookieHashExtractionPlugin
def initialize(context): def initialize(context):
import Document import Document
...@@ -70,11 +70,11 @@ def initialize(context): ...@@ -70,11 +70,11 @@ def initialize(context):
, icon='www/portal.gif' , icon='www/portal.gif'
) )
context.registerClass( VifibFacebookServerExtractionPlugin.VifibFacebookServerExtractionPlugin context.registerClass( VifibCookieHashExtractionPlugin.VifibFacebookServerExtractionPlugin
, permission=ManageUsers , permission=ManageUsers
, constructors=( , constructors=(
VifibFacebookServerExtractionPlugin.manage_addVifibFacebookServerExtractionPluginForm, VifibCookieHashExtractionPlugin.manage_addVifibFacebookServerExtractionPluginForm,
VifibFacebookServerExtractionPlugin.addVifibFacebookServerExtractionPlugin, ) VifibCookieHashExtractionPlugin.addVifibFacebookServerExtractionPlugin, )
, visibility=None , visibility=None
, icon='www/portal.gif' , icon='www/portal.gif'
) )
...@@ -82,4 +82,4 @@ def initialize(context): ...@@ -82,4 +82,4 @@ def initialize(context):
registerMultiPlugin(VifibMachineAuthenticationPlugin.VifibMachineAuthenticationPlugin.meta_type) registerMultiPlugin(VifibMachineAuthenticationPlugin.VifibMachineAuthenticationPlugin.meta_type)
registerMultiPlugin(VifibShadowAuthenticationPlugin.VifibShadowAuthenticationPlugin.meta_type) registerMultiPlugin(VifibShadowAuthenticationPlugin.VifibShadowAuthenticationPlugin.meta_type)
registerMultiPlugin(VifibFacebookServerExtractionPlugin.VifibFacebookServerExtractionPlugin.meta_type) registerMultiPlugin(VifibCookieHashExtractionPlugin.VifibFacebookServerExtractionPlugin.meta_type)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment