[Checkins] SVN: zope.authentication/trunk/s Get some shape.

Dan Korostelev nadako at gmail.com
Wed Mar 11 18:31:33 EDT 2009


Log message for revision 97931:
  Get some shape.

Changed:
  U   zope.authentication/trunk/setup.py
  U   zope.authentication/trunk/src/zope/authentication/__init__.py
  U   zope.authentication/trunk/src/zope/authentication/basicauthadapter.py
  D   zope.authentication/trunk/src/zope/authentication/browser/
  U   zope.authentication/trunk/src/zope/authentication/configure.zcml
  U   zope.authentication/trunk/src/zope/authentication/ftpauth.py
  D   zope.authentication/trunk/src/zope/authentication/i18n.py
  U   zope.authentication/trunk/src/zope/authentication/interfaces.py
  U   zope.authentication/trunk/src/zope/authentication/loginpassword.py
  A   zope.authentication/trunk/src/zope/authentication/logout.py
  U   zope.authentication/trunk/src/zope/authentication/logout.txt
  U   zope.authentication/trunk/src/zope/authentication/principal.py
  A   zope.authentication/trunk/src/zope/authentication/principalterms.txt
  U   zope.authentication/trunk/src/zope/authentication/tests/__init__.py
  D   zope.authentication/trunk/src/zope/authentication/tests/perm.zcml
  D   zope.authentication/trunk/src/zope/authentication/tests/perm_duplicate.zcml
  D   zope.authentication/trunk/src/zope/authentication/tests/principal.zcml
  U   zope.authentication/trunk/src/zope/authentication/tests/test_basicauthadapter.py
  U   zope.authentication/trunk/src/zope/authentication/tests/test_ftpauth.py
  U   zope.authentication/trunk/src/zope/authentication/tests/test_loginpassword.py
  U   zope.authentication/trunk/src/zope/authentication/tests/test_logout.py
  D   zope.authentication/trunk/src/zope/authentication/tests/test_permission.py
  A   zope.authentication/trunk/src/zope/authentication/tests/test_principal.py
  D   zope.authentication/trunk/src/zope/authentication/tests/test_principallogging.py
  D   zope.authentication/trunk/src/zope/authentication/tests/test_principalregistry.py
  A   zope.authentication/trunk/src/zope/authentication/tests/test_principalterms.py
  D   zope.authentication/trunk/src/zope/authentication/tests/test_securitydirectives.py
  D   zope.authentication/trunk/src/zope/authentication/tests/test_vocabulary.py
  D   zope.authentication/trunk/src/zope/authentication/vocabulary.py

-=-
Modified: zope.authentication/trunk/setup.py
===================================================================
--- zope.authentication/trunk/setup.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/setup.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -32,18 +32,10 @@
           'Detailed Documentation\n' +
           '======================\n'
           + '\n\n' +
-          read('src', 'zope', 'app', 'security', 'globalprincipals.txt')
+          read('src', 'zope', 'authentication', 'logout.txt')
           + '\n\n' +
-          read('src', 'zope', 'app', 'security', 'logout.txt')
+          read('src', 'zope', 'authentication', 'principalterms.txt')
           + '\n\n' +
-          read('src', 'zope', 'app', 'security', 'browser',
-               'authutilitysearchview.txt')
-          + '\n\n' +
-          read('src', 'zope', 'app', 'security', 'browser', 'loginlogout.txt')
-          + '\n\n' +
-          read('src', 'zope', 'app', 'security', 'browser',
-               'principalterms.txt')
-          + '\n\n' +
           read('CHANGES.txt')
           ),
       keywords = "zope security authentication",
@@ -68,6 +60,15 @@
                         'zope.i18nmessageid',
                         'zope.interface',
                         'zope.schema',
+                        
+                        'zope.publisher', # XXX: this is for ILoginPassword
+                                          # adapters that should be moved
+                                          # elsewhere, probably to zope.publisher
+
+                        'zope.site', # XXX: this shouldn't be needed
+                        'zope.app.component', # XXX: this is for testing, until
+                        'zope.app.testing',   # we got testingNextUtility in
+                                              # a sane place or rewrite tests.
                         ],
       include_package_data = True,
       zip_safe = False,

Modified: zope.authentication/trunk/src/zope/authentication/__init__.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/__init__.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/__init__.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,45 +1 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Zope Application-specific Security code
-
-$Id$
-"""
-from zope.component import adapts
-from zope.interface import implements, Interface
-from zope.app.security import interfaces
-
-
-class LogoutSupported(object):
-    """A class that can be registered as an adapter to flag logout support."""
-
-    adapts(Interface)
-
-    implements(interfaces.ILogoutSupported)
-
-    def __init__(self, dummy):
-        pass
-
-
-class NoLogout(object):
-    """An adapter for IAuthentication utilities that don't implement ILogout."""
-
-    adapts(interfaces.IAuthentication)
-
-    implements(interfaces.ILogout)
-
-    def __init__(self, auth):
-        pass
-
-    def logout(self, request):
-        pass
+# i am a package
\ No newline at end of file

Modified: zope.authentication/trunk/src/zope/authentication/basicauthadapter.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/basicauthadapter.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/basicauthadapter.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -17,9 +17,10 @@
 """
 from zope.component import adapts
 from zope.publisher.interfaces.http import IHTTPCredentials
-from zope.app.security.loginpassword import LoginPassword
 
+from zope.authentication.loginpassword import LoginPassword
 
+
 class BasicAuthAdapter(LoginPassword):
     """Adapter for handling HTTP Basic Auth."""
 

Modified: zope.authentication/trunk/src/zope/authentication/configure.zcml
===================================================================
--- zope.authentication/trunk/src/zope/authentication/configure.zcml	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/configure.zcml	2009-03-11 22:31:33 UTC (rev 97931)
@@ -3,7 +3,7 @@
     i18n_domain="zope"
     >
 
-  <adapter factory=".NoLogout" />
+  <adapter factory=".logout.NoLogout" />
 
   <adapter
       factory=".basicauthadapter.BasicAuthAdapter"
@@ -17,9 +17,6 @@
       for="zope.publisher.interfaces.ftp.IFTPCredentials"
       />
 
-  <utility
-      component=".principalregistry.fallback_unauthenticated_principal"
-      provides=".interfaces.IFallbackUnauthenticatedPrincipal"
-      />
+  <adapter factory=".principal.PrincipalTerms" />
 
 </configure>

Modified: zope.authentication/trunk/src/zope/authentication/ftpauth.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/ftpauth.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/ftpauth.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -17,8 +17,9 @@
 """
 from zope.component import adapts
 from zope.publisher.interfaces.ftp import IFTPCredentials
-from zope.app.security.loginpassword import LoginPassword
 
+from zope.authentication.loginpassword import LoginPassword
+
 class FTPAuth(LoginPassword):
     """Adapter for handling common FTP authentication."""
 

Deleted: zope.authentication/trunk/src/zope/authentication/i18n.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/i18n.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/i18n.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,17 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-import zope.i18nmessageid
-
-_ = zope.i18nmessageid.MessageFactory("zope")

Modified: zope.authentication/trunk/src/zope/authentication/interfaces.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/interfaces.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/interfaces.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,18 +11,19 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Zope Application-specific Security Interfaces
+"""Authentication interfaces
 
 $Id$
 """
 from zope.interface import Interface
-from zope.security.interfaces import IPrincipal, IPermission, IGroup
+from zope.security.interfaces import IPrincipal, IGroup
 from zope.schema.interfaces import ISource
 
+
 class PrincipalLookupError(LookupError):
-    """A prncipal could not be found for a principal id
-    """
+    """No principal for given principal id"""
 
+
 class IUnauthenticatedPrincipal(IPrincipal):
     """A principal that hasn't been authenticated.
 
@@ -36,22 +37,21 @@
     This principal can be used by publications to set on a request if
     no principal, not even an unauthenticated principal, was returned
     by any authentication utility to fulfill the contract of IApplicationRequest.
-
     """
 
 
 class IUnauthenticatedGroup(IGroup):
-    """A group containing unauthenticated users
-    """
+    """A group containing unauthenticated users"""
 
+
 class IAuthenticatedGroup(IGroup):
-    """A group containing authenticated users
-    """
+    """A group containing authenticated users"""
 
+
 class IEveryoneGroup(IGroup):
-    """A group containing all users
-    """
+    """A group containing all users"""
 
+
 class IAuthentication(Interface):
     """Provide support for establishing principals for requests.
 
@@ -90,13 +90,11 @@
         based on user names and passwords might request
         an adapter for the request as in::
 
-          getpw=getAdapter(request,
-                       ILoginPassword, place=self)
+          getpw = getAdapter(request, context=self)
 
-        The place keyword argument is used to control
-        where the ILoginPassword component is
-        searched for. This is necessary because
-        requests are placeless.
+        The `context` keyword argument is used to control
+        where the ILoginPassword component is searched for.
+        This is necessary because requests are placeless.
         """
 
     def unauthenticatedPrincipal():
@@ -104,7 +102,7 @@
 
         Return None if no unauthenticated principal is defined.
 
-        The unauthenticated principal must be an IUnauthenticatedPrincipal.
+        The unauthenticated principal must provide IUnauthenticatedPrincipal.
         """
 
     def unauthorized(id, request):
@@ -142,7 +140,7 @@
 class ILoginPassword(Interface):
     """A password based login.
 
-    An `IAuthentication` would use this (adapting a request),
+    An `IAuthentication` utility may use this (adapting a request),
     to discover the login/password passed from the user, or to
     indicate that a login is required.
     """

Modified: zope.authentication/trunk/src/zope/authentication/loginpassword.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/loginpassword.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/loginpassword.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,14 +11,19 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Login/Password provider
+"""Login/Password provider. 
 
 $Id$
 """
 from zope.interface import implements
-from zope.app.security.interfaces import ILoginPassword
+from zope.authentication.interfaces import ILoginPassword
 
+
 class LoginPassword(object):
+    """Basic ILoginPassword implementation.
+    
+    This class can be used as a base for implementing ILoginPassword adapters.
+    """
 
     implements(ILoginPassword)
 
@@ -27,7 +32,7 @@
         if login is None:
             self.__password = None
         else:
-            self.__password = password or ""
+            self.__password = password or ''
 
     def getLogin(self):
         return self.__login

Added: zope.authentication/trunk/src/zope/authentication/logout.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/logout.py	                        (rev 0)
+++ zope.authentication/trunk/src/zope/authentication/logout.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""ILogout implementations
+
+$Id$
+"""
+from zope.component import adapts
+from zope.interface import implements, Interface
+
+from zope.authentication.interfaces import IAuthentication
+from zope.authentication.interfaces import ILogout, ILogoutSupported
+
+
+class NoLogout(object):
+    """An adapter for IAuthentication utilities that don't implement ILogout."""
+
+    adapts(IAuthentication)
+    implements(ILogout)
+
+    def __init__(self, auth):
+        pass
+
+    def logout(self, request):
+        pass
+
+
+class LogoutSupported(object):
+    """A class that can be registered as an adapter to flag logout support."""
+
+    adapts(Interface)
+    implements(ILogoutSupported)
+
+    def __init__(self, dummy):
+        pass


Property changes on: zope.authentication/trunk/src/zope/authentication/logout.py
___________________________________________________________________
Added: svn:keywords
   + Id

Modified: zope.authentication/trunk/src/zope/authentication/logout.txt
===================================================================
--- zope.authentication/trunk/src/zope/authentication/logout.txt	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/logout.txt	2009-03-11 22:31:33 UTC (rev 97931)
@@ -4,7 +4,7 @@
 
 Logout support is defined by a simple interface ILogout:
 
-  >>> from zope.app.security.interfaces import ILogout
+  >>> from zope.authentication.interfaces import ILogout
 
 that has a single 'logout' method.
 
@@ -45,7 +45,7 @@
 
 The class:
 
-  >>> from zope.app.security import NoLogout
+  >>> from zope.authentication.logout import NoLogout
 
 can be registered as a fallback provider of ILogout for IAuthentication
 components that are not otherwise adaptable to ILogout. NoLogout's logout
@@ -64,13 +64,10 @@
 Because logout support is site-configurable, Zope provides an adapter that,
 when registered, indicates that the site is configured for logout:
 
-  >>> from zope.app.security import LogoutSupported
+  >>> from zope.authentication.logout import LogoutSupported
 
 This class merely serves as a flag as it implements ILogoutSupported:
 
-  >>> from zope.app.security.interfaces import ILogoutSupported
+  >>> from zope.authentication.interfaces import ILogoutSupported
   >>> ILogoutSupported.implementedBy(LogoutSupported)
   True
-
-For more information on login/logout UI, see
-zope/app/security/browser/loginlogout.txt.

Modified: zope.authentication/trunk/src/zope/authentication/principal.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/principal.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/principal.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2002 Zope Corporation and Contributors.
+# Copyright (c) 2009 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,20 +11,163 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Principals.
+"""Principal source and helper function
 
 $Id$
 """
-from zope.component import getUtility
-from zope.app.security.interfaces import PrincipalLookupError
-from zope.app.security.interfaces import IAuthentication
+from zope.browser.interfaces import ITerms
+from zope.component import getUtility, adapts
+from zope.interface import implements, Interface
+from zope.schema.interfaces import ISourceQueriables
+from zope.site.next import queryNextUtility # XXX: move this to zope.component
 
+from zope.authentication.interfaces import IAuthentication, IPrincipalSource
+from zope.authentication.interfaces import PrincipalLookupError
+
+
 def checkPrincipal(context, principal_id):
+    """An utility function to check if there's a principal for given principal id"""
     auth = getUtility(IAuthentication, context=context)
     try:
         if auth.getPrincipal(principal_id):
             return
     except PrincipalLookupError:
         pass
+    raise ValueError("Undefined principal id", principal_id)
 
-    raise ValueError("Undefined principal id", principal_id)
+
+class PrincipalSource(object):
+    """Generic Principal Source"""
+
+    implements(IPrincipalSource, ISourceQueriables)
+
+    def __contains__(self, id):
+        """Test for the existence of a user.
+
+        We want to check whether the system knows about a particular
+        principal, which is referenced via its id. The source will go through
+        the most local authentication utility to look for the
+        principal. Whether the utility consults other utilities to give an
+        answer is up to the utility itself.
+
+        First we need to create a dummy utility that will return a user, if
+        the id is 'bob'.
+
+        >>> class DummyUtility:
+        ...     implements(IAuthentication)
+        ...     def getPrincipal(self, id):
+        ...         if id == 'bob':
+        ...             return id
+        ...         raise PrincipalLookupError(id)
+
+        Since we do not want to bring up the entire component architecture, we
+        simply monkey patch the `getUtility()` method to always return our
+        dummy authentication utility.
+
+        >>> from zope.component import provideUtility
+        >>> provideUtility(DummyUtility())
+
+        Now initialize the principal source and test the method
+
+        >>> source = PrincipalSource()
+        >>> 'jim' in source
+        False
+        >>> 'bob' in source
+        True
+        """
+        auth = getUtility(IAuthentication)
+        try:
+            auth.getPrincipal(id)
+        except PrincipalLookupError:
+            return False
+        else:
+            return True
+
+    def getQueriables(self):
+        """Returns an iteratable of queriables.
+
+        Queriables are responsible for providing interfaces to search for
+        principals by a set of given parameters (can be different for the
+        various queriables). This method will walk up through all of the
+        authentication utilities to look for queriables.
+
+        >>> class DummyUtility1:
+        ...     implements(IAuthentication)
+        ...     __parent__ = None
+        ...     def __repr__(self): return 'dummy1'
+        >>> dummy1 = DummyUtility1()
+
+        >>> class DummyUtility2:
+        ...     implements(ISourceQueriables, IAuthentication)
+        ...     __parent__ = None
+        ...     def getQueriables(self):
+        ...         return ('1', 1), ('2', 2), ('3', 3)
+        >>> dummy2 = DummyUtility2()
+
+        >>> class DummyUtility3(DummyUtility2):
+        ...     implements(IAuthentication)
+        ...     def getQueriables(self):
+        ...         return ('4', 4),
+        >>> dummy3 = DummyUtility3()
+
+        >>> from zope.app.component.testing import testingNextUtility
+        >>> testingNextUtility(dummy1, dummy2, IAuthentication)
+        >>> testingNextUtility(dummy2, dummy3, IAuthentication)
+
+        >>> from zope.component import provideUtility
+        >>> provideUtility(dummy1)
+
+        >>> source = PrincipalSource()
+        >>> list(source.getQueriables())
+        [(u'0', dummy1), (u'1.1', 1), (u'1.2', 2), (u'1.3', 3), (u'2.4', 4)]
+        """
+        i = 0
+        auth = getUtility(IAuthentication)
+        yielded = []
+        while True:
+            queriables = ISourceQueriables(auth, None)
+            if queriables is None:
+                yield unicode(i), auth
+            else:
+                for qid, queriable in queriables.getQueriables():
+                    # ensure that we dont return same yielded utility more
+                    # then once
+                    if queriable not in yielded:
+                        yield unicode(i)+'.'+unicode(qid), queriable
+                        yielded.append(queriable)
+            auth = queryNextUtility(auth, IAuthentication)
+            if auth is None:
+                break
+            i += 1
+
+
+class PrincipalTerms(object):
+
+    implements(ITerms)
+    adapts(IPrincipalSource, Interface)
+
+    def __init__(self, context, request):
+        self.context = context
+
+    def getTerm(self, principal_id):
+        if principal_id not in self.context:
+            raise LookupError(principal_id)
+
+        auth = getUtility(IAuthentication)
+        principal = auth.getPrincipal(principal_id)
+
+        if principal is None:
+            raise LookupError(principal_id)
+
+        return PrincipalTerm(principal_id.encode('base64').strip().replace('=', '_'),
+                             principal.title)
+
+    def getValue(self, token):
+        return token.replace('_', '=').decode('base64')
+
+
+class PrincipalTerm(object):
+
+    def __init__(self, token, title):
+        self.token = token
+        self.title = title

Copied: zope.authentication/trunk/src/zope/authentication/principalterms.txt (from rev 97918, zope.authentication/trunk/src/zope/authentication/browser/principalterms.txt)
===================================================================
--- zope.authentication/trunk/src/zope/authentication/principalterms.txt	                        (rev 0)
+++ zope.authentication/trunk/src/zope/authentication/principalterms.txt	2009-03-11 22:31:33 UTC (rev 97931)
@@ -0,0 +1,68 @@
+===============
+Principal Terms
+===============
+
+Principal Terms are used to support browser interfaces for searching principal
+sources. They provide access to tokens and titles for values. The principal
+terms view uses an authentication utility to get principal titles. Let's
+create an authentication utility to demonstrate how this works:
+
+  >>> class Principal:
+  ...     def __init__(self, id, title):
+  ...         self.id, self.title = id, title
+
+  >>> from zope.interface import implements
+  >>> from zope.authentication.interfaces import IAuthentication
+  >>> from zope.authentication.interfaces import PrincipalLookupError
+  >>> class AuthUtility:
+  ...     implements(IAuthentication)
+  ...     data = {'jim': 'Jim Fulton', 'stephan': 'Stephan Richter'}
+  ...
+  ...     def getPrincipal(self, id):
+  ...         title = self.data.get(id)
+  ...         if title is not None:
+  ...             return Principal(id, title)
+  ...         raise PrincipalLookupError
+
+Now we need to install the authentication utility:
+
+  >>> from zope.component import provideUtility
+  >>> provideUtility(AuthUtility(), IAuthentication)
+
+We need a principal source so that we can create a view from it.
+
+  >>> from zope.component import getUtility
+  >>> class PrincipalSource:
+  ...     def __contains__(self, id):
+  ...          auth = getUtility(IAuthentication)
+  ...          try:
+  ...              auth.getPrincipal(id)
+  ...          except PrincipalLookupError:
+  ...              return False
+  ...          else:
+  ...              return True
+
+Now we can create an terms view:
+
+  >>> from zope.authentication.principal import PrincipalTerms
+  >>> terms = PrincipalTerms(PrincipalSource(), None)
+
+Now we can ask the terms view for terms:
+
+  >>> term = terms.getTerm('stephan')
+  >>> term.title
+  'Stephan Richter'
+  >>> term.token
+  'c3RlcGhhbg__'
+
+If we ask for a term that does not exist, we get a lookup error:
+
+  >>> terms.getTerm('bob')
+  Traceback (most recent call last):
+  ...
+  LookupError: bob
+
+If we have a token, we can get the principal id for it.
+
+  >>> terms.getValue('c3RlcGhhbg__')
+  'stephan'

Modified: zope.authentication/trunk/src/zope/authentication/tests/__init__.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/__init__.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/__init__.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,33 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Security Tests
-
-$Id$
-"""
-import zope.component
-from zope.security.interfaces import IPermission
-from zope.security.permission import Permission
-
-def addCheckerPublic():
-    """Add the CheckerPublic permission as 'zope.Public'"""
-
-    perm = Permission('zope.Public', 'Public',
-            """Special permission used for resources that are always public
-
-            The public permission is effectively an optimization, sine
-            it allows security computation to be bypassed.
-            """
-            )
-    gsm = zope.component.getGlobalSiteManager()
-    gsm.registerUtility(perm, IPermission, perm.id)

Deleted: zope.authentication/trunk/src/zope/authentication/tests/perm.zcml
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/perm.zcml	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/perm.zcml	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,13 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    i18n_domain="zope"
-    >
-
-  <include package="zope.app.security" file="meta.zcml"/>
-
-  <permission
-      id="Can.Do.It"
-      title="A Permissive Permission"
-      description="This permission lets you do anything" />
- 
-</configure>

Deleted: zope.authentication/trunk/src/zope/authentication/tests/perm_duplicate.zcml
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/perm_duplicate.zcml	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/perm_duplicate.zcml	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,17 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    i18n_domain="zope">
-
-  <include package="zope.app.security" file="meta.zcml"/>
-
-  <permission
-      id="Can.Do.It"
-      title="A Permissive Permission"
-      description="This permission lets you do anything" />
-
-  <permission
-      id="Can.Do.It"
-      title="A Permissive Permission"
-      description="This permission lets you do anything" />
- 
-</configure>

Deleted: zope.authentication/trunk/src/zope/authentication/tests/principal.zcml
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/principal.zcml	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/principal.zcml	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,25 +0,0 @@
-<configure
-    xmlns="http://namespaces.zope.org/zope"
-    i18n_domain="zope"
-    >
-
-  <include package="zope.app.security" file="meta.zcml"/>
-
-  <principal
-      id="zope.p1"
-      title="Sir Tim Peters"
-      description="Tim Peters"
-      login="tim"
-      password_manager="SHA1"
-      password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
-      />
-
-  <principal
-      id="zope.p2"
-      title="Sir Jim Fulton"
-      description="Jim Fulton"
-      login="jim"
-      password="123"
-      />
-
-</configure>

Modified: zope.authentication/trunk/src/zope/authentication/tests/test_basicauthadapter.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_basicauthadapter.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_basicauthadapter.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -17,7 +17,7 @@
 """
 import unittest
 
-from zope.app.security.basicauthadapter import BasicAuthAdapter
+from zope.authentication.basicauthadapter import BasicAuthAdapter
 
 class Request(object):
 

Modified: zope.authentication/trunk/src/zope/authentication/tests/test_ftpauth.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_ftpauth.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_ftpauth.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -17,9 +17,10 @@
 """
 from unittest import TestCase, TestSuite, main, makeSuite
 from zope.publisher.interfaces.ftp import IFTPCredentials
-from zope.app.security.ftpauth import FTPAuth
 from zope.interface import implements
 
+from zope.authentication.ftpauth import FTPAuth
+
 class FTPCredentials(object):
     __doc__ = IFTPCredentials.__doc__
 

Modified: zope.authentication/trunk/src/zope/authentication/tests/test_loginpassword.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_loginpassword.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_loginpassword.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -17,7 +17,7 @@
 """
 import unittest
 
-from zope.app.security.loginpassword import LoginPassword
+from zope.authentication.loginpassword import LoginPassword
 
 class Test(unittest.TestCase):
 

Modified: zope.authentication/trunk/src/zope/authentication/tests/test_logout.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_logout.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_logout.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -15,14 +15,13 @@
 $Id$
 """
 import unittest
-
 from zope.testing import doctest
-from zope.interface import implements
+
 from zope.component import provideAdapter, adapts
+from zope.interface import implements
 from zope.publisher.tests.httprequest import TestRequest
 
-from zope.app.testing import placelesssetup
-from zope.app.security import interfaces
+from zope.authentication.interfaces import IAuthentication
 
 
 def test_suite():
@@ -33,13 +32,7 @@
                    'TestRequest': TestRequest,
                    'implements': implements,
                    'adapts': adapts,
-                   'IAuthentication': interfaces.IAuthentication
+                   'IAuthentication': IAuthentication
                   },
-            setUp=placelesssetup.setUp,
-            tearDown=placelesssetup.tearDown,
             ),
         ))
-
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Deleted: zope.authentication/trunk/src/zope/authentication/tests/test_permission.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_permission.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_permission.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,42 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Doctests for 'permission' module.
-
-$Id$
-"""
-import unittest
-import doctest
-
-def test_bbb_imports():
-    """
-    Let's test that backward-compatibility imports still work:
-    
-      >>> from zope.app.security import permission as old
-      >>> from zope.localpermission import permission as new
-    
-      >>> old.NULL_ID is new.NULL_ID
-      True
-      >>> old.LocalPermission is new.LocalPermission
-      True
-      >>> old.setIdOnActivation is new.setIdOnActivation
-      True
-      >>> old.unsetIdOnDeactivation is new.unsetIdOnDeactivation
-      True
-
-    """
-
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocTestSuite(),
-        ))

Copied: zope.authentication/trunk/src/zope/authentication/tests/test_principal.py (from rev 97918, zope.authentication/trunk/src/zope/authentication/tests/test_vocabulary.py)
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_principal.py	                        (rev 0)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_principal.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test for principal lookup related functionality
+
+$Id$
+"""
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+
+
+def test_suite():
+    return unittest.TestSuite((
+        DocTestSuite('zope.authentication.principal'),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

Deleted: zope.authentication/trunk/src/zope/authentication/tests/test_principallogging.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_principallogging.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_principallogging.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,39 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Test for PrincipalLogging.
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-def test_bbb_imports():
-    """
-    Let's check that permission vocabularies that were moved to
-    zope.security are still importable from original place.
-    
-      >>> import zope.publisher.principallogging as new
-      >>> import zope.app.security.principallogging as old
-      >>> old.PrincipalLogging is new.PrincipalLogging
-      True
-    
-    """
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite(),
-        ))
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Deleted: zope.authentication/trunk/src/zope/authentication/tests/test_principalregistry.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_principalregistry.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_principalregistry.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,156 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Global Authentication Serive or Principal Registry Tests
-
-$Id$
-"""
-import unittest
-from zope.interface import implements
-from zope.app.security.interfaces import PrincipalLookupError
-from zope.publisher.interfaces.http import IHTTPCredentials
-
-from zope.app.testing import ztapi
-from zope.app.component.testing import PlacefulSetup
-
-from zope.app.security.basicauthadapter import BasicAuthAdapter
-from zope.app.security.interfaces import ILoginPassword
-from zope.app.security.principalregistry import PrincipalRegistry
-from zope.app.security.principalregistry import DuplicateLogin, DuplicateId
-
-
-class Request(object):
-
-    implements(IHTTPCredentials)
-
-    def __init__(self, lpw):
-        self.__lpw = lpw
-
-    def _authUserPW(self):
-        return self.__lpw
-
-    challenge = None
-    def unauthorized(self, challenge):
-        self.challenge = challenge
-
-
-class Test(PlacefulSetup, unittest.TestCase):
-
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-
-        ztapi.provideAdapter(
-            IHTTPCredentials, ILoginPassword, BasicAuthAdapter)
-
-        self.reg = PrincipalRegistry()
-
-        self.reg.definePrincipal('1', 'Tim Peters', 'Sir Tim Peters',
-                                 'tim', '123')
-        self.reg.definePrincipal('2', 'Jim Fulton', 'Sir Jim Fulton',
-                                 'jim', '456')
-
-    def testRegistered(self):
-        p = self.reg.getPrincipal('1')
-        self.assertEqual(p.id, '1')
-        self.assertEqual(p.title, 'Tim Peters')
-        self.assertEqual(p.description, 'Sir Tim Peters')
-        p = self.reg.getPrincipal('2')
-        self.assertEqual(p.id, '2')
-        self.assertEqual(p.title, 'Jim Fulton')
-        self.assertEqual(p.description, 'Sir Jim Fulton')
-
-        self.assertEqual(len(self.reg.getPrincipals('')), 2)
-
-    def testUnRegistered(self):
-        self.assertRaises(PrincipalLookupError, self.reg.getPrincipal, '3')
-
-    def testDup(self):
-        self.assertRaises(DuplicateId,
-                          self.reg.definePrincipal,
-                          '1', 'Tim Peters', 'Sir Tim Peters',
-                          'tim2', '123')
-        self.assertRaises(DuplicateLogin,
-                          self.reg.definePrincipal,
-                          '3', 'Tim Peters', 'Sir Tim Peters',
-                          'tim', '123')
-        self.assertRaises(PrincipalLookupError, self.reg.getPrincipal, '3')
-        self.assertEqual(len(self.reg.getPrincipals('')), 2)
-
-    def testSearch(self):
-        r = self.reg.getPrincipals('J')
-        self.assertEquals(len(r), 1)
-        self.failUnless(r[0] is self.reg.getPrincipal('2'))
-
-    def testByLogin(self):
-        tim = self.reg.getPrincipalByLogin('tim')
-        self.assertEquals(tim.getLogin(), 'tim')
-        jim = self.reg.getPrincipalByLogin('jim')
-        self.assertEquals(jim.getLogin(), 'jim')
-        self.assertRaises(KeyError,
-                          self.reg.getPrincipalByLogin, 'kim')
-
-    def testValidation(self):
-        tim = self.reg.getPrincipalByLogin('tim')
-        self.assert_(tim.validate('123'))
-        self.failIf(tim.validate('456'))
-        self.failIf(tim.validate(''))
-        self.failIf(tim.validate('1234'))
-        self.failIf(tim.validate('12'))
-
-    def testAuthenticate(self):
-        req = Request(('tim', '123'))
-        pid = self.reg.authenticate(req).id
-        self.assertEquals(pid, '1')
-        req = Request(('tim', '1234'))
-        p = self.reg.authenticate(req)
-        self.assertEquals(p, None)
-        req = Request(('kim', '123'))
-        p = self.reg.authenticate(req)
-        self.assertEquals(p, None)
-
-    def testUnauthorized(self):
-        request = Request(None)
-        self.reg.unauthorized(self.reg.unauthenticatedPrincipal(), request)
-        self.assertEquals(request.challenge, 'basic realm="Zope"')
-        request = Request(None)
-        self.reg.unauthorized(None, request)
-        self.assertEquals(request.challenge, 'basic realm="Zope"')
-        request = Request(None)
-        self.reg.unauthorized("1", request)
-        self.assertEquals(request.challenge, None)
-
-    def testDefaultPrincipal(self):
-        self.assertEquals(self.reg.unauthenticatedPrincipal(), None)
-        self.assertRaises(DuplicateId, self.reg.defineDefaultPrincipal,
-                          "1", "tim")
-        self.reg.defineDefaultPrincipal("everybody", "Default Principal")
-        self.assertEquals(self.reg.unauthenticatedPrincipal().id, "everybody")
-        self.reg.defineDefaultPrincipal("anybody", "Default Principal",
-                                        "This is the default headmaster")
-        self.assertEquals(self.reg.unauthenticatedPrincipal().id, "anybody")
-        self.assertRaises(PrincipalLookupError,
-                          self.reg.getPrincipal, "everybody")
-        p = self.reg.getPrincipal("anybody")
-        self.assertEquals(p.id, "anybody")
-        self.assertEquals(p.title, "Default Principal")
-        self.assertRaises(DuplicateId, self.reg.definePrincipal,
-                          "anybody", "title")
-
-
-def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(Test),
-        ))
-
-if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')

Copied: zope.authentication/trunk/src/zope/authentication/tests/test_principalterms.py (from rev 97920, zope.authentication/trunk/src/zope/authentication/browser/tests.py)
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_principalterms.py	                        (rev 0)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_principalterms.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for PrincipalTerms
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import unittest
+from zope.testing import doctest
+
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite('../principalterms.txt'),
+        ))

Deleted: zope.authentication/trunk/src/zope/authentication/tests/test_securitydirectives.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_securitydirectives.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_securitydirectives.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,79 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Security Directives Tests
-
-$Id$
-"""
-import unittest
-from zope.configuration.config import ConfigurationConflictError
-from zope.configuration import xmlconfig
-
-from zope.component import getUtility
-from zope.app.testing import ztapi
-from zope.app.testing.placelesssetup import PlacelessSetup
-
-from zope.security.interfaces import IPermission
-from zope.app.security.interfaces import IAuthentication
-from zope.app.security.principalregistry import principalRegistry
-import zope.app.security.tests
-
-
-class TestBase(PlacelessSetup):
-
-    def setUp(self):
-        super(TestBase, self).setUp()
-        ztapi.provideUtility(IAuthentication, principalRegistry)
-
-
-class TestPrincipalDirective(TestBase, unittest.TestCase):
-
-    def testRegister(self):
-        context = xmlconfig.file("principal.zcml", zope.app.security.tests)
-        reg=principalRegistry
-
-        p = reg.getPrincipal('zope.p1')
-        self.assertEqual(p.id, 'zope.p1')
-        self.assertEqual(p.title, 'Sir Tim Peters')
-        self.assertEqual(p.description, 'Tim Peters')
-        p = reg.getPrincipal('zope.p2')
-        self.assertEqual(p.id, 'zope.p2')
-        self.assertEqual(p.title, 'Sir Jim Fulton')
-        self.assertEqual(p.description, 'Jim Fulton')
-
-        self.assertEqual(len(reg.getPrincipals('')), 2)
-
-
-class TestPermissionDirective(TestBase, unittest.TestCase):
-
-    def testRegister(self):
-        context = xmlconfig.file("perm.zcml", zope.app.security.tests)
-        perm = getUtility(IPermission, "Can.Do.It")
-        self.failUnless(perm.id.endswith('Can.Do.It'))
-        self.assertEqual(perm.title, 'A Permissive Permission')
-        self.assertEqual(perm.description,
-                         'This permission lets you do anything')
-
-    def testDuplicationRegistration(self):
-        self.assertRaises(ConfigurationConflictError, xmlconfig.file,
-                          "perm_duplicate.zcml", zope.app.security.tests)
-
-
-def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(TestPrincipalDirective),
-        unittest.makeSuite(TestPermissionDirective),
-        ))
-
-if __name__ == '__main__':
-    unittest.main()

Deleted: zope.authentication/trunk/src/zope/authentication/tests/test_vocabulary.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/tests/test_vocabulary.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/tests/test_vocabulary.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,42 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Permission vocabluary doc tests.
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-def test_bbb_imports():
-    """
-    Let's check that permission vocabularies that were moved to
-    zope.security are still importable from original place.
-    
-      >>> import zope.security.permission as new
-      >>> import zope.app.security.vocabulary as old
-      >>> old.PermissionsVocabulary is new.PermissionsVocabulary
-      True
-      >>> old.PermissionIdsVocabulary is new.PermissionIdsVocabulary
-      True
-    
-    """
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite(),
-        DocTestSuite('zope.app.security.vocabulary'),
-        ))
-
-if __name__ == '__main__':
-    unittest.main(defaultTest='test_suite')

Deleted: zope.authentication/trunk/src/zope/authentication/vocabulary.py
===================================================================
--- zope.authentication/trunk/src/zope/authentication/vocabulary.py	2009-03-11 22:31:29 UTC (rev 97930)
+++ zope.authentication/trunk/src/zope/authentication/vocabulary.py	2009-03-11 22:31:33 UTC (rev 97931)
@@ -1,138 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Permission Id Vocabulary.
-
-This vocabulary provides permission IDs.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import zope.component
-from zope.interface import implements
-from zope.schema.interfaces import ISourceQueriables
-from zope.site.next import queryNextUtility
-
-from zope.app.security.interfaces import IAuthentication
-from zope.app.security.interfaces import IPrincipalSource
-from zope.app.security.interfaces import PrincipalLookupError
-
-
-class PrincipalSource(object):
-    """Generic Principal Source"""
-    implements(IPrincipalSource, ISourceQueriables)
-
-    def __contains__(self, id):
-        """Test for the existence of a user.
-
-        We want to check whether the system knows about a particular
-        principal, which is referenced via its id. The source will go through
-        the most local authentication utility to look for the
-        principal. Whether the utility consults other utilities to give an
-        answer is up to the utility itself.
-
-        First we need to create a dummy utility that will return a user, if
-        the id is 'bob'.
-
-        >>> class DummyUtility:
-        ...     def getPrincipal(self, id):
-        ...         if id == 'bob':
-        ...             return id
-        ...         raise PrincipalLookupError(id)
-
-        Since we do not want to bring up the entire component architecture, we
-        simply monkey patch the `getUtility()` method to always return our
-        dummy authentication utility.
-
-        >>> temp = zope.component.getUtility
-        >>> zope.component.getUtility = lambda iface: DummyUtility()
-
-        Now initialize the principal source and test the method
-
-        >>> source = PrincipalSource()
-        >>> 'jim' in source
-        False
-        >>> 'bob' in source
-        True
-
-        Now revert our patch.
-
-        >>> zope.component.getUtility = temp
-        """
-        auth = zope.component.getUtility(IAuthentication)
-        try:
-            auth.getPrincipal(id)
-        except PrincipalLookupError:
-            return False
-        else:
-            return True
-
-    def getQueriables(self):
-        """Returns an iteratable of queriables.
-
-        Queriables are responsible for providing interfaces to search for
-        principals by a set of given parameters (can be different for the
-        various queriables). This method will walk up through all of the
-        authentication utilities to look for queriables.
-
-        >>> class DummyUtility1:
-        ...     implements(IAuthentication)
-        ...     __parent__ = None
-        ...     def __repr__(self): return 'dummy1'
-        >>> dummy1 = DummyUtility1()
-
-        >>> class DummyUtility2:
-        ...     implements(ISourceQueriables, IAuthentication)
-        ...     __parent__ = None
-        ...     def getQueriables(self):
-        ...         return ('1', 1), ('2', 2), ('3', 3)
-        >>> dummy2 = DummyUtility2()
-
-        >>> class DummyUtility3(DummyUtility2):
-        ...     implements(IAuthentication)
-        ...     def getQueriables(self):
-        ...         return ('4', 4),
-        >>> dummy3 = DummyUtility3()
-
-        >>> from zope.app.component.testing import testingNextUtility
-        >>> testingNextUtility(dummy1, dummy2, IAuthentication)
-        >>> testingNextUtility(dummy2, dummy3, IAuthentication)
-
-        >>> temp = zope.component.getUtility
-        >>> zope.component.getUtility = lambda iface: dummy1
-
-        >>> source = PrincipalSource()
-        >>> list(source.getQueriables())
-        [(u'0', dummy1), (u'1.1', 1), (u'1.2', 2), (u'1.3', 3), (u'2.4', 4)]
-
-        >>> zope.component.getUtility = temp
-        """
-        i = 0
-        auth = zope.component.getUtility(IAuthentication)
-        yielded = []
-        while True:
-            queriables = ISourceQueriables(auth, None)
-            if queriables is None:
-                yield unicode(i), auth
-            else:
-                for qid, queriable in queriables.getQueriables():
-                    # ensure that we dont return same yielded utility more
-                    # then once
-                    if queriable not in yielded:
-                        yield unicode(i)+'.'+unicode(qid), queriable
-                        yielded.append(queriable)
-            auth = queryNextUtility(auth, IAuthentication)
-            if auth is None:
-                break
-            i += 1



More information about the Checkins mailing list