From b6e73853afcf5742335a5a22653caaea0313cb7b Mon Sep 17 00:00:00 2001 From: chaoflow Date: Tue, 11 Nov 2008 13:20:45 +0000 Subject: [PATCH] paula: a bunch of stuff, all nice and beautiful and not solving the problem git-svn-id: https://svn.plone.org/svn/collective/paula/trunk@75485 db7f04ef-aaf3-0310-a811-c281ed44c4ad --- .../src/paula/pasplugins/configure.zcml | 3 +- .../src/paula/pasplugins/ftesting.zcml | 5 +- .../src/paula/pasplugins/integration.txt | 6 +- .../src/paula/pasplugins/plugins/auth.py | 64 +++++++++++++++++++--- .../src/paula/pasplugins/plugins/groups.py | 8 +-- .../src/paula/pasplugins/plugins/paucred.py | 3 +- .../src/paula/pasplugins/plugins/properties.py | 8 +-- .../profiles/default/componentregistry.xml | 2 +- .../src/paula/pasplugins/setuphandlers.py | 4 +- .../pasplugins/tests/fake_group_subscriber.py | 38 ------------- .../src/paula/pasplugins/tests/fake_pau_ap.py | 3 +- ...fake_prop_subscriber.py => fake_subscribers.py} | 20 ++++++- 12 files changed, 97 insertions(+), 67 deletions(-) delete mode 100644 paula.pasplugins/src/paula/pasplugins/tests/fake_group_subscriber.py rename paula.pasplugins/src/paula/pasplugins/tests/{fake_prop_subscriber.py => fake_subscribers.py} (77%) diff --git a/paula.pasplugins/src/paula/pasplugins/configure.zcml b/paula.pasplugins/src/paula/pasplugins/configure.zcml index b7ca42b..cbf7859 100644 --- a/paula.pasplugins/src/paula/pasplugins/configure.zcml +++ b/paula.pasplugins/src/paula/pasplugins/configure.zcml @@ -13,7 +13,8 @@ /> diff --git a/paula.pasplugins/src/paula/pasplugins/ftesting.zcml b/paula.pasplugins/src/paula/pasplugins/ftesting.zcml index e3936fe..e8e3ae7 100644 --- a/paula.pasplugins/src/paula/pasplugins/ftesting.zcml +++ b/paula.pasplugins/src/paula/pasplugins/ftesting.zcml @@ -5,15 +5,16 @@ diff --git a/paula.pasplugins/src/paula/pasplugins/integration.txt b/paula.pasplugins/src/paula/pasplugins/integration.txt index 33dfc34..bf03bd0 100644 --- a/paula.pasplugins/src/paula/pasplugins/integration.txt +++ b/paula.pasplugins/src/paula/pasplugins/integration.txt @@ -10,13 +10,13 @@ PAU is up and running with our real and fake plugins First of all, there should be a PAU and it should know about the credentials plugin: - >>> from zope.app.authentication.interfaces import \ - ... IPluggableAuthentication + >>> from zope.app.security.interfaces import \ + ... IAuthentication >>> from zope.app.authentication.interfaces import \ ... ICredentialsPlugin >>> from paula.pasplugins.plugins.paucred import CREDPLUG_NAME - >>> pau = getUtility(IPluggableAuthentication) + >>> pau = getUtility(IAuthentication) >>> CREDPLUG_NAME in pau.credentialsPlugins True diff --git a/paula.pasplugins/src/paula/pasplugins/plugins/auth.py b/paula.pasplugins/src/paula/pasplugins/plugins/auth.py index b9dd1de..f6b62ff 100644 --- a/paula.pasplugins/src/paula/pasplugins/plugins/auth.py +++ b/paula.pasplugins/src/paula/pasplugins/plugins/auth.py @@ -28,9 +28,10 @@ from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin from Products.PluggableAuthService.interfaces.plugins \ - import IAuthenticationPlugin + import IAuthenticationPlugin, IUserEnumerationPlugin +from Products.PlonePAS.interfaces.plugins import IUserIntrospection -from zope.app.authentication.interfaces import IPluggableAuthentication +from zope.app.security.interfaces import IAuthentication from zope.interface import implements, alsoProvides from zope.component import getUtility from zope.publisher.interfaces import IRequest @@ -51,7 +52,7 @@ def addAuthenticationPlugin( dispatcher, id, title=None, REQUEST=None ): REQUEST['RESPONSE'].redirect( '%s/manage_workspace' '?manage_tabs_message=' - 'paula.plonepas.AuthenticationPlugin+added.' + 'paula.pasplugins.AuthenticationPlugin+added.' % dispatcher.absolute_url()) @@ -60,7 +61,11 @@ class AuthenticationPlugin(BasePlugin): """ security = ClassSecurityInfo() - implements(IAuthenticationPlugin) + implements( + IAuthenticationPlugin, + IUserEnumerationPlugin, + IUserIntrospection, + ) meta_type = "Paula PAS Authentication Plugin" @@ -68,6 +73,8 @@ class AuthenticationPlugin(BasePlugin): self._id = self.id = id self.title = title + # IAuthenticationPlugin + # security.declarePrivate('authenticateCredentials') def authenticateCredentials(self, credentials): """ credentials -> (userid, login) @@ -90,8 +97,8 @@ class AuthenticationPlugin(BasePlugin): ... and x.has_key('login') \\ ... and x.has_key('password') \\ ... and p, - ... alsoProvides=(IPluggableAuthentication,)) - >>> provideUtility(au, IPluggableAuthentication) + ... alsoProvides=(IAuthentication,)) + >>> provideUtility(au, IAuthentication) our authentication plugin @@ -116,7 +123,7 @@ class AuthenticationPlugin(BasePlugin): >>> ap.authenticateCredentials(creds) is None True """ - pau = getUtility(IPluggableAuthentication) + pau = getUtility(IAuthentication) # pau expects something providing request # our fake credentials plugin is fine with a mapping @@ -132,4 +139,47 @@ class AuthenticationPlugin(BasePlugin): return None + # IUserEnumerationPlugin + # + security.declarePrivate( 'enumerateUsers' ) + def enumerateUsers( self + , id=None + , login=None + , exact_match=False + , sort_by=None + , max_results=None + , **kw + ): + return ({ + 'id': id, + 'login': id, + 'pluginid': self.getId(), + 'editurl': 'some fake url', + },) + + # IUserIntrospection + # + security.declarePrivate('getUserIds') + def getUserIds(self): + return ('fakelogin',) + + # IUserIntrospection + # + security.declarePrivate('getUserNames') + def getUserNames(self): + return ('fakelogin',) + + # IUserIntrospection + # + security.declarePrivate('getUsers') + def getUsers(self): + """ + Return a list of users + + XXX DON'T USE THIS, it will kill performance + """ + uf = getToolByName(self, 'acl_users') + return tuple([uf.getUserById(x) for x in self.getUserIds()]) + + InitializeClass( AuthenticationPlugin) diff --git a/paula.pasplugins/src/paula/pasplugins/plugins/groups.py b/paula.pasplugins/src/paula/pasplugins/plugins/groups.py index edf837d..b8fda36 100644 --- a/paula.pasplugins/src/paula/pasplugins/plugins/groups.py +++ b/paula.pasplugins/src/paula/pasplugins/plugins/groups.py @@ -31,7 +31,7 @@ from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin from Products.PluggableAuthService.interfaces.plugins \ import IGroupsPlugin -from zope.app.authentication.interfaces import IPluggableAuthentication +from zope.app.security.interfaces import IAuthentication from zope.app.security.interfaces import PrincipalLookupError from zope.component import getUtility from zope.interface import implements @@ -43,7 +43,7 @@ manage_addGroupsPluginForm = PageTemplateFile( def addGroupsPlugin( dispatcher, id, title=None, REQUEST=None ): - """Add a paula.plonepas GroupsPlugin to a PluggableAuthService. + """Add a paula.pasplugins GroupsPlugin to a PluggableAuthService. """ plugin = GroupsPlugin(id, title) dispatcher._setObject(plugin.getId(), plugin) @@ -52,7 +52,7 @@ def addGroupsPlugin( dispatcher, id, title=None, REQUEST=None ): REQUEST['RESPONSE'].redirect( '%s/manage_workspace' '?manage_tabs_message=' - 'paula.plonepas.GroupsPlugin+added.' + 'paula.pasplugins.GroupsPlugin+added.' % dispatcher.absolute_url()) @@ -79,7 +79,7 @@ class GroupsPlugin(BasePlugin): o May assign groups based on values in the REQUEST object, if present """ # get principal from pau - pau = getUtility(IPluggableAuthentication) + pau = getUtility(IAuthentication) try: p = pau.getPrincipal(principal.getId()) except PrincipalLookupError: diff --git a/paula.pasplugins/src/paula/pasplugins/plugins/paucred.py b/paula.pasplugins/src/paula/pasplugins/plugins/paucred.py index 960c24c..d6751b7 100644 --- a/paula.pasplugins/src/paula/pasplugins/plugins/paucred.py +++ b/paula.pasplugins/src/paula/pasplugins/plugins/paucred.py @@ -20,6 +20,7 @@ __author__ = "Florian Friesdorf " __docformat__ = "plaintext" +from Globals import Acquisition from zope.app.authentication.interfaces import ICredentialsPlugin from zope.interface import implements, alsoProvides from zope.publisher.interfaces import IRequest @@ -27,7 +28,7 @@ from zope.publisher.interfaces import IRequest CREDPLUG_NAME = "Paula: PAU CredentialsFromMappingPlugin" -class CredentialsFromMappingPlugin(object): +class CredentialsFromMappingPlugin(Acquisition.Explicit): """Just returns a mapping it is passed Useful, if you use paula and PAU just for authentication but not for diff --git a/paula.pasplugins/src/paula/pasplugins/plugins/properties.py b/paula.pasplugins/src/paula/pasplugins/plugins/properties.py index 9f74acb..bfb42f2 100644 --- a/paula.pasplugins/src/paula/pasplugins/plugins/properties.py +++ b/paula.pasplugins/src/paula/pasplugins/plugins/properties.py @@ -31,7 +31,7 @@ from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin from Products.PluggableAuthService.interfaces.plugins \ import IPropertiesPlugin -from zope.app.authentication.interfaces import IPluggableAuthentication +from zope.app.security.interfaces import IAuthentication from zope.app.security.interfaces import PrincipalLookupError from zope.component import getUtility from zope.interface import alsoProvides, implements @@ -123,8 +123,8 @@ class PropertiesPlugin(BasePlugin): >>> from zope.component import provideUtility >>> au = Mock(getPrincipal = lambda x : x == "login" and p) - >>> alsoProvides(au, IPluggableAuthentication) - >>> provideUtility(au, IPluggableAuthentication) + >>> alsoProvides(au, IAuthentication) + >>> provideUtility(au, IAuthentication) our property plugin @@ -148,7 +148,7 @@ class PropertiesPlugin(BasePlugin): {} """ # get principal from pau - pau = getUtility(IPluggableAuthentication) + pau = getUtility(IAuthentication) try: principal = pau.getPrincipal(user.getId()) except PrincipalLookupError: diff --git a/paula.pasplugins/src/paula/pasplugins/profiles/default/componentregistry.xml b/paula.pasplugins/src/paula/pasplugins/profiles/default/componentregistry.xml index a549f56..cfabf67 100644 --- a/paula.pasplugins/src/paula/pasplugins/profiles/default/componentregistry.xml +++ b/paula.pasplugins/src/paula/pasplugins/profiles/default/componentregistry.xml @@ -3,7 +3,7 @@ diff --git a/paula.pasplugins/src/paula/pasplugins/setuphandlers.py b/paula.pasplugins/src/paula/pasplugins/setuphandlers.py index 25dfcae..1fcc3b6 100644 --- a/paula.pasplugins/src/paula/pasplugins/setuphandlers.py +++ b/paula.pasplugins/src/paula/pasplugins/setuphandlers.py @@ -10,7 +10,7 @@ from Products.PluggableAuthService.interfaces.plugins \ import IAuthenticationPlugin from Products.PlonePAS.Extensions.Install import activatePluginInterfaces -from zope.app.authentication.interfaces import IPluggableAuthentication +from zope.app.security.interfaces import IAuthentication from zope.component import getUtility @@ -42,7 +42,7 @@ def _setupPlugins(portal, out): activatePluginInterfaces(portal, 'paula_groups', out) credplugname = 'Paula: PAU CredentialsFromMappingPlugin' - pau = getUtility(IPluggableAuthentication) + pau = getUtility(IAuthentication) if credplugname not in pau.credentialsPlugins: pau.credentialsPlugins = tuple( list(pau.credentialsPlugins) + [credplugname] diff --git a/paula.pasplugins/src/paula/pasplugins/tests/fake_group_subscriber.py b/paula.pasplugins/src/paula/pasplugins/tests/fake_group_subscriber.py deleted file mode 100644 index c675de7..0000000 --- a/paula.pasplugins/src/paula/pasplugins/tests/fake_group_subscriber.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2008 by Florian Friesdorf -# -# GNU Affero General Public License (AGPL) -# -# 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 -# . -""" -""" -__author__ = "Florian Friesdorf " -__docformat__ = "plaintext" - -from zope.app.authentication.interfaces import IPrincipalCreated -from zope.security.interfaces import IGroupAwarePrincipal -from zope.component import adapter, queryUtility - -from paula.pasplugins.tests.fake_pau_ap import FAKE_LOGIN - -@adapter(IPrincipalCreated) -def setGroupsForPrincipal(event): - """Put groups onto the principal - """ - principal = event.principal - if not IGroupAwarePrincipal.providedBy(principal): - return None - - if principal.id == FAKE_LOGIN: - principal.groups.extend(['fakegroup1', 'fakegroup2']) diff --git a/paula.pasplugins/src/paula/pasplugins/tests/fake_pau_ap.py b/paula.pasplugins/src/paula/pasplugins/tests/fake_pau_ap.py index 1dffb26..c49f817 100644 --- a/paula.pasplugins/src/paula/pasplugins/tests/fake_pau_ap.py +++ b/paula.pasplugins/src/paula/pasplugins/tests/fake_pau_ap.py @@ -20,6 +20,7 @@ __author__ = "Florian Friesdorf " __docformat__ = "plaintext" +from Globals import Acquisition from UserDict import UserDict # this should be moved from zope.app.authentication to zope.authentication @@ -38,7 +39,7 @@ alsoProvides(FAKE_REQUEST, IRequest) AUTHPLUG_NAME = "Paula: Fake PAU AuthenticatorPlugin - Do not use!" -class AuthenticatorPlugin(object): +class AuthenticatorPlugin(Acquisition.Explicit): """Authenticate a fixed fake user >>> ap = AuthenticatorPlugin() diff --git a/paula.pasplugins/src/paula/pasplugins/tests/fake_prop_subscriber.py b/paula.pasplugins/src/paula/pasplugins/tests/fake_subscribers.py similarity index 77% rename from paula.pasplugins/src/paula/pasplugins/tests/fake_prop_subscriber.py rename to paula.pasplugins/src/paula/pasplugins/tests/fake_subscribers.py index 5faa24c..aec534b 100644 --- a/paula.pasplugins/src/paula/pasplugins/tests/fake_prop_subscriber.py +++ b/paula.pasplugins/src/paula/pasplugins/tests/fake_subscribers.py @@ -21,11 +21,13 @@ __author__ = "Florian Friesdorf " __docformat__ = "plaintext" from zope.app.authentication.interfaces import IPrincipalCreated -from zope.component import adapter -from zope.interface import alsoProvides, Interface, Attribute +from zope.component import adapter, queryUtility +from zope.interface import Attribute, Interface, alsoProvides +from zope.security.interfaces import IGroupAwarePrincipal -from paula.pau_addons.interfaces import IPropertyInterface from paula.pasplugins.tests.fake_pau_ap import FAKE_LOGIN +from paula.pau_addons.interfaces import IPropertyInterface + class IA(Interface): email = Attribute(u'email') @@ -51,3 +53,15 @@ def setPropertiesForPrincipal(event): principal.foo = u'foo value' alsoProvides(principal, IA) alsoProvides(principal, IB) + + +@adapter(IPrincipalCreated) +def setGroupsForPrincipal(event): + """Put groups onto the principal + """ + principal = event.principal + if not IGroupAwarePrincipal.providedBy(principal): + return None + + if principal.id == FAKE_LOGIN: + principal.groups.extend(['fakegroup1', 'fakegroup2']) -- 2.11.4.GIT