[Checkins] SVN: zope.app.security/trunk/ The interfaces and some of helper functionality were moved into new "zope.authentication package". Provide bbb imports.
Dan Korostelev
nadako at gmail.com
Wed Mar 11 20:38:29 EDT 2009
Log message for revision 97943:
The interfaces and some of helper functionality were moved into new "zope.authentication package". Provide bbb imports.
Changed:
U zope.app.security/trunk/CHANGES.txt
U zope.app.security/trunk/buildout.cfg
U zope.app.security/trunk/setup.py
U zope.app.security/trunk/src/zope/app/security/__init__.py
U zope.app.security/trunk/src/zope/app/security/basicauthadapter.py
U zope.app.security/trunk/src/zope/app/security/browser/configure.zcml
U zope.app.security/trunk/src/zope/app/security/browser/principalterms.py
D zope.app.security/trunk/src/zope/app/security/browser/principalterms.txt
U zope.app.security/trunk/src/zope/app/security/browser/tests.py
U zope.app.security/trunk/src/zope/app/security/configure.zcml
U zope.app.security/trunk/src/zope/app/security/ftpauth.py
U zope.app.security/trunk/src/zope/app/security/interfaces.py
U zope.app.security/trunk/src/zope/app/security/loginpassword.py
D zope.app.security/trunk/src/zope/app/security/logout.txt
U zope.app.security/trunk/src/zope/app/security/principal.py
U zope.app.security/trunk/src/zope/app/security/tests/test_basicauthadapter.py
U zope.app.security/trunk/src/zope/app/security/tests/test_ftpauth.py
A zope.app.security/trunk/src/zope/app/security/tests/test_interfaces.py
U zope.app.security/trunk/src/zope/app/security/tests/test_loginpassword.py
U zope.app.security/trunk/src/zope/app/security/tests/test_logout.py
A zope.app.security/trunk/src/zope/app/security/tests/test_principal.py
U zope.app.security/trunk/src/zope/app/security/tests/test_vocabulary.py
U zope.app.security/trunk/src/zope/app/security/vocabulary.py
-=-
Modified: zope.app.security/trunk/CHANGES.txt
===================================================================
--- zope.app.security/trunk/CHANGES.txt 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/CHANGES.txt 2009-03-12 00:38:29 UTC (rev 97943)
@@ -5,6 +5,11 @@
3.7.0 (unreleased)
------------------
+- All interfaces, as well as some authentication-related helper classes and
+ functions (checkPrincipal, PrincipalSource, PrincipalTerms, etc.) were moved
+ into the new ``zope.authentication`` package. Backward-compatibility imports
+ are provided.
+
- The IPrincipal -> zope.publisher.interfaces.logginginfo.ILoggingInfo
adapter was moved to ``zope.publisher``. Backward-compatibility import
is provided.
Modified: zope.app.security/trunk/buildout.cfg
===================================================================
--- zope.app.security/trunk/buildout.cfg 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/buildout.cfg 2009-03-12 00:38:29 UTC (rev 97943)
@@ -1,6 +1,16 @@
[buildout]
-develop = . ../zope.localpermission ../zope.security ../zope.publisher
parts = test coverage-test coverage-report
+develop = .
+ ../zope.authentication
+ ../zope.localpermission
+ ../zope.publisher
+ ../zope.security
+
+ ../zope.component
+ ../../zope.app.testing
+ ../../zope.container
+ ../../zope.app.publisher
+# these are needed until we get new zope.component released
[test]
recipe = zc.recipe.testrunner
Modified: zope.app.security/trunk/setup.py
===================================================================
--- zope.app.security/trunk/setup.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/setup.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -34,16 +34,11 @@
+ '\n\n' +
read('src', 'zope', 'app', 'security', 'globalprincipals.txt')
+ '\n\n' +
- read('src', 'zope', 'app', 'security', 'logout.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 = "zope3 security authentication principal ftp http",
@@ -69,6 +64,7 @@
'zope.app.form',
'zope.app.pagetemplate',
'zope.app.publisher',
+ 'zope.authentication',
'zope.component',
'zope.configuration',
'zope.container',
Modified: zope.app.security/trunk/src/zope/app/security/__init__.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/__init__.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/__init__.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -15,36 +15,10 @@
$Id$
"""
-from zope.component import adapts
-from zope.interface import implements, Interface
-from zope.app.security import interfaces
-
# Register some standard types
import _protections
_protections.protect()
del _protections
-
-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
+# BBB: the code was moved to zope.authentication
+from zope.authentication.logout import LogoutSupported, NoLogout
Modified: zope.app.security/trunk/src/zope/app/security/basicauthadapter.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/basicauthadapter.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/basicauthadapter.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,29 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""HTTP Basic Authentication adapter
+"""Backward compatibility for the IHTTPCredentials -> ILoginPassword adapter
$Id$
"""
-from zope.component import adapts
-from zope.publisher.interfaces.http import IHTTPCredentials
-from zope.app.security.loginpassword import LoginPassword
-
-class BasicAuthAdapter(LoginPassword):
- """Adapter for handling HTTP Basic Auth."""
-
- adapts(IHTTPCredentials)
-
- def __init__(self, request):
- self.__request = request
- # TODO base64 decoding should be done here, not in request
- lpw = request._authUserPW()
- if lpw is None:
- login, password = None, None
- else:
- login, password = lpw
- super(BasicAuthAdapter, self).__init__(login, password)
-
- def needLogin(self, realm):
- self.__request.unauthorized('basic realm="%s"' % realm)
+# BBB, XXX: this may change in near future
+from zope.authentication.basicauthadapter import BasicAuthAdapter
Modified: zope.app.security/trunk/src/zope/app/security/browser/configure.zcml
===================================================================
--- zope.app.security/trunk/src/zope/app/security/browser/configure.zcml 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/browser/configure.zcml 2009-03-12 00:38:29 UTC (rev 97943)
@@ -10,13 +10,6 @@
factory="zope.app.security.browser.auth.AuthUtilitySearchView"
/>
- <adapter
- for="zope.app.security.interfaces.IPrincipalSource
- zope.publisher.interfaces.browser.IBrowserRequest"
- provides="zope.browser.interfaces.ITerms"
- factory="zope.app.security.browser.principalterms.PrincipalTerms"
- />
-
<browser:page
name="failsafelogin.html"
for="*"
Modified: zope.app.security/trunk/src/zope/app/security/browser/principalterms.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/browser/principalterms.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/browser/principalterms.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,45 +11,11 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Terms view for Principal Source
+"""Backward-compatibility imports for principal terms
$Id$
"""
-__docformat__ = "reStructuredText"
-from zope.component import getUtility, adapts
-from zope.interface import implements
-from zope.browser.interfaces import ITerms
-from zope.publisher.interfaces.browser import IBrowserRequest
-
-from zope.app.security.interfaces import IAuthentication, IPrincipalSource
-
-class Term(object):
-
- def __init__(self, token, title):
- self.token = token
- self.title = title
-
-
-class PrincipalTerms(object):
- implements(ITerms)
- adapts(IPrincipalSource, IBrowserRequest)
-
- 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 Term(principal_id.encode('base64').strip().replace('=', '_'),
- principal.title)
-
- def getValue(self, token):
- return token.replace('_', '=').decode('base64')
+# BBB
+from zope.authentication.principal import PrincipalTerm as Term
+from zope.authentication.principal import PrincipalTerms
Deleted: zope.app.security/trunk/src/zope/app/security/browser/principalterms.txt
===================================================================
--- zope.app.security/trunk/src/zope/app/security/browser/principalterms.txt 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/browser/principalterms.txt 2009-03-12 00:38:29 UTC (rev 97943)
@@ -1,68 +0,0 @@
-===============
-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.app.security.interfaces import IAuthentication
- >>> from zope.app.security.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.app.testing import ztapi
- >>> ztapi.provideUtility(IAuthentication, AuthUtility())
-
-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.app.security.browser.principalterms 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.app.security/trunk/src/zope/app/security/browser/tests.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/browser/tests.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/browser/tests.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -20,14 +20,24 @@
from zope.testing import doctest
from zope.app.testing import placelesssetup
+def test_bbb_imports():
+ """
+ >>> import zope.app.security.browser.principalterms as old
+ >>> import zope.authentication.principal as new
+
+ >>> old.PrincipalTerms is new.PrincipalTerms
+ True
+ >>> old.Term is new.PrincipalTerm
+ True
+
+ """
+
def test_suite():
return unittest.TestSuite((
+ doctest.DocTestSuite(),
doctest.DocFileSuite('authutilitysearchview.txt',
setUp=placelesssetup.setUp,
tearDown=placelesssetup.tearDown),
- doctest.DocFileSuite('principalterms.txt',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown),
doctest.DocFileSuite('loginlogout.txt',
setUp=placelesssetup.setUp,
tearDown=placelesssetup.tearDown),
Modified: zope.app.security/trunk/src/zope/app/security/configure.zcml
===================================================================
--- zope.app.security/trunk/src/zope/app/security/configure.zcml 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/configure.zcml 2009-03-12 00:38:29 UTC (rev 97943)
@@ -5,6 +5,7 @@
<include package="zope.security" />
<include package="zope.localpermission" />
+ <include package="zope.authentication" />
<include file="globalmodules.zcml" />
<include file="_protections.zcml" />
@@ -14,21 +15,12 @@
component=".principalregistry.principalRegistry"
/>
-
- <class class="zope.security.permission.Permission">
- <allow
- interface="zope.security.interfaces.IPermission"
- />
- </class>
-
<class class=".principalregistry.Principal">
<allow
interface=".interfaces.IPrincipal"
/>
</class>
- <adapter factory=".NoLogout" />
-
<!-- Standard Permissions -->
<permission
@@ -79,18 +71,6 @@
packing the ZODB."
/>
- <adapter
- factory=".basicauthadapter.BasicAuthAdapter"
- provides=".interfaces.ILoginPassword"
- for="zope.publisher.interfaces.http.IHTTPCredentials"
- />
-
- <adapter
- factory=".ftpauth.FTPAuth"
- provides=".interfaces.ILoginPassword"
- for="zope.publisher.interfaces.ftp.IFTPCredentials"
- />
-
<utility
component=".principalregistry.fallback_unauthenticated_principal"
provides=".interfaces.IFallbackUnauthenticatedPrincipal"
Modified: zope.app.security/trunk/src/zope/app/security/ftpauth.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/ftpauth.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/ftpauth.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,27 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""FTP Standard Authentication adapter
+"""Backward compatibility for the IFTPCredentials -> ILoginPassword adapter
$Id$
"""
-from zope.component import adapts
-from zope.publisher.interfaces.ftp import IFTPCredentials
-from zope.app.security.loginpassword import LoginPassword
-class FTPAuth(LoginPassword):
- """Adapter for handling common FTP authentication."""
-
- adapts(IFTPCredentials)
-
- def __init__(self, request):
- self.__request = request
- lpw = request._authUserPW()
- if lpw is None:
- login, password = None, None
- else:
- login, password = lpw
- super(FTPAuth, self).__init__(login, password)
-
- def needLogin(self, realm):
- self.__request.unauthorized("Did not work")
+# BBB, XXX: this may change in near future
+from zope.authentication.ftpauth import FTPAuth
Modified: zope.app.security/trunk/src/zope/app/security/interfaces.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/interfaces.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/interfaces.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,171 +11,23 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Zope Application-specific Security Interfaces
+"""Backward-compatibility imports for authentication interfaces
$Id$
"""
-from zope.interface import Interface
-from zope.security.interfaces import IPrincipal, IPermission, IGroup
-from zope.schema.interfaces import ISource
-class PrincipalLookupError(LookupError):
- """A prncipal could not be found for a principal id
- """
-
-class IUnauthenticatedPrincipal(IPrincipal):
- """A principal that hasn't been authenticated.
-
- Authenticated principals are preferable to UnauthenticatedPrincipals.
- """
-
-
-class IFallbackUnauthenticatedPrincipal(IUnauthenticatedPrincipal):
- """Marker interface for the fallback unauthenticated principal.
-
- 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
- """
-
-class IAuthenticatedGroup(IGroup):
- """A group containing authenticated users
- """
-
-class IEveryoneGroup(IGroup):
- """A group containing all users
- """
-
-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.
-
- `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
- most specific utility in a place and rely on the utility to delegate to
- other utilities as necessary.
-
- The interface doesn't include methods for data management. Utilities may
- use external data and not allow management in Zope. Simularly, the data to
- be managed may vary with different implementations of a utility.
- """
-
- def authenticate(request):
- """Identify a principal for a request.
-
- If a principal can be identified, then return the
- principal. Otherwise, return None.
-
- The request object is fairly opaque. We may decide
- that it implements some generic request interface.
-
- Implementation note
-
- It is likely that the component will dispatch
- to another component based on the actual
- request interface. This will allow different
- kinds of requests to be handled correctly.
-
- For example, a component that authenticates
- based on user names and passwords might request
- an adapter for the request as in::
-
- getpw=getAdapter(request,
- ILoginPassword, place=self)
-
- The place keyword argument is used to control
- where the ILoginPassword component is
- searched for. This is necessary because
- requests are placeless.
- """
-
- def unauthenticatedPrincipal():
- """Return the unauthenticated principal, if one is defined.
-
- Return None if no unauthenticated principal is defined.
-
- The unauthenticated principal must be an IUnauthenticatedPrincipal.
- """
-
- def unauthorized(id, request):
- """Signal an authorization failure.
-
- This method is called when an auhorization problem
- occurs. It can perform a variety of actions, such
- as issuing an HTTP authentication challenge or
- displaying a login interface.
-
- Note that the authentication utility nearest to the
- requested resource is called. It is up to
- authentication utility implementations to
- collaborate with utilities higher in the object
- hierarchy.
-
- If no principal has been identified, id will be
- None.
- """
-
- def getPrincipal(id):
- """Get principal meta-data.
-
- Returns an object of type IPrincipal for the given principal
- id. A PrincipalLookupError is raised if the principal cannot be
- found.
-
- Note that the authentication utility nearest to the requested
- resource is called. It is up to authentication utility
- implementations to collaborate with utilities higher in the
- object hierarchy.
- """
-
-
-class ILoginPassword(Interface):
- """A password based login.
-
- 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.
- """
-
- def getLogin():
- """Return login name, or None if no login name found."""
-
- def getPassword():
- """Return password, or None if no login name found.
-
- If there's a login but no password, return empty string.
- """
-
- def needLogin(realm):
- """Indicate that a login is needed.
-
- The realm argument is the name of the principal registry.
- """
-
-class IPrincipalSource(ISource):
- """A Source of Principal Ids"""
-
-
-class ILogout(Interface):
- """Provides support for logging out."""
-
- def logout(request):
- """Perform a logout."""
-
-
-class ILogoutSupported(Interface):
- """A marker indicating that the security configuration supports logout.
-
- Provide an adapter to this interface to signal that the security system
- supports logout.
- """
+# BBB
+from zope.security.interfaces import IPrincipal, IPermission, IGroup
+from zope.authentication.interfaces import (
+ PrincipalLookupError,
+ IUnauthenticatedPrincipal,
+ IFallbackUnauthenticatedPrincipal,
+ IUnauthenticatedGroup,
+ IAuthenticatedGroup,
+ IEveryoneGroup,
+ IAuthentication,
+ ILoginPassword,
+ IPrincipalSource,
+ ILogout,
+ ILogoutSupported,
+ )
Modified: zope.app.security/trunk/src/zope/app/security/loginpassword.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/loginpassword.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/loginpassword.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,29 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Login/Password provider
+"""Backward-compatibility import for base ILoginPassword implementation.
$Id$
"""
-from zope.interface import implements
-from zope.app.security.interfaces import ILoginPassword
-class LoginPassword(object):
-
- implements(ILoginPassword)
-
- def __init__(self, login, password):
- self.__login = login
- if login is None:
- self.__password = None
- else:
- self.__password = password or ""
-
- def getLogin(self):
- return self.__login
-
- def getPassword(self):
- return self.__password
-
- def needLogin(self, realm):
- pass
+# BBB
+from zope.authentication.loginpassword import LoginPassword
Deleted: zope.app.security/trunk/src/zope/app/security/logout.txt
===================================================================
--- zope.app.security/trunk/src/zope/app/security/logout.txt 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/logout.txt 2009-03-12 00:38:29 UTC (rev 97943)
@@ -1,76 +0,0 @@
-==============
-Logout Support
-==============
-
-Logout support is defined by a simple interface ILogout:
-
- >>> from zope.app.security.interfaces import ILogout
-
-that has a single 'logout' method.
-
-The current use of ILogout is to adapt an IAuthentication component to ILogout
-To illustrate, we'll create a simple logout implementation that adapts
-IAuthentication:
-
- >>> class SimpleLogout(object):
- ...
- ... adapts(IAuthentication)
- ... implements(ILogout)
- ...
- ... def __init__(self, auth):
- ... pass
- ...
- ... def logout(self, request):
- ... print 'User has logged out'
-
- >>> provideAdapter(SimpleLogout)
-
-and something to represent an authentication utility:
-
- >>> class Authentication(object):
- ...
- ... implements(IAuthentication)
-
- >>> auth = Authentication()
-
-To perform a logout, we adapt auth to ILogout and call 'logout':
-
- >>> logout = ILogout(auth)
- >>> logout.logout(TestRequest())
- User has logged out
-
-
-The 'NoLogout' Adapter
-----------------------
-
-The class:
-
- >>> from zope.app.security import NoLogout
-
-can be registered as a fallback provider of ILogout for IAuthentication
-components that are not otherwise adaptable to ILogout. NoLogout's logout
-method is a no-op:
-
- >>> NoLogout(auth).logout(TestRequest())
-
-
-Logout User Interface
----------------------
-
-Because some authentication protocols do not formally support logout, it may
-not be possible for a user to logout once he or she has logged in. In such
-cases, it would be inappropriate to present a user interface for logging out.
-
-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
-
-This class merely serves as a flag as it implements ILogoutSupported:
-
- >>> from zope.app.security.interfaces import ILogoutSupported
- >>> ILogoutSupported.implementedBy(LogoutSupported)
- True
-
-For more information on login/logout UI, see
-zope/app/security/browser/loginlogout.txt.
Modified: zope.app.security/trunk/src/zope/app/security/principal.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/principal.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/principal.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Principals.
+"""Backward-compatibility import for the checkPrincipal function
$Id$
"""
-from zope.component import getUtility
-from zope.app.security.interfaces import PrincipalLookupError
-from zope.app.security.interfaces import IAuthentication
-def checkPrincipal(context, principal_id):
- auth = getUtility(IAuthentication, context=context)
- try:
- if auth.getPrincipal(principal_id):
- return
- except PrincipalLookupError:
- pass
-
- raise ValueError("Undefined principal id", principal_id)
+# BBB
+from zope.authentication.principal import checkPrincipal
Modified: zope.app.security/trunk/src/zope/app/security/tests/test_basicauthadapter.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_basicauthadapter.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_basicauthadapter.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -16,43 +16,21 @@
$Id$
"""
import unittest
+from zope.testing import doctest
-from zope.app.security.basicauthadapter import BasicAuthAdapter
+def test_bbb_imports():
+ """XXX: the place may change
+ Let's check if original imports still work:
+
+ >>> import zope.app.security.basicauthadapter as old
+ >>> import zope.authentication.basicauthadapter as new
+
+ >>> old.BasicAuthAdapter is new.BasicAuthAdapter
+ True
+
+ """
-class Request(object):
-
- def __init__(self, lpw):
- self.lpw = lpw
-
- def _authUserPW(self):
- return self.lpw
-
- challenge = None
- def unauthorized(self, challenge):
- self.challenge = challenge
-
-
-class Test(unittest.TestCase):
-
- def testBasicAuthAdapter(self):
- r = Request(None)
- a = BasicAuthAdapter(r)
- self.assertEqual(a.getLogin(), None)
- self.assertEqual(a.getPassword(), None)
- r = Request(("tim", "123"))
- a = BasicAuthAdapter(r)
- self.assertEqual(a.getLogin(), "tim")
- self.assertEqual(a.getPassword(), "123")
-
- def testUnauthorized(self):
- r = Request(None)
- a = BasicAuthAdapter(r)
- a.needLogin("tim")
- self.assertEqual(r.challenge, 'basic realm="tim"')
-
def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
Modified: zope.app.security/trunk/src/zope/app/security/tests/test_ftpauth.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_ftpauth.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_ftpauth.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -15,43 +15,22 @@
$Id$
"""
-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
+import unittest
+from zope.testing import doctest
-class FTPCredentials(object):
- __doc__ = IFTPCredentials.__doc__
+def test_bbb_imports():
+ """XXX: the place may change
+ Let's check if original imports still work:
+
+ >>> import zope.app.security.ftpauth as old
+ >>> import zope.authentication.ftpauth as new
+
+ >>> old.FTPAuth is new.FTPAuth
+ True
+
+ """
- implements(IFTPCredentials)
-
- def __init__(self, credentials):
- self.credentials = credentials
-
- def _authUserPW(self):
- return self.credentials
-
- unauth = 0
- def unauthorized(self, challenge):
- self.unauth += 1
-
-
-class Test(TestCase):
-
- def test(self):
- request = FTPCredentials(('bob', '123'))
- auth = FTPAuth(request)
- self.assertEqual(auth.getLogin(), 'bob')
- self.assertEqual(auth.getPassword(), '123')
-
- unauth = request.unauth
- auth.needLogin('xxx')
- self.assertEqual(request.unauth, unauth+1)
-
def test_suite():
- return TestSuite((
- makeSuite(Test),
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
))
-
-if __name__=='__main__':
- main(defaultTest='test_suite')
Added: zope.app.security/trunk/src/zope/app/security/tests/test_interfaces.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_interfaces.py (rev 0)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_interfaces.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# 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 importability of BBB interfaces
+
+$Id$
+"""
+import unittest
+from zope.testing import doctest
+
+def test_bbb_imports():
+ """
+ Let's check that permission vocabularies that were moved to
+ zope.security are still importable from original place.
+
+ >>> import zope.app.security.interfaces as old
+ >>> import zope.authentication.interfaces as new
+
+ >>> old.PrincipalLookupError is new.PrincipalLookupError
+ True
+ >>> old.IUnauthenticatedPrincipal is new.IUnauthenticatedPrincipal
+ True
+ >>> old.IFallbackUnauthenticatedPrincipal is new.IFallbackUnauthenticatedPrincipal
+ True
+ >>> old.IUnauthenticatedGroup is new.IUnauthenticatedGroup
+ True
+ >>> old.IAuthenticatedGroup is new.IAuthenticatedGroup
+ True
+ >>> old.IEveryoneGroup is new.IEveryoneGroup
+ True
+ >>> old.IAuthentication is new.IAuthentication
+ True
+ >>> old.ILoginPassword is new.ILoginPassword
+ True
+ >>> old.IPrincipalSource is new.IPrincipalSource
+ True
+ >>> old.ILogout is new.ILogout
+ True
+ >>> old.ILogoutSupported is new.ILogoutSupported
+ True
+
+ >>> import zope.security.interfaces as new
+
+ >>> old.IPrincipal is new.IPrincipal
+ True
+ >>> old.IPermission is new.IPermission
+ True
+ >>> old.IGroup is new.IGroup
+ True
+
+ """
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
Property changes on: zope.app.security/trunk/src/zope/app/security/tests/test_interfaces.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: zope.app.security/trunk/src/zope/app/security/tests/test_loginpassword.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_loginpassword.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_loginpassword.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -16,29 +16,21 @@
$Id$
"""
import unittest
+from zope.testing import doctest
-from zope.app.security.loginpassword import LoginPassword
+def test_bbb_imports():
+ """
+ Let's check that permission vocabularies that were moved to
+ zope.security are still importable from original place.
+
+ >>> import zope.authentication.loginpassword as new
+ >>> import zope.app.security.loginpassword as old
+ >>> old.LoginPassword is new.LoginPassword
+ True
+
+ """
-class Test(unittest.TestCase):
-
- def testLoginPassword(self):
- lp = LoginPassword("tim", "123")
- self.assertEqual(lp.getLogin(), "tim")
- self.assertEqual(lp.getPassword(), "123")
- lp = LoginPassword(None, None)
- self.assertEqual(lp.getLogin(), None)
- self.assertEqual(lp.getPassword(), None)
- lp = LoginPassword(None, "123")
- self.assertEqual(lp.getLogin(), None)
- self.assertEqual(lp.getPassword(), None)
- lp = LoginPassword("tim", None)
- self.assertEqual(lp.getLogin(), "tim")
- self.assertEqual(lp.getPassword(), "")
- lp.needLogin("tim") # This method should exist
-
def test_suite():
- loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
-
-if __name__=='__main__':
- unittest.TextTestRunner().run(test_suite())
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
Modified: zope.app.security/trunk/src/zope/app/security/tests/test_logout.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_logout.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_logout.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -15,31 +15,24 @@
$Id$
"""
import unittest
-
from zope.testing import doctest
-from zope.interface import implements
-from zope.component import provideAdapter, adapts
-from zope.publisher.tests.httprequest import TestRequest
-from zope.app.testing import placelesssetup
-from zope.app.security import interfaces
+def test_bbb_imports():
+ """
+ Let's check if original imports still work:
+
+ >>> import zope.app.security as old
+ >>> import zope.authentication.logout as new
+
+ >>> old.NoLogout is new.NoLogout
+ True
+ >>> old.LogoutSupported is new.LogoutSupported
+ True
+
+ """
def test_suite():
return unittest.TestSuite((
- doctest.DocFileSuite(
- '../logout.txt',
- globs={'provideAdapter': provideAdapter,
- 'TestRequest': TestRequest,
- 'implements': implements,
- 'adapts': adapts,
- 'IAuthentication': interfaces.IAuthentication
- },
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown,
- ),
+ doctest.DocTestSuite(),
))
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Added: zope.app.security/trunk/src/zope/app/security/tests/test_principal.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_principal.py (rev 0)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_principal.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# 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 bbb imports for checkPrincipal
+
+$Id$
+"""
+import unittest
+from zope.testing import doctest
+
+def test_bbb_imports():
+ """
+ >>> import zope.authentication.principal as new
+ >>> import zope.app.security.principal as old
+ >>> old.checkPrincipal is new.checkPrincipal
+ True
+
+ """
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
Property changes on: zope.app.security/trunk/src/zope/app/security/tests/test_principal.py
___________________________________________________________________
Added: svn:keywords
+ Id
Modified: zope.app.security/trunk/src/zope/app/security/tests/test_vocabulary.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/tests/test_vocabulary.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/tests/test_vocabulary.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -16,7 +16,7 @@
$Id$
"""
import unittest
-from zope.testing.doctestunit import DocTestSuite
+from zope.testing import doctest
def test_bbb_imports():
"""
@@ -29,14 +29,14 @@
True
>>> old.PermissionIdsVocabulary is new.PermissionIdsVocabulary
True
+
+ >>> import zope.authentication.principal as new
+ >>> old.PrincipalSource is new.PrincipalSource
+ True
"""
def test_suite():
return unittest.TestSuite((
- DocTestSuite(),
- DocTestSuite('zope.app.security.vocabulary'),
+ doctest.DocTestSuite(),
))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Modified: zope.app.security/trunk/src/zope/app/security/vocabulary.py
===================================================================
--- zope.app.security/trunk/src/zope/app/security/vocabulary.py 2009-03-12 00:12:57 UTC (rev 97942)
+++ zope.app.security/trunk/src/zope/app/security/vocabulary.py 2009-03-12 00:38:29 UTC (rev 97943)
@@ -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,132 +11,12 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Permission Id Vocabulary.
+"""Backward-compatibility imports for PrincipalSource and permission vocabularies.
-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
-
-# BBB: these vocabularies are moved to zope.security.
+# BBB
from zope.security.permission import PermissionsVocabulary
from zope.security.permission import PermissionIdsVocabulary
-
-
-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
+from zope.authentication.principal import PrincipalSource
More information about the Checkins
mailing list