Skip to content

Commit

Permalink
Implemented principal source widget based on z3c.form
Browse files Browse the repository at this point in the history
Now there is a widget which uses forms and doesn't use the vocabulary hook.
This is all done with the widget, form and term implementation from z3c.form.
It's really impressive how flexible z3c.form is.
Removed the latest dependencies to zope.app.authentication and zope.app.form

TODO:
write more tests, check import and setup dependencies
  • Loading branch information
projekt01 committed Mar 26, 2008
1 parent 98a9350 commit df83c4b
Show file tree
Hide file tree
Showing 21 changed files with 1,019 additions and 280 deletions.
21 changes: 10 additions & 11 deletions src/z3c/authenticator/README.txt
@@ -1,10 +1,10 @@
========================
X Authentication Utility
========================
=======================
IAuthentication Utility
=======================

The X Authentication Utility provides a framework for authenticating
principals and associating information with them. It uses plugins and
subscribers to get its work done.
The Authenticator Utility provides a framework for authenticating principals
and associating information with them. It uses plugins and subscribers to get
its work done.

For a simple authentication utility to be used, it should be registered as a
utility providing the `zope.app.security.interfaces.IAuthentication` interface.
Expand Down Expand Up @@ -67,11 +67,10 @@ Authenticator plugins are responsible for authenticating the credentials
extracted by a credentials plugin. They are also typically able to create
principal objects for credentials they successfully authenticate.

Given a request object, the Authenticator returns a principal object,
if it can. The X Autentication utility does this by first iterateing
through its credentials plugins to obtain a set of credentials. If it gets
credentials, it iterates through its authenticator plugins to authenticate
them.
Given a request object, the Authenticator returns a principal object, if it
can. The Authenticator utility does this by first iterateing through its
credentials plugins to obtain a set of credentials. If it gets credentials, it
iterates through its authenticator plugins to authenticate them.

If an authenticator succeeds in authenticating a set of credentials, the
Authenticator uses the authenticator to create a principal
Expand Down
30 changes: 0 additions & 30 deletions src/z3c/authenticator/authentication.py
Expand Up @@ -144,34 +144,4 @@ def logout(self, request):
next.logout(request)


class QuerySchemaSearchAdapter(object):
"""Performs schema-based principal searches on behalf of a PAU.
Delegates the search to the adapted authenticator (which also provides
IQuerySchemaSearch)..
"""
zope.component.adapts(
interfaces.IQuerySchemaSearch,
interfaces.IAuthenticator)

zope.interface.implements(
interfaces.IQueriableAuthenticator,
interfaces.IQuerySchemaSearch,
ILocation)

def __init__(self, authplugin, pau):
if ILocation.providedBy(authplugin):
self.__parent__ = authplugin.__parent__
self.__name__ = authplugin.__name__
else:
self.__parent__ = pau
self.__name__ = ""
self.authplugin = authplugin
self.pau = pau
self.schema = authplugin.schema

def search(self, query, start=None, batch_size=None):
for id in self.authplugin.search(query, start, batch_size):
yield id


7 changes: 0 additions & 7 deletions src/z3c/authenticator/browser/configure.zcml
Expand Up @@ -3,13 +3,6 @@
xmlns="http://namespaces.zope.org/browser"
i18n_domain="z3c">

<zope:adapter
for="..interfaces.IQuerySchemaSearch
zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.app.form.browser.interfaces.ISourceQueryView"
factory=".schemasearch.QuerySchemaSearchView"
/>

<include file="authenticator.zcml" />
<include file="credential.zcml" />
<include file="group.zcml" />
Expand Down
44 changes: 0 additions & 44 deletions src/z3c/authenticator/browser/edit.py

This file was deleted.

26 changes: 24 additions & 2 deletions src/z3c/authenticator/browser/group.py
Expand Up @@ -27,13 +27,15 @@
from z3c.authenticator import interfaces
from z3c.authenticator import group
from z3c.authenticator import user
from z3c.authenticator.widget import getSourceInputWidget
from z3c.form import field
from z3c.form import button
from z3c.formui import form
from z3c.pagelet import browser
from z3c.configurator import configurator



class IAddName(zope.interface.Interface):
"""Object name."""

Expand Down Expand Up @@ -103,5 +105,25 @@ class GroupEditForm(form.EditForm):
"""Group edit form."""

label = _('Edit Group.')

fields = field.Fields(interfaces.IGroup).select('title', 'description')
groupCycleErrorMessage = _('There is a cyclic relationship among groups.')

fields = field.Fields(interfaces.IGroup).select('title', 'description',
'principals')

fields['principals'].widgetFactory = getSourceInputWidget

@button.buttonAndHandler(_('Apply'), name='apply')
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
try:
changes = self.applyChanges(data)
except group.GroupCycle, e:
self.status = self.groupCycleErrorMessage
return
if changes:
self.status = self.successMessage
else:
self.status = self.noChangesMessage
111 changes: 0 additions & 111 deletions src/z3c/authenticator/browser/schemasearch.py

This file was deleted.

6 changes: 2 additions & 4 deletions src/z3c/authenticator/browser/user.py
Expand Up @@ -73,8 +73,7 @@ class UserAddForm(form.AddForm):

label = _('Add User.')

fields = field.Fields(IAddName)
fields += field.Fields(interfaces.IUser).select('login', 'password',
fields = field.Fields(interfaces.IUser).select('login', 'password',
'title', 'description', 'passwordManagerName')

def createAndAdd(self, data):
Expand All @@ -85,9 +84,8 @@ def createAndAdd(self, data):
passwordManagerName = data.get('passwordManagerName', u'')
obj = user.User(login, password, title, description,
passwordManagerName)
self.contentName = data.get('__name__', u'')
zope.event.notify(zope.lifecycleevent.ObjectCreatedEvent(obj))
self.context[self.contentName] = obj
self.contentName, usr = self.context.add(obj)

#configure
configurator.configure(obj, data)
Expand Down
13 changes: 4 additions & 9 deletions src/z3c/authenticator/configure.zcml
Expand Up @@ -17,13 +17,6 @@
/>
</class>

<adapter
for=".interfaces.IQuerySchemaSearch
.interfaces.IAuthenticator"
provides=".interfaces.IQueriableAuthenticator"
factory=".authentication.QuerySchemaSearchAdapter"
/>

<utility
component=".vocabulary.authenticatorPlugins"
name="Z3CAuthenticatorPlugins"
Expand All @@ -34,10 +27,12 @@
name="Z3CCredentialsPlugins"
/>

<include file="principal.zcml" />
<include file="credential.zcml" />
<include file="group.zcml" />
<include file="password.zcml" />
<include file="principal.zcml" />
<include file="user.zcml" />
<include file="credential.zcml" />
<include file="widget.zcml" />

<include package=".browser" />

Expand Down
5 changes: 1 addition & 4 deletions src/z3c/authenticator/group.py
Expand Up @@ -93,10 +93,7 @@ def __repr__(self):

class GroupContainer(btree.BTreeContainer):

zope.interface.implements(interfaces.IGroupContainer,
interfaces.IQuerySchemaSearch,)

schema = interfaces.IGroupSearchCriteria
zope.interface.implements(interfaces.IGroupContainer)

def __init__(self, prefix=u''):
self.prefix = prefix
Expand Down
6 changes: 0 additions & 6 deletions src/z3c/authenticator/group.zcml
Expand Up @@ -31,12 +31,6 @@
factory=".group.GroupPrincipal"
/>

<adapter
provides="zope.app.container.interfaces.INameChooser"
for=".interfaces.IGroupContainer"
factory="zope.app.authentication.idpicker.IdPicker"
/>

<subscriber
for=".interfaces.IPrincipalCreated"
handler=".group.specialGroups"
Expand Down

0 comments on commit df83c4b

Please sign in to comment.