[Zope3-Users] IPluggableAuthentication -- 'new
style' authentication problem
Christian Lueck
christian.lueck at ruhr-uni-bochum.de
Thu Oct 13 20:55:03 EDT 2005
Christian Lueck wrote:
>How do I get the PAUtility? (or the several PAUs?)
>paus =
>zapi.getAllUtilitiesRegisteredFor(zope.app.authentication.interfaces.IPluggableAuthentication)
>returns no pau at all, neither in the context of the root-folder, nor in
>the context of the local site called 'subfolder'. len(paus) is allways 0.
>
>
This is still a miracle to me and I would still like to learn.
But thanks to Tom's advice I was able to write a view which adds new
principals to the ZMI-registered principal folder plugin. It is possible
to get the principal folder plugin without getting the PAU before:
>>> from zope.app.debug import Debugger
>>> debugger = Debugger('var/Data.fs', 'etc/site.zcml')
>>> root = debugger.root()
>>> from zope.app.component.hooks import setSite
>>> setSite(root)
still zero PAUs:
>>> from zope.app.authentication.interfaces import IPluggableAuthentication
>>> paus = zapi.getAllUtilitiesRegisteredFor(IPluggableAuthentication)
>>> print len(paus)
0
but the principal folder plugin which I named 'users' in the ZMI is there:
>>> from zope.app.authentication.interfaces import IAuthenticatorPlugin
>>> apus = zapi.getAllUtilitiesRegisteredFor(IAuthenticatorPlugin)
>>> print len(apus)
1
>>> for apu in apus:
... plugin = apu
...
>>> plugin.__name__
u'users'
So I wrote the above mentioned view which could be a substitute for
Example 19.2.7 of Philipp's book. -- Hmm, I'm really not happy with it,
but it's a first step...
Note that it makes use of the ZMI-registered 'new style' principal
folder instead of 19.2.2. It does not work with the cookie based login
of Chapter 19.1 -- don't ask me why (may be due to my config).
from zope.i18nmessageid import MessageIDFactory
from zope.security.proxy import removeSecurityProxy
from zope.app import zapi
from zope.app.publisher.browser import BrowserView
from zope.app.exception.interfaces import UserError
from zope.app.authentication.interfaces import IAuthenticatorPlugin
from zope.app.authentication.principalfolder import InternalPrincipal
from zope.app.securitypolicy.interfaces import IPrincipalRoleManager
_ = MessageIDFactory('paradigm')
#from paradigm.userdb.interfaces import ISignupPrincipalSource
principal_source_name = 'users'
class SignUpView(BrowserView):
def _getPrincipalSource(self):
try:
ps = zapi.getUtility(IAuthenticatorPlugin,
name=principal_source_name,
context = self.context)
except ComponentLookupError:
raise UserError(_("Signup requires a Principal Source Folder."))
return ps
def signUp(self, login, title, password, confirmation):
# check confirmation
if confirmation != password:
raise UserError(_(u"Password and confirmation didn't match"))
# instantiate a new principal
newprincipal = InternalPrincipal(login=login,
password=password,
title=title)
# get principal source and add newprincipal to it
principal_source = self._getPrincipalSource()
if login in principal_source:
raise UserError(_(u"This login has already been choosen."))
try:
principal_source[login] = newprincipal
except ValueError:
raise UserError(_(u"There already exists a principal with
this login. Please choose a different one."))
# hm, this works only with 19.2.2
#role_manager = IPrincipalRoleManager(self.context)
#role_manager = removeSecurityProxy(role_manger)
#for role in principal_source.signup_roles:
# role_manager.assignRoleToPrincipal(role, principal.id)
# redirect to next url
self.request.response.redirect('@@welcome.html')
Regards,
Christian
More information about the Zope3-users
mailing list