Florian Lindner wrote:
Hello,
I've a PluggableAuthentication and want to add and register some plugins to it.


Adding works fine:

principal_folder = zope.app.authentication.principalfolder.PrincipalFolder(prefix = "cs")

pau["PrincipalFolder"] = principal_folder

and I think I can select it with:

pau.credentialsPlugins = [principal_folder]

but how to register it before?

And how do I select credential plugins?

This is how we did it in a project:
createAuthenticationUtils is called on handling the ObjectAddedEvent for the folder (which is programmatically made a site) which should contain the PAU.

HTH, mac

-------------------------------

from zope.app.security.interfaces import IAuthentication
from zope.app.authentication.interfaces import IAuthenticatorPlugin
from zope.app.appsetup.bootstrap import ensureUtility
from zope.app.authentication.authentication import \
    PluggableAuthentication
from zope.app.authentication.principalfolder import PrincipalFolder
from zope.app.authentication.groupfolder import \
    GroupFolder, GroupInformation
from zope.app import zapi

from myproject import config

def addUtilityToPAU(pau, interface, utility_factory, id, name):
    utility = utility_factory()
    pau[id] = utility

    reg_man = pau.registrationManager
    reg = site.UtilityRegistration(name, interface, utility)
    reg_man.addRegistration(reg)
    reg.status = u'Active'

def _addGroupInformation(group_folder, id, title, description):
    group = GroupInformation()
    group.title = title
    group.description = description
    group_folder[id] = group

def createAuthenticationUtils(obj):
    ensureUtility(obj, IAuthentication, '', PluggableAuthentication,
                  copy_to_zlog=False)
    auth = zapi.getUtility(IAuthentication)
    auth.credentialsPlugins = (u'Session Credentials',)
    addUtilityToPAU(auth, IAuthenticatorPlugin, PrincipalFolder,
                    'principal_folder', u'Benutzerverwaltung')
    addUtilityToPAU(auth, IAuthenticatorPlugin, GroupFolder,
                    'group_folder', u'Rollenverwaltung')
    auth.authenticatorPlugins = (u'Benutzerverwaltung',
                                 u'Rollenverwaltung',)
    group_folder = auth['group_folder']
    for group in config.company_groups:
        _addGroupInformation(group_folder, group['id'],
                             group['title'], group['description'])

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to