zope.authentication-3.7.1/bootstrap.py0000644000000000000000000000742211366620452020054 0ustar rootroot00000000000000############################################################################## # # Copyright (c) 2006 Zope Foundation 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. # ############################################################################## """Bootstrap a buildout-based project Simply run this script in a directory containing a buildout.cfg. The script accepts buildout command-line options, so you can use the -c option to specify an alternate configuration file. $Id: bootstrap.py 111660 2010-04-30 17:27:53Z hannosch $ """ import os, shutil, sys, tempfile, urllib2 from optparse import OptionParser tmpeggs = tempfile.mkdtemp() is_jython = sys.platform.startswith('java') # parsing arguments parser = OptionParser() parser.add_option("-v", "--version", dest="version", help="use a specific zc.buildout version") parser.add_option("-d", "--distribute", action="store_true", dest="distribute", default=False, help="Use Disribute rather than Setuptools.") parser.add_option("-c", None, action="store", dest="config_file", help=("Specify the path to the buildout configuration " "file to be used.")) options, args = parser.parse_args() # if -c was provided, we push it back into args for buildout' main function if options.config_file is not None: args += ['-c', options.config_file] if options.version is not None: VERSION = '==%s' % options.version else: VERSION = '' USE_DISTRIBUTE = options.distribute args = args + ['bootstrap'] to_reload = False try: import pkg_resources if not hasattr(pkg_resources, '_distribute'): to_reload = True raise ImportError except ImportError: ez = {} if USE_DISTRIBUTE: exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py' ).read() in ez ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True) else: exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' ).read() in ez ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) if to_reload: reload(pkg_resources) else: import pkg_resources if sys.platform == 'win32': def quote(c): if ' ' in c: return '"%s"' % c # work around spawn lamosity on windows else: return c else: def quote (c): return c cmd = 'from setuptools.command.easy_install import main; main()' ws = pkg_resources.working_set if USE_DISTRIBUTE: requirement = 'distribute' else: requirement = 'setuptools' if is_jython: import subprocess assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd', quote(tmpeggs), 'zc.buildout' + VERSION], env=dict(os.environ, PYTHONPATH= ws.find(pkg_resources.Requirement.parse(requirement)).location ), ).wait() == 0 else: assert os.spawnle( os.P_WAIT, sys.executable, quote (sys.executable), '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION, dict(os.environ, PYTHONPATH= ws.find(pkg_resources.Requirement.parse(requirement)).location ), ) == 0 ws.add_entry(tmpeggs) ws.require('zc.buildout' + VERSION) import zc.buildout.buildout zc.buildout.buildout.main(args) shutil.rmtree(tmpeggs) zope.authentication-3.7.1/buildout.cfg0000644000000000000000000000060611156427206017771 0ustar rootroot00000000000000[buildout] develop = . parts = test coverage-test coverage-report [test] recipe = zc.recipe.testrunner eggs = zope.authentication [coverage-test] recipe = zc.recipe.testrunner eggs = zope.authentication defaults = ['--coverage', '../../coverage'] [coverage-report] recipe = zc.recipe.egg eggs = z3c.coverage scripts = coverage=coverage-report arguments = ('coverage', 'coverage/report') zope.authentication-3.7.1/CHANGES.txt0000644000000000000000000000052311366620464017274 0ustar rootroot00000000000000======= CHANGES ======= 3.7.1 (2010-04-30) ------------------ - Removed undeclared testing dependency on zope.testing. 3.7.0 (2009-03-14) ------------------ Initial release. This package was split off from ``zope.app.security`` to provide a separate common interface definition for authentication utilities without extra dependencies. zope.authentication-3.7.1/PKG-INFO0000644000000000000000000001521411366620546016564 0ustar rootroot00000000000000Metadata-Version: 1.0 Name: zope.authentication Version: 3.7.1 Summary: Definition of authentication basics for the Zope Framework Home-page: http://pypi.python.org/pypi/zope.authentication Author: Zope Corporation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: This package provides a definition of authentication concepts for use in Zope Framework. Detailed Documentation ====================== ============== Logout Support ============== Logout support is defined by a simple interface ILogout: >>> from zope.authentication.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.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 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.authentication.logout import LogoutSupported This class merely serves as a flag as it implements ILogoutSupported: >>> from zope.authentication.interfaces import ILogoutSupported >>> ILogoutSupported.implementedBy(LogoutSupported) True >>> request = object() >>> ILogoutSupported.providedBy(LogoutSupported(request)) True =============== 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' ======= CHANGES ======= 3.7.1 (2010-04-30) ------------------ - Removed undeclared testing dependency on zope.testing. 3.7.0 (2009-03-14) ------------------ Initial release. This package was split off from ``zope.app.security`` to provide a separate common interface definition for authentication utilities without extra dependencies. Keywords: zope security authentication Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3 zope.authentication-3.7.1/README.txt0000644000000000000000000000013111156035040017137 0ustar rootroot00000000000000This package provides a definition of authentication concepts for use in Zope Framework. zope.authentication-3.7.1/setup.cfg0000644000000000000000000000007311366620546017305 0ustar rootroot00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 zope.authentication-3.7.1/setup.py0000644000000000000000000000501511366620510017166 0ustar rootroot00000000000000############################################################################## # # Copyright (c) 2006-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. # ############################################################################## """Setup for zope.authentication package $Id: setup.py 111661 2010-04-30 17:28:23Z hannosch $ """ import os from setuptools import setup, find_packages def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() setup(name='zope.authentication', version = '3.7.1', author='Zope Corporation and Contributors', author_email='zope-dev@zope.org', description='Definition of authentication basics for the Zope Framework', long_description=( read('README.txt') + '\n\n' + 'Detailed Documentation\n' + '======================\n' + '\n\n' + read('src', 'zope', 'authentication', 'logout.txt') + '\n\n' + read('src', 'zope', 'authentication', 'principalterms.txt') + '\n\n' + read('CHANGES.txt') ), keywords = "zope security authentication", classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', 'Programming Language :: Python', 'Natural Language :: English', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', 'Framework :: Zope3'], url='http://pypi.python.org/pypi/zope.authentication', license='ZPL 2.1', packages=find_packages('src'), package_dir = {'': 'src'}, namespace_packages=['zope'], install_requires=['setuptools', 'zope.browser', 'zope.component>=3.6.0', 'zope.i18nmessageid', 'zope.interface', 'zope.schema', 'zope.security', ], include_package_data = True, zip_safe = False, ) zope.authentication-3.7.1/src/zope/__init__.py0000644000000000000000000000031111155770354021333 0ustar rootroot00000000000000# this is a namespace package try: import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) zope.authentication-3.7.1/src/zope/authentication/__init__.py0000644000000000000000000000002011156044724024343 0ustar rootroot00000000000000# i am a packagezope.authentication-3.7.1/src/zope/authentication/configure.zcml0000644000000000000000000000023611156427206025113 0ustar rootroot00000000000000 zope.authentication-3.7.1/src/zope/authentication/interfaces.py0000644000000000000000000001346211156044724024745 0ustar rootroot00000000000000############################################################################## # # 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. # ############################################################################## """Authentication interfaces $Id: interfaces.py 97931 2009-03-11 22:31:33Z nadako $ """ from zope.interface import Interface from zope.security.interfaces import IPrincipal, IGroup from zope.schema.interfaces import ISource class PrincipalLookupError(LookupError): """No principal for given 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, context=self) The `context` 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 provide 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` utility may 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. """ zope.authentication-3.7.1/src/zope/authentication/loginpassword.py0000644000000000000000000000253511156044724025514 0ustar rootroot00000000000000############################################################################## # # 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. # ############################################################################## """Login/Password provider. $Id: loginpassword.py 97931 2009-03-11 22:31:33Z nadako $ """ from zope.interface import implements 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) 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 zope.authentication-3.7.1/src/zope/authentication/logout.py0000644000000000000000000000256211156044724024132 0ustar rootroot00000000000000############################################################################## # # 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: logout.py 97931 2009-03-11 22:31:33Z nadako $ """ 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 zope.authentication-3.7.1/src/zope/authentication/logout.txt0000644000000000000000000000403011156046354024312 0ustar rootroot00000000000000============== Logout Support ============== Logout support is defined by a simple interface ILogout: >>> from zope.authentication.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.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 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.authentication.logout import LogoutSupported This class merely serves as a flag as it implements ILogoutSupported: >>> from zope.authentication.interfaces import ILogoutSupported >>> ILogoutSupported.implementedBy(LogoutSupported) True >>> request = object() >>> ILogoutSupported.providedBy(LogoutSupported(request)) True zope.authentication-3.7.1/src/zope/authentication/principal.py0000644000000000000000000001503611156060300024566 0ustar rootroot00000000000000############################################################################## # # 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. # ############################################################################## """Principal source and helper function $Id: principal.py 97941 2009-03-12 00:09:21Z nadako $ """ from zope.browser.interfaces import ITerms from zope.component import getUtility, queryNextUtility, adapts from zope.interface import implements, Interface from zope.schema.interfaces import ISourceQueriables 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. Raises ValueError when principal doesn't exists for given context and principal id. To test it, let's create and register a dummy authentication utility. >>> class DummyUtility: ... ... implements(IAuthentication) ... ... def getPrincipal(self, id): ... if id == 'bob': ... return id ... raise PrincipalLookupError(id) >>> from zope.component import provideUtility >>> provideUtility(DummyUtility()) Now, let's the behaviour of this function. >>> checkPrincipal(None, 'bob') >>> checkPrincipal(None, 'dan') Traceback (most recent call last): ... ValueError: ('Undefined principal id', 'dan') """ auth = getUtility(IAuthentication, context=context) try: if auth.getPrincipal(principal_id): return except PrincipalLookupError: pass 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) Let's register our dummy auth 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.component.nexttesting 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: # TODO: is this a possible case? 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 zope.authentication-3.7.1/src/zope/authentication/principalterms.txt0000644000000000000000000000407511156044724026045 0ustar rootroot00000000000000=============== 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' zope.authentication-3.7.1/src/zope/authentication/tests/__init__.py0000644000000000000000000000000011156044724025503 0ustar rootroot00000000000000zope.authentication-3.7.1/src/zope/authentication/tests/test_loginpassword.py0000644000000000000000000000316011156546262027714 0ustar rootroot00000000000000############################################################################## # # Copyright (c) 2001-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 Login and Password $Id: test_loginpassword.py 98048 2009-03-13 20:14:26Z nadako $ """ import unittest from zope.authentication.loginpassword import LoginPassword 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()) zope.authentication-3.7.1/src/zope/authentication/tests/test_logout.py0000644000000000000000000000237611366620452026337 0ustar rootroot00000000000000############################################################################## # # Copyright (c) 2004-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. # ############################################################################## """ $Id: test_logout.py 111660 2010-04-30 17:27:53Z hannosch $ """ import doctest import unittest from zope.component import provideAdapter, adapts from zope.interface import implements from zope.authentication.interfaces import IAuthentication def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite( '../logout.txt', globs={'provideAdapter': provideAdapter, 'TestRequest': object, 'implements': implements, 'adapts': adapts, 'IAuthentication': IAuthentication }, ), )) zope.authentication-3.7.1/src/zope/authentication/tests/test_principal.py0000644000000000000000000000170711366620452027004 0ustar rootroot00000000000000############################################################################## # # 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: test_principal.py 111660 2010-04-30 17:27:53Z hannosch $ """ import doctest import unittest def test_suite(): return unittest.TestSuite(( doctest.DocTestSuite('zope.authentication.principal'), doctest.DocFileSuite('../principalterms.txt'), )) zope.authentication-3.7.1/src/zope.authentication.egg-info/dependency_links.txt0000644000000000000000000000000111366620546030006 0ustar rootroot00000000000000 zope.authentication-3.7.1/src/zope.authentication.egg-info/namespace_packages.txt0000644000000000000000000000000511366620546030266 0ustar rootroot00000000000000zope zope.authentication-3.7.1/src/zope.authentication.egg-info/not-zip-safe0000644000000000000000000000000111366620176026165 0ustar rootroot00000000000000 zope.authentication-3.7.1/src/zope.authentication.egg-info/PKG-INFO0000644000000000000000000001521411366620546025040 0ustar rootroot00000000000000Metadata-Version: 1.0 Name: zope.authentication Version: 3.7.1 Summary: Definition of authentication basics for the Zope Framework Home-page: http://pypi.python.org/pypi/zope.authentication Author: Zope Corporation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: This package provides a definition of authentication concepts for use in Zope Framework. Detailed Documentation ====================== ============== Logout Support ============== Logout support is defined by a simple interface ILogout: >>> from zope.authentication.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.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 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.authentication.logout import LogoutSupported This class merely serves as a flag as it implements ILogoutSupported: >>> from zope.authentication.interfaces import ILogoutSupported >>> ILogoutSupported.implementedBy(LogoutSupported) True >>> request = object() >>> ILogoutSupported.providedBy(LogoutSupported(request)) True =============== 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' ======= CHANGES ======= 3.7.1 (2010-04-30) ------------------ - Removed undeclared testing dependency on zope.testing. 3.7.0 (2009-03-14) ------------------ Initial release. This package was split off from ``zope.app.security`` to provide a separate common interface definition for authentication utilities without extra dependencies. Keywords: zope security authentication Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3 zope.authentication-3.7.1/src/zope.authentication.egg-info/requires.txt0000644000000000000000000000015111366620546026335 0ustar rootroot00000000000000setuptools zope.browser zope.component>=3.6.0 zope.i18nmessageid zope.interface zope.schema zope.securityzope.authentication-3.7.1/src/zope.authentication.egg-info/SOURCES.txt0000644000000000000000000000161011366620546025622 0ustar rootroot00000000000000CHANGES.txt README.txt bootstrap.py buildout.cfg setup.py src/zope/__init__.py src/zope.authentication.egg-info/PKG-INFO src/zope.authentication.egg-info/SOURCES.txt src/zope.authentication.egg-info/dependency_links.txt src/zope.authentication.egg-info/namespace_packages.txt src/zope.authentication.egg-info/not-zip-safe src/zope.authentication.egg-info/requires.txt src/zope.authentication.egg-info/top_level.txt src/zope/authentication/__init__.py src/zope/authentication/configure.zcml src/zope/authentication/interfaces.py src/zope/authentication/loginpassword.py src/zope/authentication/logout.py src/zope/authentication/logout.txt src/zope/authentication/principal.py src/zope/authentication/principalterms.txt src/zope/authentication/tests/__init__.py src/zope/authentication/tests/test_loginpassword.py src/zope/authentication/tests/test_logout.py src/zope/authentication/tests/test_principal.pyzope.authentication-3.7.1/src/zope.authentication.egg-info/top_level.txt0000644000000000000000000000000511366620546026465 0ustar rootroot00000000000000zope