[Zope3-Users] Creating PluggableAuthentication problem.

Tobias Weber tobi-weber at gmx.de
Thu Apr 13 13:13:03 EDT 2006


Hello!

I try to add a PluggableAuthentication and a PrincipalFolder automatically.
When I add a principal to the PrincipalFolder it works fine, but the 
authentification of the User fails. When I add one more 
PluggableAuthentication manually and choose the automatically generated 
PrincipalFolder as authenticator plugin, it works.
Here is my code:

from zope.app import zapi
from zope.app.publisher.browser import BrowserView
from zope.security.proxy import removeSecurityProxy
from zope.app.component.interfaces import ISite
from zope.app.component.site import LocalSiteManager
from zope.app.authentication.authentication import PluggableAuthentication
from zope.app.component.site import UtilityRegistration
from zope.app.security.interfaces import IAuthentication
from zope.app.container.interfaces import INameChooser
from zope.app.component.interfaces.registration import ActiveStatus
from zope.app.authentication.principalfolder import PrincipalFolder
from zope.app.authentication.interfaces import IAuthenticatorPlugin

class MakeUserFolder(BrowserView):
	
	def addUserFolder(self):
		if ISite.providedBy(self.context):
			raise zapi.UserError('This is already a site')

		# We don't want to store security proxies (we can't,
		# actually), so we have to remove proxies here before passing
		# the context to the SiteManager.
		bare = removeSecurityProxy(self.context)
		sm = LocalSiteManager(bare)
		self.context.setSiteManager(sm)
		
		# create PluggableAuthentication utility
		pluggableauth = PluggableAuthentication()
		pluggableauth.prefix = u'learn2l'

		# get site manager and site management folder
		sitemanager = bare.getSiteManager()
		default = sitemanager['default']
	
		# add utility to site management folder
		chooser = INameChooser(default)
		folder_name = chooser.chooseName(pluggableauth.__name__, pluggableauth)
		default[folder_name] = pluggableauth

		# create service registration
		registration = UtilityRegistration('pluggableauth', IAuthentication, 			
									pluggableauth)
		key = default.registrationManager.addRegistration(registration)
		zapi.traverse(default.registrationManager, key).status = ActiveStatus
		
		# create PrincipalFolder utility
		pf = PrincipalFolder()
		pf.prefix = u'users'
		
		# add utility to PuggableAuthentication
		chooser = INameChooser(pluggableauth)
		folder_name = chooser.chooseName(pf.__name__, pf)
		pluggableauth[folder_name] = pf
		
		# create service registration
		registration = UtilityRegistration('users', IAuthenticatorPlugin, pf)
		key = pluggableauth.registrationManager.addRegistration(registration)
		zapi.traverse(pluggableauth.registrationManager, key).status = ActiveStatus
		
		pluggableauth.authenticatorPlugins = [u'users']
		pluggableauth.credentialsPlugins = [u'Zope Realm Basic-Auth']
		
		self.request.response.redirect(".")


I am sorry for this code, I try to figure out how it works.

Thank you,
Tobias


More information about the Zope3-users mailing list