[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/authentication/
Added 'login' to the principal info provided by the principal
folder. Group folder is now providing its own principal info
implementation instead of using principal folder's.
Garrett Smith
garrett at mojave-corp.com
Fri Apr 1 17:57:55 EST 2005
Log message for revision 29817:
Added 'login' to the principal info provided by the principal folder. Group folder is now providing its own principal info implementation instead of using principal folder's.
Changed:
U Zope3/trunk/src/zope/app/authentication/README.txt
U Zope3/trunk/src/zope/app/authentication/groupfolder.py
U Zope3/trunk/src/zope/app/authentication/groupfolder.txt
U Zope3/trunk/src/zope/app/authentication/principalfolder.py
U Zope3/trunk/src/zope/app/authentication/principalfolder.zcml
-=-
Modified: Zope3/trunk/src/zope/app/authentication/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/authentication/README.txt 2005-04-01 22:43:52 UTC (rev 29816)
+++ Zope3/trunk/src/zope/app/authentication/README.txt 2005-04-01 22:57:54 UTC (rev 29817)
@@ -64,30 +64,31 @@
Simple Authenticator Plugin
---------------------------
-Next we'll create a simple authenticator plugin:
+Next we'll create a simple authenticator plugin. For our plugin, we'll need
+an implementation of IPrincipalInfo:
- >>> from zope.app.authentication import principalfolder
- >>> from zope.event import notify
+ >>> class PrincipalInfo(object):
+ ...
+ ... interface.implements(interfaces.IPrincipalInfo)
+ ...
+ ... def __init__(self, id, title, description):
+ ... self.id = id
+ ... self.title = title
+ ... self.description = description
+ ...
+ ... def __repr__(self):
+ ... return 'PrincipalInfo(%r)' % self.id
+Our authenticator uses this type when it creates a principal info:
+
>>> class MyAuthenticatorPlugin:
...
... interface.implements(interfaces.IAuthenticatorPlugin)
...
... def authenticateCredentials(self, credentials):
... if credentials == 'secretcode':
- ... return principalfolder.PrincipalInfo('bob', 'Bob', '')
+ ... return PrincipalInfo('bob', 'Bob', '')
...
- ... def createAuthenticatedPrincipal_XXX(self, info, request):
- ... principal = principalfolder.Principal(info.id)
- ... notify(interfaces.AuthenticatedPrincipalCreated(
- ... principal, info, request))
- ... return principal
- ...
- ... def createFoundPrincipal_XXX(self, info):
- ... principal = principalfolder.Principal(info.id)
- ... notify(interfaces.FoundPrincipalCreated(principal, info))
- ... return principal
- ...
... def principalInfo(self, id):
... pass # plugin not currently supporting search
@@ -100,13 +101,10 @@
-------------------
While authenticator plugins provide principal info, they are not responsible
for creating principals. This function is performed by factory adapters. For
-these tests we will register factories for creating both 'authenticated'
-principals:
+these tests we'll borrow some factories from the principal folder:
+ >>> from zope.app.authentication import principalfolder
>>> provideAdapter(principalfolder.AuthenticatedPrincipalFactory)
-
-and 'found' principals:
-
>>> provideAdapter(principalfolder.FoundPrincipalFactory)
For more information on these factories, see their docstrings.
@@ -184,9 +182,9 @@
...
... def authenticateCredentials(self, credentials):
... if credentials == 'secretcode':
- ... return principalfolder.PrincipalInfo('black', 'Black Spy', '')
+ ... return PrincipalInfo('black', 'Black Spy', '')
... elif credentials == 'hiddenkey':
- ... return principalfolder.PrincipalInfo('white', 'White Spy', '')
+ ... return PrincipalInfo('white', 'White Spy', '')
>>> provideUtility(MyAuthenticatorPlugin2(), name='My Authenticator Plugin 2')
@@ -357,20 +355,8 @@
... if id is not None:
... return self.infos[id]
...
- ... def createAuthenticatedPrincipal_XXX(self, info, request):
- ... principal = principalfolder.Principal(info.id)
- ... notify(interfaces.AuthenticatedPrincipalCreated(
- ... principal, info, request))
- ... return principal
- ...
- ... def createFoundPrincipal_XXX(self, info):
- ... principal = principalfolder.Principal(info.id)
- ... notify(interfaces.FoundPrincipalCreated(principal, info))
- ... return principal
- ...
... def add(self, id, title, description, credentials):
- ... self.infos[id] = principalfolder.PrincipalInfo(
- ... id, title, description)
+ ... self.infos[id] = PrincipalInfo(id, title, description)
... self.ids[credentials] = id
This class is typical of an authenticator plugin. It can both authenticate
Modified: Zope3/trunk/src/zope/app/authentication/groupfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/authentication/groupfolder.py 2005-04-01 22:43:52 UTC (rev 29816)
+++ Zope3/trunk/src/zope/app/authentication/groupfolder.py 2005-04-01 22:57:54 UTC (rev 29817)
@@ -89,6 +89,34 @@
missing_value=u'',
)
+
+class GroupInfo:
+ """An implementation of IPrincipalInfo used by the group folder.
+
+ A group info is created with id, title, and description:
+
+ >>> info = GroupInfo('groups.managers', 'Managers', 'Taskmasters')
+ >>> info
+ GroupInfo('groups.managers')
+ >>> info.id
+ 'groups.managers'
+ >>> info.title
+ 'Managers'
+ >>> info.description
+ 'Taskmasters'
+
+ """
+ interface.implements(interfaces.IPrincipalInfo)
+
+ def __init__(self, id, title, description):
+ self.id = id
+ self.title = title
+ self.description = description
+
+ def __repr__(self):
+ return 'GroupInfo(%r)' % self.id
+
+
class GroupFolder(BTreeContainer):
interface.implements(
@@ -168,7 +196,7 @@
id = id[len(self.prefix):]
info = self.get(id)
if info is not None:
- return principalfolder.PrincipalInfo(
+ return GroupInfo(
self.prefix+id, info.title, info.description)
class GroupCycle(Exception):
Modified: Zope3/trunk/src/zope/app/authentication/groupfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/authentication/groupfolder.txt 2005-04-01 22:43:52 UTC (rev 29816)
+++ Zope3/trunk/src/zope/app/authentication/groupfolder.txt 2005-04-01 22:57:54 UTC (rev 29817)
@@ -52,8 +52,8 @@
...
... def __init__(self, groups):
... self.principals = {
- ... 'p1': principalfolder.PrincipalInfo('p1', '', ''),
- ... 'p2': principalfolder.PrincipalInfo('p2', '', ''),
+ ... 'p1': principalfolder.PrincipalInfo('p1', '', '', ''),
+ ... 'p2': principalfolder.PrincipalInfo('p2', '', '', ''),
... }
... self.groups = groups
...
@@ -194,7 +194,7 @@
>>> principal = principals.getPrincipal('group.G1')
>>> principal.id
'group.G1'
-
+
>>> principal.groups
[u'group.G2']
Modified: Zope3/trunk/src/zope/app/authentication/principalfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/authentication/principalfolder.py 2005-04-01 22:43:52 UTC (rev 29816)
+++ Zope3/trunk/src/zope/app/authentication/principalfolder.py 2005-04-01 22:57:54 UTC (rev 29817)
@@ -126,14 +126,16 @@
class PrincipalInfo:
- """A basic implementation of interfaces.IPrincipalInfo.
+ """An implementation of IPrincipalInfo used by the principal folder.
- A principal info is created with id, title, and description:
+ A principal info is created with id, login, title, and description:
- >>> info = PrincipalInfo('foo', 'Foo', 'An over-used term.')
+ >>> info = PrincipalInfo('users.foo', 'foo', 'Foo', 'An over-used term.')
>>> info
- PrincipalInfo('foo')
+ PrincipalInfo('users.foo')
>>> info.id
+ 'users.foo'
+ >>> info.login
'foo'
>>> info.title
'Foo'
@@ -143,8 +145,9 @@
"""
interface.implements(interfaces.IPrincipalInfo)
- def __init__(self, id, title, description):
+ def __init__(self, id, login, title, description):
self.id = id
+ self.login = login
self.title = title
self.description = description
@@ -207,19 +210,18 @@
id = self.__id_by_login.get(credentials['login'])
if id is None:
return None
- principal = self[id]
- if principal.password != credentials['password']:
+ internal = self[id]
+ if internal.password != credentials['password']:
return None
- return PrincipalInfo(
- id=self.prefix + id,
- title=principal.title,
- description=principal.description)
+ return PrincipalInfo(self.prefix + id, internal.login, internal.title,
+ internal.description)
def principalInfo(self, id):
if id.startswith(self.prefix):
internal = self.get(id[len(self.prefix):])
if internal is not None:
- return PrincipalInfo(id, internal.title, internal.description)
+ return PrincipalInfo(id, internal.login, internal.title,
+ internal.description)
def search(self, query, start=None, batch_size=None):
"""Search through this principal provider."""
@@ -285,7 +287,7 @@
To use the factory, create it with the info (interfaces.IPrincipalInfo) of
the principal to create and a request:
- >>> info = PrincipalInfo('mary', 'Mary', 'The site admin.')
+ >>> info = PrincipalInfo('users.mary', 'mary', 'Mary', 'The site admin.')
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> factory = AuthenticatedPrincipalFactory(info, request)
@@ -295,7 +297,7 @@
and description:
>>> principal.id
- 'mary'
+ 'users.mary'
>>> principal.title
'Mary'
>>> principal.description
@@ -308,7 +310,7 @@
>>> event.principal is principal
True
>>> event.info
- PrincipalInfo('mary')
+ PrincipalInfo('users.mary')
>>> event.request is request
True
@@ -342,7 +344,7 @@
To use the factory, create it with the info (interfaces.IPrincipalInfo) of
the principal to create:
- >>> info = PrincipalInfo('sam', 'Sam', 'A site user.')
+ >>> info = PrincipalInfo('users.sam', 'sam', 'Sam', 'A site user.')
>>> factory = FoundPrincipalFactory(info)
>>> principal = factory()
@@ -350,7 +352,7 @@
and description:
>>> principal.id
- 'sam'
+ 'users.sam'
>>> principal.title
'Sam'
>>> principal.description
@@ -363,7 +365,7 @@
>>> event.principal is principal
True
>>> event.info
- PrincipalInfo('sam')
+ PrincipalInfo('users.sam')
Listeners can subscribe to this event to perform additional operations
when the 'found' principal is created.
Modified: Zope3/trunk/src/zope/app/authentication/principalfolder.zcml
===================================================================
--- Zope3/trunk/src/zope/app/authentication/principalfolder.zcml 2005-04-01 22:43:52 UTC (rev 29816)
+++ Zope3/trunk/src/zope/app/authentication/principalfolder.zcml 2005-04-01 22:57:54 UTC (rev 29817)
@@ -4,11 +4,11 @@
i18n_domain="zope"
>
- <content class=".principalfolder.PrincipalInformation">
+ <content class=".principalfolder.InternalPrincipal">
<require
permission="zope.ManageServices"
interface=".principalfolder.IInternalPrincipal"
- set_schema=".principalfolder.IInternalPrincipal"
+ set_schema=".principalfolder.IInternalPrincipal"
/>
</content>
@@ -17,7 +17,7 @@
<require
permission="zope.ManageServices"
interface="zope.app.container.interfaces.IContainer" />
-
+
<require
permission="zope.ManageServices"
attributes="prefix" />
More information about the Zope3-Checkins
mailing list