Wiring It All Up
First, lets register the ExamplePlugin class with Zope. In the products __init__.py file add the following code:
from Products.PluggableAuthService.PluggableAuthService import \
registerMultiPlugin
from plugins import example
def initialize(context):
''' Initialize product
'''
registerMultiPlugin(example.ExamplePlugin.meta_type) # Add to PAS menu
context.registerClass(example.ExamplePlugin,
constructors = (example.manage_addExamplePluginForm,
example.addExamplePlugin),
visibility = None)
The call to registerMultiPlugin will add our plugin to the drop down in the "acl_users" folder. A user can thus add the plugin manually. We are going to configure Generic Setup to automatically install the plugin so this line is optional. The call to registerClass registers the factory methods used to create an ExamplePlugin with Zope.
Next, we need to register our initialize method with Zope so that it gets called when Zope starts up. We do this in the configure.zcml file:
<five:registerPackage package="." initialize=".initialize" />
Be sure the "five" name space is defined as an attribute of the "configure" tag:
<configure
xmlns:five="http://namespaces.zope.org/five"
...
While we are in the configure.zcml file, register the Generic Setup profile we are going to create in the net step:
<genericsetup:registerProfile
name="default"
title="examplepas"
directory="profiles/default"
description="Add PlonePAS authentication ExamplePlugin"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
Be sure to add the genericsetup name space:
<configure
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
...
Now lets add the generic setup profile. We specified the profile will be in the directory "profiles/default" so go ahead and create that:
mkdir -p profiles/default cd profiles/default
Create a new file called "import_steps.xml" and add the following code:
?xml version="1.0"?>
<import-steps>
<import-step id="examplepas_varius" version="0.1"
handler="example.pas.setuphandlers.importVarius"
title="ExamplePAS Plugin">
</import-step>
</import-steps>
This will cause our plugin to be registered with Generic Setup and be selectable from the "Extension Profiles" menu when creating a new Plone site. We next need to implement the importVariuos method we just told Generic Setup to execute.
In the base plugin directory create a file called "setuphandlers.py" and add the following code:
from Products.PlonePAS.Extensions.Install import activatePluginInterfaces
from Products.CMFCore.utils import getToolByName
from StringIO import StringIO
from plugins.example import addExamplePlugin
def importVarius(context):
''' Install the ExamplePAS plugin
'''
out = StringIO()
portal = context.getSite()
uf = getToolByName(portal, 'acl_users')
installed = uf.objectIds()
if 'examplepas' not in installed:
addExamplePlugin(uf, 'examplepas', 'Example PAS')
activatePluginInterfaces(portal, 'examplepas', out)
else:
print >> out, 'examplepas already installed'
print out.getvalue()
This code first checks to see if our plugin is already installed. If it is not than it makes a call to the addExamplePlugin factory method to create an instance of the plugin in the "acl_users" folder. This Generic Setup step is also available from the "portal_setup" tool and can be rerun by selecting it there.
If you left the registerMultiPlugin function call in your initialize function than you can also go to your "acl_users" folder and add "Example PAS" from the drop down menu.
At this point you should be able to add the ExamplePlugin to the "acl_users" folder and login to your Plone site as user "foo" with a password of "bar".
