def getAuthPlugins(): ''' Load all the authentication plugins. ''' if getAuthPlugins.__cachePlugins == None: pluginsPath = hlm_application.getPath() + '/libs/auth' regex = re.compile('^hlma_([a-zA-Z0-9_]+).py$') plugins = [] allProviders = {} for item in os.listdir(pluginsPath): if os.path.isfile(pluginsPath + '/' + item): match = regex.search(item) if match != None: try: pluginModule = hlm_plugin.load(item[:-3], pluginsPath, 'auth') pluginModule.pluginName = match.group(1) # Compute the supported providers, supported SSIDs etc pluginProviders = pluginModule.getSupportedProviders() pluginSSIDs = set() for provider in pluginProviders: pluginSSIDs = pluginSSIDs.union( pluginProviders[provider]) pluginModule.supportedSSIDs = list(pluginSSIDs) # Merge the supported plugin providers/SSIDs in the global cache for provider in pluginProviders: if pluginProviders[provider] != []: if provider not in allProviders: allProviders[provider] = set() allProviders[provider] = allProviders[ provider].union(pluginProviders[provider]) # Add the plugin plugins.append(pluginModule) except SystemExit: raise except BaseException as exc: if __WARNING__: logWarning( _('Invalid authentication plugin {0}: {1}'). format(quote(item), exc)) # Normalize the providers list if allProviders == {}: raise FatalError( _('No authentication plugin available / no supported service provider, exiting.' )) for provider in allProviders: allProviders[provider] = list(allProviders[provider]) allProviders[provider].sort() # Cache the results getAuthPlugins.__cachePlugins = plugins getAuthPlugins.__cacheProviders = allProviders return getAuthPlugins.__cachePlugins
def install(wrapperVars, moduleName): ''' Import moduleName and install into the wrapper module every public variable/function/class it defines. Modules imported by moduleName are not installed into the wrapper. Public items are the ones NOT starting with an underscore. Usage: from hotspot_login_manager.libs.core import hlm_platform hlm_platform.install(vars(), 'module') ''' moduleObject = hlm_plugin.load('hlmp_' + moduleName, _platformPluginsPath, 'platform') moduleVars = vars(moduleObject) for varName in moduleVars: varObject = moduleVars[varName] if (not type(varObject) is types.ModuleType) and (not varName.startswith('_')): wrapperVars[varName] = varObject
def getAuthPlugins(): ''' Load all the authentication plugins. ''' if getAuthPlugins.__cachePlugins == None: pluginsPath = hlm_application.getPath() + '/libs/auth' regex = re.compile('^hlma_([a-zA-Z0-9_]+).py$') plugins = [] allProviders = {} for item in os.listdir(pluginsPath): if os.path.isfile(pluginsPath + '/' + item): match = regex.search(item) if match != None: try: pluginModule = hlm_plugin.load(item[:-3], pluginsPath, 'auth') pluginModule.pluginName = match.group(1) # Compute the supported providers, supported SSIDs etc pluginProviders = pluginModule.getSupportedProviders() pluginSSIDs = set() for provider in pluginProviders: pluginSSIDs = pluginSSIDs.union(pluginProviders[provider]) pluginModule.supportedSSIDs = list(pluginSSIDs) # Merge the supported plugin providers/SSIDs in the global cache for provider in pluginProviders: if pluginProviders[provider] != []: if provider not in allProviders: allProviders[provider] = set() allProviders[provider] = allProviders[provider].union(pluginProviders[provider]) # Add the plugin plugins.append(pluginModule) except SystemExit: raise except BaseException as exc: if __WARNING__: logWarning(_('Invalid authentication plugin {0}: {1}').format(quote(item), exc)) # Normalize the providers list if allProviders == {}: raise FatalError(_('No authentication plugin available / no supported service provider, exiting.')) for provider in allProviders: allProviders[provider] = list(allProviders[provider]) allProviders[provider].sort() # Cache the results getAuthPlugins.__cachePlugins = plugins getAuthPlugins.__cacheProviders = allProviders return getAuthPlugins.__cachePlugins
def install(wrapperVars, moduleName): ''' Import moduleName and install into the wrapper module every public variable/function/class it defines. Modules imported by moduleName are not installed into the wrapper. Public items are the ones NOT starting with an underscore. Usage: from hotspot_login_manager.libs.core import hlm_platform hlm_platform.install(vars(), 'module') ''' moduleObject = hlm_plugin.load('hlmp_' + moduleName, _platformPluginsPath, 'platform') moduleVars = vars(moduleObject) for varName in moduleVars: varObject = moduleVars[varName] if (not type(varObject) is types.ModuleType) and ( not varName.startswith('_')): wrapperVars[varName] = varObject