Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Added some bbb and updated the final packages to the new layout. Merged
Browse files Browse the repository at this point in the history
trunk.
  • Loading branch information
strichter committed Jan 17, 2005
1 parent e5e9fe3 commit a608331
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions browser/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from zope.interface import implements
from zope.i18n import translate
from zope.app.publisher.interfaces.http import ILogin, ILogout
from zope.app.security.interfaces import IAuthenticationUtility
from zope.app.security.interfaces import IAuthentication
from zope.app.security.principalregistry import UnauthenticatedPrincipal
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.proxy import removeAllProxies
Expand All @@ -28,7 +28,7 @@
search_label = _('search-button', 'Search')

class AuthUtilitySearchView(object):
__used_for__ = IAuthenticationUtility
__used_for__ = IAuthentication

def __init__(self, context, request):
self.context = context
Expand Down
2 changes: 1 addition & 1 deletion browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


<adapter
for="zope.app.security.interfaces.IAuthenticationUtility
for="zope.app.security.interfaces.IAuthentication
zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.app.form.browser.interfaces.ISourceQueryView"
factory="zope.app.security.browser.auth.AuthUtilitySearchView"
Expand Down
8 changes: 4 additions & 4 deletions browser/principalterms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ create an authentication utility to demonstrate how this works:
... self.id, self.title = id, title

>>> from zope.interface import implements
>>> from zope.app.security.interfaces import IAuthenticationUtility
>>> from zope.app.security.interfaces import IAuthentication
>>> from zope.app.security.interfaces import PrincipalLookupError
>>> class AuthUtility:
... implements(IAuthenticationUtility)
... implements(IAuthentication)
... data = {'jim': 'Jim Fulton', 'stephan': 'Stephan Richter'}
...
... def getPrincipal(self, id):
Expand All @@ -26,14 +26,14 @@ create an authentication utility to demonstrate how this works:
Now we need to install the authentication utility:

>>> from zope.app.testing import ztapi
>>> ztapi.provideUtility(IAuthenticationUtility, AuthUtility())
>>> ztapi.provideUtility(IAuthentication, AuthUtility())

We need a principal source so that we can create a view from it.

>>> from zope.app import zapi
>>> class PrincipalSource:
... def __contains__(self, id):
... auth = zapi.getUtility(IAuthenticationUtility)
... auth = zapi.getUtility(IAuthentication)
... try:
... auth.getPrincipal(id)
... except PrincipalLookupError:
Expand Down
2 changes: 1 addition & 1 deletion configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<include file="_protections.zcml" />

<utility
provides=".interfaces.IAuthenticationUtility"
provides=".interfaces.IAuthentication"
component=".principalregistry.principalRegistry" />

<localUtility class=".permission.LocalPermission">
Expand Down
15 changes: 8 additions & 7 deletions interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class IUnauthenticatedPrincipal(IPrincipal):
Authenticated principals are preferable to UnauthenticatedPrincipals.
"""

class IAuthenticationUtility(Interface):
class IAuthentication(Interface):
"""Provide support for establishing principals for requests.
This is implemented by performing protocol-specific actions, such as
issuing challenges or providing login interfaces.
`IAuthenticationUtility` objects are used to implement authentication
`IAuthentication` objects are used to implement authentication
utilities. Because they implement utilities, they are expected to
collaborate with utilities in other contexts. Client code doesn't search a
context and call multiple utilities. Instead, client code will call the
Expand Down Expand Up @@ -119,11 +119,12 @@ def getPrincipal(id):
object hierarchy.
"""

class IAuthenticationUtility(IAuthentication):
"""This interface is deprecated
"""

def getPrincipals(name):
"""Get principals with matching names.
Get an iterable object with the principals with names that are
similar to (e.g. contain) the given name.
"""This interface is deprecated
"""

############################################################################
Expand All @@ -134,7 +135,7 @@ def getPrincipals(name):
class ILoginPassword(Interface):
"""A password based login.
An `IAuthenticationUtility` would use this (adapting a request),
An `IAuthentication` would use this (adapting a request),
to discover the login/password passed from the user, or to
indicate that a login is required.
"""
Expand Down
4 changes: 2 additions & 2 deletions principal.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"""
from zope.app import zapi
from zope.app.security.interfaces import PrincipalLookupError
from zope.app.security.interfaces import IAuthenticationUtility
from zope.app.security.interfaces import IAuthentication

# BBB Backward Compatibility
from zope.exceptions import NotFoundError
import warnings

def checkPrincipal(context, principal_id):

auth = zapi.getUtility(IAuthenticationUtility, context=context)
auth = zapi.getUtility(IAuthentication, context=context)
try:
if auth.getPrincipal(principal_id):
return
Expand Down
6 changes: 3 additions & 3 deletions principalregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from zope.app.security.interfaces import PrincipalLookupError
from zope.app import zapi
from zope.app.security.interfaces import ILoginPassword
from zope.app.security.interfaces import IAuthenticationUtility, IPrincipal
from zope.app.security.interfaces import IAuthentication, IPrincipal
from zope.app.security.interfaces import IUnauthenticatedPrincipal
from zope.app.container.contained import Contained, contained
from warnings import warn
Expand All @@ -30,9 +30,9 @@ class DuplicateId(Exception): pass

class PrincipalRegistry(object):

implements(IAuthenticationUtility)
implements(IAuthentication)

# Methods implementing IAuthenticationUtility
# Methods implementing IAuthentication

def authenticate(self, request):
a = ILoginPassword(request, None)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_securitydirectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from zope.app.testing.placelesssetup import PlacelessSetup

from zope.app.servicenames import Authentication
from zope.app.security.interfaces import IAuthenticationUtility, IPermission
from zope.app.security.interfaces import IAuthentication, IPermission
from zope.app.security.principalregistry import principalRegistry
from zope.app.security.settings import Allow
import zope.app.security.tests
Expand All @@ -34,7 +34,7 @@ class TestBase(PlacelessSetup):

def setUp(self):
super(TestBase, self).setUp()
ztapi.provideUtility(IAuthenticationUtility, principalRegistry)
ztapi.provideUtility(IAuthentication, principalRegistry)


class TestPrincipalDirective(TestBase, unittest.TestCase):
Expand Down
18 changes: 9 additions & 9 deletions vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from zope.interface import implements
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
from zope.schema.interfaces import ISourceQueriables
from zope.app.security.interfaces import IPermission, IAuthenticationUtility
from zope.app.security.interfaces import IPermission, IAuthentication
from zope.app.security.interfaces import PrincipalLookupError
from zope.app.component import queryNextUtility

Expand Down Expand Up @@ -147,7 +147,7 @@ def __contains__(self, id):
>>> zapi.getUtility = temp
"""
auth = zapi.getUtility(IAuthenticationUtility)
auth = zapi.getUtility(IAuthentication)
try:
auth.getPrincipal(id)
except PrincipalLookupError:
Expand All @@ -174,27 +174,27 @@ def getQueriables(self):
authentication utilities to look for queriables.
>>> class DummyUtility1:
... implements(IAuthenticationUtility)
... implements(IAuthentication)
... __parent__ = None
... def __repr__(self): return 'dummy1'
>>> dummy1 = DummyUtility1()
>>> class DummyUtility2:
... implements(ISourceQueriables, IAuthenticationUtility)
... implements(ISourceQueriables, IAuthentication)
... __parent__ = None
... def getQueriables(self):
... return ('1', 1), ('2', 2), ('3', 3)
>>> dummy2 = DummyUtility2()
>>> class DummyUtility3(DummyUtility2):
... implements(IAuthenticationUtility)
... implements(IAuthentication)
... def getQueriables(self):
... return ('4', 4),
>>> dummy3 = DummyUtility3()
>>> from zope.app.component.testing import testingNextUtility
>>> testingNextUtility(dummy1, dummy2, IAuthenticationUtility)
>>> testingNextUtility(dummy2, dummy3, IAuthenticationUtility)
>>> testingNextUtility(dummy1, dummy2, IAuthentication)
>>> testingNextUtility(dummy2, dummy3, IAuthentication)
>>> temp = zapi.getUtility
>>> zapi.getUtility = lambda iface: dummy1
Expand All @@ -206,15 +206,15 @@ def getQueriables(self):
>>> zapi.getUtility = temp
"""
i = 0
auth = zapi.getUtility(IAuthenticationUtility)
auth = zapi.getUtility(IAuthentication)
while True:
queriables = ISourceQueriables(auth, None)
if queriables is None:
yield unicode(i), auth
else:
for qid, queriable in queriables.getQueriables():
yield unicode(i)+'.'+unicode(qid), queriable
auth = queryNextUtility(auth, IAuthenticationUtility)
auth = queryNextUtility(auth, IAuthentication)
if auth is None:
break
i += 1

0 comments on commit a608331

Please sign in to comment.