[Zope3-checkins] CVS: Zope3/src/zope/app/services/pluggableauth -
__init__.py:1.7.6.2
Jim Fulton
jim at zope.com
Fri Sep 12 15:16:04 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/services/pluggableauth
In directory cvs.zope.org:/tmp/cvs-serv13470/src/zope/app/services/pluggableauth
Modified Files:
Tag: parentgeddon-branch
__init__.py
Log Message:
Can't have the tests passing, can we?
=== Zope3/src/zope/app/services/pluggableauth/__init__.py 1.7.6.1 => 1.7.6.2 ===
--- Zope3/src/zope/app/services/pluggableauth/__init__.py:1.7.6.1 Mon Sep 8 14:21:48 2003
+++ Zope3/src/zope/app/services/pluggableauth/__init__.py Fri Sep 12 15:15:34 2003
@@ -31,20 +31,20 @@
from zope.app.services.servicenames import Authentication
from zope.component.interfaces import IViewFactory
from zope.app.container.ordered import OrderedContainer
-from zope.app.interfaces.container import IContainerNamesContainer
from zope.app.interfaces.container import IOrderedContainer
from zope.app.interfaces.container import IAddNotifiable
from zope.app.interfaces.services.pluggableauth import IUserSchemafied
from zope.app.interfaces.security import ILoginPassword
from zope.app.interfaces.services.pluggableauth \
import IPluggableAuthenticationService
-from zope.app.interfaces.services.pluggableauth import IPrincipalSource, \
- ILoginPasswordPrincipalSource, IContainerPrincipalSource
+from zope.app.interfaces.services.pluggableauth import \
+ IPrincipalSource, ILoginPasswordPrincipalSource, IContainerPrincipalSource
from zope.app.interfaces.services.service import ISimpleService
from zope.app.component.nextservice import queryNextService
from zope.app import zapi
from zope.app.traversing import getPath
from zope.exceptions import NotFoundError
+from zope.app.container.contained import Contained, contained, uncontained
def gen_key():
"""Return a random int (1, MAXINT), suitable for use as a BTree key."""
@@ -69,7 +69,7 @@
# references which embed the old earmark.
OrderedContainer.__init__(self)
- def afterAddHook(self, ob, container):
+ def addNotify(self, event):
""" See IAddNotifiable. """
if self.earmark is None:
# we manufacture what is intended to be a globally unique
@@ -86,9 +86,7 @@
if loginView is not None:
principal = loginView.authenticate()
if principal is not None:
- id = '\t'.join((self.earmark, ps_key,
- str(principal.getId())))
- return PrincipalWrapper(principal, self, id)
+ return principal
next = queryNextService(self, Authentication, None)
if next is not None:
@@ -142,16 +140,14 @@
source = self.get(principal_src_id)
if source is None:
raise NotFoundError, principal_src_id
- p = source.getPrincipal(principal_id)
- return PrincipalWrapper(p, self, id)
+ return source.getPrincipal(principal_id)
def getPrincipals(self, name):
""" See IAuthenticationService. """
for ps_key, ps in self.items():
for p in ps.getPrincipals(name):
- id = '\t'.join((self.earmark, ps_key, str(p.getId())))
- yield PrincipalWrapper(p, self, id)
+ yield p
next = queryNextService(self, Authentication, None)
if next is not None:
@@ -172,7 +168,7 @@
if not IPrincipalSource.isImplementedBy(principal_source):
raise TypeError("Source must implement IPrincipalSource")
- self.setObject(id, principal_source)
+ self[id] = principal_source
def removePrincipalSource(self, id):
""" See IPluggableAuthenticationService.
@@ -193,11 +189,10 @@
del self[id]
-class BTreePrincipalSource(Persistent):
+class BTreePrincipalSource(Persistent, Contained):
"""An efficient, scalable provider of Authentication Principals."""
- implements(ILoginPasswordPrincipalSource, IContainerPrincipalSource,
- IContainerNamesContainer)
+ implements(ILoginPasswordPrincipalSource, IContainerPrincipalSource)
def __init__(self):
@@ -206,13 +201,12 @@
# IContainer-related methods
- def __delitem__(self, key):
+ def __delitem__(self, login):
""" See IContainer.
>>> sps = BTreePrincipalSource()
>>> prin = SimplePrincipal('fred', 'fred', '123')
- >>> sps.setObject('fred', prin)
- 'fred'
+ >>> sps['fred'] = prin
>>> int(sps.get('fred') == prin)
1
>>> del sps['fred']
@@ -220,20 +214,23 @@
0
"""
- number = self._numbers_by_login[key]
+ number = self._numbers_by_login[login]
+ uncontained(self._principals_by_number[number], self)
del self._principals_by_number[number]
- del self._numbers_by_login[key]
+ del self._numbers_by_login[login]
- def setObject(self, id, ob):
+ def __setitem__(self, login, ob):
""" See IContainerNamesContainer
>>> sps = BTreePrincipalSource()
>>> prin = SimplePrincipal('gandalf', 'shadowfax')
- >>> dummy = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> sps.get('doesntmatter')
"""
+ ob = contained(ob, self, login)
+
store = self._principals_by_number
key = gen_key()
@@ -252,11 +249,11 @@
>>> sps.keys()
[]
>>> prin = SimplePrincipal('arthur', 'tea')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> sps.keys()
['arthur']
>>> prin = SimplePrincipal('ford', 'towel')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> sps.keys()
['arthur', 'ford']
"""
@@ -270,9 +267,9 @@
>>> sps.keys()
[]
>>> prin = SimplePrincipal('trillian', 'heartOfGold')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> prin = SimplePrincipal('zaphod', 'gargleblaster')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> [i for i in sps]
['trillian', 'zaphod']
"""
@@ -284,7 +281,7 @@
>>> sps = BTreePrincipalSource()
>>> prin = SimplePrincipal('gag', 'justzisguy')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> sps['gag'].login
'gag'
"""
@@ -297,7 +294,7 @@
>>> sps = BTreePrincipalSource()
>>> prin = SimplePrincipal(1, 'slartibartfast', 'fjord')
- >>> key = sps.setObject('slartibartfast', prin)
+ >>> sps['slartibartfast'] = prin
>>> principal = sps.get('slartibartfast')
>>> sps.get('marvin', 'No chance, dude.')
'No chance, dude.'
@@ -317,11 +314,11 @@
>>> sps.keys()
[]
>>> prin = SimplePrincipal('arthur', 'tea')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> [user.login for user in sps.values()]
['arthur']
>>> prin = SimplePrincipal('ford', 'towel')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> [user.login for user in sps.values()]
['arthur', 'ford']
"""
@@ -336,7 +333,7 @@
>>> int(len(sps) == 0)
1
>>> prin = SimplePrincipal(1, 'trillian', 'heartOfGold')
- >>> key = sps.setObject('trillian', prin)
+ >>> sps['trillian'] = prin
>>> int(len(sps) == 1)
1
"""
@@ -350,11 +347,11 @@
>>> sps.keys()
[]
>>> prin = SimplePrincipal('zaphod', 'gargleblaster')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> [(k, v.login) for k, v in sps.items()]
[('zaphod', 'zaphod')]
>>> prin = SimplePrincipal('marvin', 'paranoid')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> [(k, v.login) for k, v in sps.items()]
[('marvin', 'marvin'), ('zaphod', 'zaphod')]
"""
@@ -367,7 +364,7 @@
>>> sps = BTreePrincipalSource()
>>> prin = SimplePrincipal('slinkp', 'password')
- >>> key = sps.setObject('doesntmatter', prin)
+ >>> sps['doesntmatter'] = prin
>>> int('slinkp' in sps)
1
>>> int('desiato' in sps)
@@ -400,15 +397,15 @@
>>> sps = BTreePrincipalSource()
>>> prin1 = SimplePrincipal('gandalf', 'shadowfax')
- >>> dummy = sps.setObject('doesntmatter', prin1)
+ >>> sps['doesntmatter'] = prin1
>>> prin1 = SimplePrincipal('frodo', 'ring')
- >>> dummy = sps.setObject('doesntmatter', prin1)
+ >>> sps['doesntmatter'] = prin1
>>> prin1 = SimplePrincipal('pippin', 'pipe')
- >>> dummy = sps.setObject('doesntmatter', prin1)
+ >>> sps['doesntmatter'] = prin1
>>> prin1 = SimplePrincipal('sam', 'garden')
- >>> dummy = sps.setObject('doesntmatter', prin1)
+ >>> sps['doesntmatter'] = prin1
>>> prin1 = SimplePrincipal('merry', 'food')
- >>> dummy = sps.setObject('doesntmatter', prin1)
+ >>> sps['doesntmatter'] = prin1
>>> [p.login for p in sps.getPrincipals('a')]
['gandalf', 'sam']
>>> [p.login for p in sps.getPrincipals('')]
@@ -430,7 +427,18 @@
if user.password == password:
return user
-class SimplePrincipal(Persistent):
+ def chooseName(self, name, object):
+ "See zope.app.interfaces.container.INameChooser"
+
+ store = self._principals_by_number
+ while 1:
+ key = gen_key()
+ if key not in store:
+ return str(key)
+
+
+
+class SimplePrincipal(Persistent, Contained):
"""A no-frills IUserSchemafied implementation."""
implements(IUserSchemafied)
@@ -445,11 +453,10 @@
def getId(self):
""" See IPrincipal.
- This method returns just a simple id, PrincipalWrapper is
- used to get the full id as used by the
- PluggableAuthenticationService.
"""
- return self.id
+ source = self.__parent__
+ auth = source.__parent__
+ return "%s\t%s\t%s" %(auth.earmark, source.__name__, self.id)
def getTitle(self):
""" See IPrincipal. """
@@ -497,19 +504,3 @@
p = self.context.authenticate(login, password)
return p
-
-
-class PrincipalWrapper(ContainedProxy):
- """Principal Wrapper
-
- A wrapper for a principal as returned from the authentication
- service. This wrapper returns the principal id which includes
- identification of the auth service and the principal store id in
- addition to the principal id.
- """
-
- def getId(self):
- """ Return the id as passed in to the wrapper """
- return self.__name__
-
-
More information about the Zope3-Checkins
mailing list