zope.principalregistry-3.7.1/000755 000766 000024 00000000000 11447366250 016164 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/CHANGES.txt000644 000766 000024 00000001535 11447366233 020002 0ustar00macstaff000000 000000 ======= CHANGES ======= 3.7.1 (2010-09-25) ------------------ - Added test extra to declare test dependency on ``zope.component [test]``. - Using Python's ``doctest`` module instead of depreacted ``zope.testing.doctest``. 3.7.0 (2009-03-14) ------------------ - Removed ``zope.container`` dependency, as contained principals didn't make any sense, since PrincipalRegistry never provided IContainer. Also, zope.container pulls a number dependencies, that are not needed for non-persistent principal registry (like, ZCML, for example). Set __name__ and __parent__ by hand to provide some backward-compatibility and to save a pointer to registry from principal objects. - Initial release. This package was splitted from zope.app.security as a part of the refactoring process to provide global principal registry without extra dependencies. zope.principalregistry-3.7.1/COPYRIGHT.txt000644 000766 000024 00000000040 11447366233 020270 0ustar00macstaff000000 000000 Zope Foundation and Contributorszope.principalregistry-3.7.1/LICENSE.txt000644 000766 000024 00000004026 11447366233 020012 0ustar00macstaff000000 000000 Zope Public License (ZPL) Version 2.1 A copyright notice accompanies this license document that identifies the copyright holders. This license has been certified as open source. It has also been designated as GPL compatible by the Free Software Foundation (FSF). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions in source code must retain the accompanying copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the accompanying copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Names of the copyright holders must not be used to endorse or promote products derived from this software without prior written permission from the copyright holders. 4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks (sm) or Trademarks (tm) of the copyright holders. Use of them is covered by separate agreement with the copyright holders. 5. If any files are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. Disclaimer THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. zope.principalregistry-3.7.1/PKG-INFO000644 000766 000024 00000027676 11447366250 017303 0ustar00macstaff000000 000000 Metadata-Version: 1.0 Name: zope.principalregistry Version: 3.7.1 Summary: Global principal registry component for Zope3 Home-page: http://pypi.python.org/pypi/zope.principalregistry Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: =========================== Global principal definition =========================== Global principals are defined via ZCML. There are several kinds of principals that can be defined. Authenticated Users ------------------- There are principals that can log in: >>> zcml(""" ... ... ... ... ... ... """) >>> import pprint >>> from zope.principalregistry.principalregistry import principalRegistry >>> [p] = principalRegistry.getPrincipals('') >>> p.id, p.title, p.description, p.getLogin(), p.validate('123') ('zope.manager', u'Manager', u'System Manager', u'admin', True) The unauthenticated principal ----------------------------- There is the unauthenticated principal: >>> zcml(""" ... ... ... ... ... ... """) >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated principal will also be registered as a utility. This is to provide easy access to the data defined for the principal so that other (more featureful) principal objects can be created for the same principal. >>> from zope import component >>> from zope.authentication import interfaces >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated group ------------------------- An unauthenticated group can also be defined in ZCML: >>> zcml(""" ... ... ... ... ... ... """) This directive creates a group and registers it as a utility providing IUnauthenticatedGroup: >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup', u'Anonymous users', u"People we don't know") The unauthenticatedGroup directive also updates the group of the unauthenticated principal: >>> p = principalRegistry.unauthenticatedPrincipal() >>> g.id in p.groups True >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> g.id in p.groups True If the unauthenticated principal is defined after the unauthenticated group, it will likewise have the group added to it: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... """) >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup2', u'Anonymous users', u"People we don't know") >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown2', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown2', True) The unauthenticated group shows up as a principal in the principal registry: >>> principalRegistry.getPrincipal(g.id) == g True >>> list(principalRegistry.getPrincipals("Anonymous")) == [g] True The authenticated group ----------------------- There is an authenticated group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) It defines an IAuthenticatedGroup utility: >>> g = component.getUtility(interfaces.IAuthenticatedGroup) >>> g.id, g.title, g.description ('zope.authenticated', u'Authenticated users', u'People we know') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.authenticated False zope.manager2 True zope.manager3 True Excluding unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown3', False) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown3', False) The everybody group ------------------- Finally, there is an everybody group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) The everybodyGroup directive defines an IEveryoneGroup utility: >>> g = component.getUtility(interfaces.IEveryoneGroup) >>> g.id, g.title, g.description ('zope.everybody', u'Everybody', u'All People') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.everybody False zope.manager4 True zope.manager5 True Including unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown4', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown4', True) Note that it is up to IAuthentication implementations to associate these groups with their principals, as appropriate. The system_user --------------- There is also a system_user that is defined in the code. It will be returned from the getPrincipal method of the registry. >>> import zope.security.management >>> import zope.principalregistry.principalregistry >>> auth = zope.principalregistry.principalregistry.PrincipalRegistry() >>> system_user = auth.getPrincipal(u'zope.security.management.system_user') >>> system_user is zope.security.management.system_user True ======= CHANGES ======= 3.7.1 (2010-09-25) ------------------ - Added test extra to declare test dependency on ``zope.component [test]``. - Using Python's ``doctest`` module instead of depreacted ``zope.testing.doctest``. 3.7.0 (2009-03-14) ------------------ - Removed ``zope.container`` dependency, as contained principals didn't make any sense, since PrincipalRegistry never provided IContainer. Also, zope.container pulls a number dependencies, that are not needed for non-persistent principal registry (like, ZCML, for example). Set __name__ and __parent__ by hand to provide some backward-compatibility and to save a pointer to registry from principal objects. - Initial release. This package was splitted from zope.app.security as a part of the refactoring process to provide global principal registry without extra dependencies. Keywords: zope security authentication principal registry 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.principalregistry-3.7.1/README.txt000644 000766 000024 00000000174 11447366233 017665 0ustar00macstaff000000 000000 This package provides an authentication utility for zope.authentication that uses simple non-persistent principal registry. zope.principalregistry-3.7.1/bootstrap.py000644 000766 000024 00000003302 11447366233 020552 0ustar00macstaff000000 000000 ############################################################################## # # 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. """ import os, shutil, sys, tempfile, urllib2 tmpeggs = tempfile.mkdtemp() ez = {} exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py' ).read() in ez ez['use_setuptools'](to_dir=tmpeggs, download_delay=0) import pkg_resources cmd = 'from setuptools.command.easy_install import main; main()' if sys.platform == 'win32': cmd = '"%s"' % cmd # work around spawn lamosity on windows ws = pkg_resources.working_set assert os.spawnle( os.P_WAIT, sys.executable, sys.executable, '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout', dict(os.environ, PYTHONPATH= ws.find(pkg_resources.Requirement.parse('setuptools')).location ), ) == 0 ws.add_entry(tmpeggs) ws.require('zc.buildout') import zc.buildout.buildout zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap']) shutil.rmtree(tmpeggs) zope.principalregistry-3.7.1/buildout.cfg000644 000766 000024 00000000623 11447366233 020476 0ustar00macstaff000000 000000 [buildout] parts = test coverage-test coverage-report develop = . [test] recipe = zc.recipe.testrunner eggs = zope.principalregistry [test] [coverage-test] recipe = zc.recipe.testrunner eggs = zope.principalregistry defaults = ['--coverage', '../../coverage'] [coverage-report] recipe = zc.recipe.egg eggs = z3c.coverage scripts = coverage=coverage-report arguments = ('coverage', 'coverage/report') zope.principalregistry-3.7.1/setup.cfg000644 000766 000024 00000000073 11447366250 020005 0ustar00macstaff000000 000000 [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 zope.principalregistry-3.7.1/setup.py000644 000766 000024 00000004462 11447366233 017705 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Setup for zope.principalregistry package """ 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.principalregistry', version = '3.7.1', author='Zope Foundation and Contributors', author_email='zope-dev@zope.org', description='Global principal registry component for Zope3', long_description=( read('src', 'zope', 'principalregistry', 'README.txt') + '\n\n' + read('CHANGES.txt') ), keywords = "zope security authentication principal registry", 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.principalregistry', license='ZPL 2.1', packages=find_packages('src'), package_dir = {'': 'src'}, namespace_packages=['zope'], install_requires=['setuptools', 'zope.authentication', 'zope.component', 'zope.interface', 'zope.password', 'zope.security', ], extras_require=dict( test=[ 'zope.component [test]', ]), include_package_data = True, zip_safe = False, ) zope.principalregistry-3.7.1/src/000755 000766 000024 00000000000 11447366250 016753 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/000755 000766 000024 00000000000 11447366250 017730 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/000755 000766 000024 00000000000 11447366250 025173 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/PKG-INFO000644 000766 000024 00000027676 11447366247 026320 0ustar00macstaff000000 000000 Metadata-Version: 1.0 Name: zope.principalregistry Version: 3.7.1 Summary: Global principal registry component for Zope3 Home-page: http://pypi.python.org/pypi/zope.principalregistry Author: Zope Foundation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: =========================== Global principal definition =========================== Global principals are defined via ZCML. There are several kinds of principals that can be defined. Authenticated Users ------------------- There are principals that can log in: >>> zcml(""" ... ... ... ... ... ... """) >>> import pprint >>> from zope.principalregistry.principalregistry import principalRegistry >>> [p] = principalRegistry.getPrincipals('') >>> p.id, p.title, p.description, p.getLogin(), p.validate('123') ('zope.manager', u'Manager', u'System Manager', u'admin', True) The unauthenticated principal ----------------------------- There is the unauthenticated principal: >>> zcml(""" ... ... ... ... ... ... """) >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated principal will also be registered as a utility. This is to provide easy access to the data defined for the principal so that other (more featureful) principal objects can be created for the same principal. >>> from zope import component >>> from zope.authentication import interfaces >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated group ------------------------- An unauthenticated group can also be defined in ZCML: >>> zcml(""" ... ... ... ... ... ... """) This directive creates a group and registers it as a utility providing IUnauthenticatedGroup: >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup', u'Anonymous users', u"People we don't know") The unauthenticatedGroup directive also updates the group of the unauthenticated principal: >>> p = principalRegistry.unauthenticatedPrincipal() >>> g.id in p.groups True >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> g.id in p.groups True If the unauthenticated principal is defined after the unauthenticated group, it will likewise have the group added to it: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... """) >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup2', u'Anonymous users', u"People we don't know") >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown2', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown2', True) The unauthenticated group shows up as a principal in the principal registry: >>> principalRegistry.getPrincipal(g.id) == g True >>> list(principalRegistry.getPrincipals("Anonymous")) == [g] True The authenticated group ----------------------- There is an authenticated group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) It defines an IAuthenticatedGroup utility: >>> g = component.getUtility(interfaces.IAuthenticatedGroup) >>> g.id, g.title, g.description ('zope.authenticated', u'Authenticated users', u'People we know') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.authenticated False zope.manager2 True zope.manager3 True Excluding unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown3', False) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown3', False) The everybody group ------------------- Finally, there is an everybody group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) The everybodyGroup directive defines an IEveryoneGroup utility: >>> g = component.getUtility(interfaces.IEveryoneGroup) >>> g.id, g.title, g.description ('zope.everybody', u'Everybody', u'All People') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.everybody False zope.manager4 True zope.manager5 True Including unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown4', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown4', True) Note that it is up to IAuthentication implementations to associate these groups with their principals, as appropriate. The system_user --------------- There is also a system_user that is defined in the code. It will be returned from the getPrincipal method of the registry. >>> import zope.security.management >>> import zope.principalregistry.principalregistry >>> auth = zope.principalregistry.principalregistry.PrincipalRegistry() >>> system_user = auth.getPrincipal(u'zope.security.management.system_user') >>> system_user is zope.security.management.system_user True ======= CHANGES ======= 3.7.1 (2010-09-25) ------------------ - Added test extra to declare test dependency on ``zope.component [test]``. - Using Python's ``doctest`` module instead of depreacted ``zope.testing.doctest``. 3.7.0 (2009-03-14) ------------------ - Removed ``zope.container`` dependency, as contained principals didn't make any sense, since PrincipalRegistry never provided IContainer. Also, zope.container pulls a number dependencies, that are not needed for non-persistent principal registry (like, ZCML, for example). Set __name__ and __parent__ by hand to provide some backward-compatibility and to save a pointer to registry from principal objects. - Initial release. This package was splitted from zope.app.security as a part of the refactoring process to provide global principal registry without extra dependencies. Keywords: zope security authentication principal registry 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.principalregistry-3.7.1/src/zope.principalregistry.egg-info/SOURCES.txt000644 000766 000024 00000001667 11447366247 027077 0ustar00macstaff000000 000000 CHANGES.txt COPYRIGHT.txt LICENSE.txt README.txt bootstrap.py buildout.cfg setup.py src/zope/__init__.py src/zope.principalregistry.egg-info/PKG-INFO src/zope.principalregistry.egg-info/SOURCES.txt src/zope.principalregistry.egg-info/dependency_links.txt src/zope.principalregistry.egg-info/namespace_packages.txt src/zope.principalregistry.egg-info/not-zip-safe src/zope.principalregistry.egg-info/requires.txt src/zope.principalregistry.egg-info/top_level.txt src/zope/principalregistry/README.txt src/zope/principalregistry/__init__.py src/zope/principalregistry/configure.zcml src/zope/principalregistry/meta.zcml src/zope/principalregistry/metaconfigure.py src/zope/principalregistry/metadirectives.py src/zope/principalregistry/principalregistry.py src/zope/principalregistry/tests/__init__.py src/zope/principalregistry/tests/principal.zcml src/zope/principalregistry/tests/test_doc.py src/zope/principalregistry/tests/test_principalregistry.pyzope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/dependency_links.txt000644 000766 000024 00000000001 11447366247 031247 0ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/namespace_packages.txt000644 000766 000024 00000000005 11447366247 031527 0ustar00macstaff000000 000000 zope zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/not-zip-safe000644 000766 000024 00000000001 11447366234 027423 0ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/requires.txt000644 000766 000024 00000000166 11447366247 027604 0ustar00macstaff000000 000000 setuptools zope.authentication zope.component zope.interface zope.password zope.security [test] zope.component [test]zope.principalregistry-3.7.1/src/zope.principalregistry.egg-info/top_level.txt000644 000766 000024 00000000005 11447366247 027726 0ustar00macstaff000000 000000 zope zope.principalregistry-3.7.1/src/zope/__init__.py000644 000766 000024 00000000311 11447366233 022035 0ustar00macstaff000000 000000 # 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.principalregistry-3.7.1/src/zope/principalregistry/000755 000766 000024 00000000000 11447366250 023502 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/principalregistry/README.txt000644 000766 000024 00000021217 11447366233 025204 0ustar00macstaff000000 000000 =========================== Global principal definition =========================== Global principals are defined via ZCML. There are several kinds of principals that can be defined. Authenticated Users ------------------- There are principals that can log in: >>> zcml(""" ... ... ... ... ... ... """) >>> import pprint >>> from zope.principalregistry.principalregistry import principalRegistry >>> [p] = principalRegistry.getPrincipals('') >>> p.id, p.title, p.description, p.getLogin(), p.validate('123') ('zope.manager', u'Manager', u'System Manager', u'admin', True) The unauthenticated principal ----------------------------- There is the unauthenticated principal: >>> zcml(""" ... ... ... ... ... ... """) >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated principal will also be registered as a utility. This is to provide easy access to the data defined for the principal so that other (more featureful) principal objects can be created for the same principal. >>> from zope import component >>> from zope.authentication import interfaces >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, p.title, p.description ('zope.unknown', u'Anonymous user', u"A person we don't know") The unauthenticated group ------------------------- An unauthenticated group can also be defined in ZCML: >>> zcml(""" ... ... ... ... ... ... """) This directive creates a group and registers it as a utility providing IUnauthenticatedGroup: >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup', u'Anonymous users', u"People we don't know") The unauthenticatedGroup directive also updates the group of the unauthenticated principal: >>> p = principalRegistry.unauthenticatedPrincipal() >>> g.id in p.groups True >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> g.id in p.groups True If the unauthenticated principal is defined after the unauthenticated group, it will likewise have the group added to it: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... """) >>> g = component.getUtility(interfaces.IUnauthenticatedGroup) >>> g.id, g.title, g.description ('zope.unknowngroup2', u'Anonymous users', u"People we don't know") >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown2', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown2', True) The unauthenticated group shows up as a principal in the principal registry: >>> principalRegistry.getPrincipal(g.id) == g True >>> list(principalRegistry.getPrincipals("Anonymous")) == [g] True The authenticated group ----------------------- There is an authenticated group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) It defines an IAuthenticatedGroup utility: >>> g = component.getUtility(interfaces.IAuthenticatedGroup) >>> g.id, g.title, g.description ('zope.authenticated', u'Authenticated users', u'People we know') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.authenticated False zope.manager2 True zope.manager3 True Excluding unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown3', False) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown3', False) The everybody group ------------------- Finally, there is an everybody group: >>> reset() >>> zcml(""" ... ... ... ... ... ... ... ... ... """) The everybodyGroup directive defines an IEveryoneGroup utility: >>> g = component.getUtility(interfaces.IEveryoneGroup) >>> g.id, g.title, g.description ('zope.everybody', u'Everybody', u'All People') It also adds it self to the groups of any non-group principals already defined, and, when non-group principals are defined, they put themselves in the group if it's defined: >>> principals = list(principalRegistry.getPrincipals('')) >>> principals.sort(lambda p1, p2: cmp(p1.id, p2.id)) >>> for p in principals: ... print p.id, p.groups == [g.id] zope.everybody False zope.manager4 True zope.manager5 True Including unauthenticated principals, of course: >>> p = principalRegistry.unauthenticatedPrincipal() >>> p.id, g.id in p.groups ('zope.unknown4', True) >>> p = component.getUtility(interfaces.IUnauthenticatedPrincipal) >>> p.id, g.id in p.groups ('zope.unknown4', True) Note that it is up to IAuthentication implementations to associate these groups with their principals, as appropriate. The system_user --------------- There is also a system_user that is defined in the code. It will be returned from the getPrincipal method of the registry. >>> import zope.security.management >>> import zope.principalregistry.principalregistry >>> auth = zope.principalregistry.principalregistry.PrincipalRegistry() >>> system_user = auth.getPrincipal(u'zope.security.management.system_user') >>> system_user is zope.security.management.system_user True zope.principalregistry-3.7.1/src/zope/principalregistry/__init__.py000644 000766 000024 00000000021 11447366233 025605 0ustar00macstaff000000 000000 # i am a package zope.principalregistry-3.7.1/src/zope/principalregistry/configure.zcml000644 000766 000024 00000000766 11447366233 026364 0ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/principalregistry/meta.zcml000644 000766 000024 00000002170 11447366233 025320 0ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/principalregistry/metaconfigure.py000644 000766 000024 00000011105 11447366233 026703 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Directives for defining principals and groups """ from zope import component from zope.component.zcml import utility from zope.authentication import interfaces from zope.principalregistry import principalregistry def _principal(): group = component.queryUtility(interfaces.IAuthenticatedGroup) if group is not None: _authenticatedGroup(group.id) group = component.queryUtility(interfaces.IEveryoneGroup) if group is not None: _everybodyGroup(group.id) def principal(_context, id, title, login, password, description='', password_manager="Plain Text"): _context.action( discriminator = ('principal', id), callable = principalregistry.principalRegistry.definePrincipal, args = (id, title, description, login, password, password_manager) ) _context.action(discriminator = None, callable = _principal, args = ()) def _unauthenticatedPrincipal(): group = component.queryUtility(interfaces.IUnauthenticatedGroup) if group is not None: _unauthenticatedGroup(group.id) group = component.queryUtility(interfaces.IEveryoneGroup) if group is not None: _everybodyGroup(group.id) def unauthenticatedPrincipal(_context, id, title, description=''): principal = principalregistry.UnauthenticatedPrincipal( id, title, description) _context.action( discriminator = 'unauthenticatedPrincipal', callable = principalregistry.principalRegistry.defineDefaultPrincipal, args = (id, title, description, principal) ) utility(_context, interfaces.IUnauthenticatedPrincipal, principal) _context.action( discriminator = None, callable = _unauthenticatedPrincipal, args = (), ) def _unauthenticatedGroup(group): p = principalregistry.principalRegistry.unauthenticatedPrincipal() if p is not None: p.groups.append(group) def unauthenticatedGroup(_context, id, title, description=''): principal = principalregistry.UnauthenticatedGroup( id, title, description) utility(_context, interfaces.IUnauthenticatedGroup, principal) _context.action( discriminator = None, callable = _unauthenticatedGroup, args = (principal.id, ), ) _context.action( discriminator = None, callable = principalregistry.principalRegistry.registerGroup, args = (principal, ), ) def _authenticatedGroup(group): for p in principalregistry.principalRegistry.getPrincipals(''): if not isinstance(p, principalregistry.Principal): continue if group not in p.groups: p.groups.append(group) def authenticatedGroup(_context, id, title, description=''): principal = principalregistry.AuthenticatedGroup( id, title, description) utility(_context, interfaces.IAuthenticatedGroup, principal) _context.action( discriminator = None, callable = _authenticatedGroup, args = (principal.id, ), ) _context.action( discriminator = None, callable = principalregistry.principalRegistry.registerGroup, args = (principal, ), ) def _everybodyGroup(group): for p in principalregistry.principalRegistry.getPrincipals(''): if not isinstance(p, principalregistry.Principal): continue if group not in p.groups: p.groups.append(group) p = principalregistry.principalRegistry.unauthenticatedPrincipal() if p is not None: p.groups.append(group) def everybodyGroup(_context, id, title, description=''): principal = principalregistry.EverybodyGroup( id, title, description) utility(_context, interfaces.IEveryoneGroup, principal) _context.action( discriminator = None, callable = _everybodyGroup, args = (principal.id, ), ) _context.action( discriminator = None, callable = principalregistry.principalRegistry.registerGroup, args = (principal, ), ) zope.principalregistry-3.7.1/src/zope/principalregistry/metadirectives.py000644 000766 000024 00000004435 11447366233 027073 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Schemas for directives that define principals and groups """ from zope.interface import Interface from zope.schema import Id, TextLine class IBasePrincipalDirective(Interface): """Base interface for principal definition directives.""" id = Id( title=u"Id", description=u"Id as which this object will be known and used.", required=True) title = TextLine( title=u"Title", description=u"Provides a title for the object.", required=True) description = TextLine( title=u"Title", description=u"Provides a description for the object.", required=False) class IDefinePrincipalDirective(IBasePrincipalDirective): """Define a new principal.""" login = TextLine( title=u"Username/Login", description=u"Specifies the Principal's Username/Login.", required=True) password = TextLine( title=u"Password", description=u"Specifies the Principal's Password.", required=True) password_manager = TextLine( title=u"Password Manager Name", description=(u"Name of the password manager will be used" " for encode/check the password"), default=u"Plain Text" ) class IDefineUnauthenticatedPrincipalDirective(IBasePrincipalDirective): """Define a new unauthenticated principal.""" class IDefineUnauthenticatedGroupDirective(IBasePrincipalDirective): """Define the unauthenticated group.""" class IDefineAuthenticatedGroupDirective(IBasePrincipalDirective): """Define the authenticated group.""" class IDefineEverybodyGroupDirective(IBasePrincipalDirective): """Define the everybody group.""" zope.principalregistry-3.7.1/src/zope/principalregistry/principalregistry.py000644 000766 000024 00000014164 11447366233 027635 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Global Authentication Utility or Principal Registry """ from zope.component import getUtility from zope.interface import implements import zope.security.management from zope.security.interfaces import IGroupAwarePrincipal from zope.password.interfaces import IPasswordManager from zope.authentication.interfaces import ( IAuthentication, PrincipalLookupError, ILoginPassword, ILogout, IUnauthenticatedPrincipal, IUnauthenticatedGroup, IAuthenticatedGroup, IEveryoneGroup, ) class DuplicateLogin(Exception): pass class DuplicateId(Exception): pass class PrincipalRegistry(object): implements(IAuthentication, ILogout) # Methods implementing IAuthentication def authenticate(self, request): a = ILoginPassword(request, None) if a is not None: login = a.getLogin() if login is not None: p = self.__principalsByLogin.get(login, None) if p is not None: password = a.getPassword() if p.validate(password): return p return None __defaultid = None __defaultObject = None def defineDefaultPrincipal(self, id, title, description='', principal=None): if id in self.__principalsById: raise DuplicateId(id) self.__defaultid = id if principal is None: principal = UnauthenticatedPrincipal(id, title, description) principal.__name__ = id principal.__parent__ = self self.__defaultObject = principal return principal def unauthenticatedPrincipal(self): return self.__defaultObject def unauthorized(self, id, request): if id is None or id is self.__defaultid: a = ILoginPassword(request) a.needLogin(realm="Zope") def getPrincipal(self, id): r = self.__principalsById.get(id) if r is None: if id == self.__defaultid: return self.__defaultObject if id == zope.security.management.system_user.id: return zope.security.management.system_user raise PrincipalLookupError(id) return r def getPrincipalByLogin(self, login): return self.__principalsByLogin[login] def getPrincipals(self, name): name = name.lower() return [p for p in self.__principalsById.itervalues() if p.title.lower().startswith(name) or p.getLogin().lower().startswith(name)] def logout(self, request): # not supporting basic auth logout -- no such thing pass # Management methods def __init__(self): self.__principalsById = {} self.__principalsByLogin = {} def definePrincipal(self, principal, title, description='', login='', password='', passwordManagerName='Plain Text'): id=principal if login in self.__principalsByLogin: raise DuplicateLogin(login) if id in self.__principalsById or id == self.__defaultid: raise DuplicateId(id) p = Principal(id, title, description, login, password, passwordManagerName) p.__name__ = id p.__parent__ = self self.__principalsByLogin[login] = p self.__principalsById[id] = p return p def registerGroup(self, group): id = group.id if id in self.__principalsById or id == self.__defaultid: raise DuplicateId(id) self.__principalsById[group.id] = group def _clear(self): self.__init__() self.__defaultid = None self.__defaultObject = None principalRegistry = PrincipalRegistry() # Register our cleanup with Testing.CleanUp to make writing unit tests # simpler. try: from zope.testing.cleanup import addCleanUp except ImportError: pass else: addCleanUp(principalRegistry._clear) del addCleanUp class PrincipalBase(object): __name__ = __parent__ = None def __init__(self, id, title, description): self.id = id self.title = title self.description = description self.groups = [] class Group(PrincipalBase): def getLogin(self): return '' # to make registry search happy class Principal(PrincipalBase): implements(IGroupAwarePrincipal) def __init__(self, id, title, description, login, pw, pwManagerName="Plain Text"): super(Principal, self).__init__(id, title, description) self.__login = login self.__pwManagerName = pwManagerName self.__pw = pw def __getPasswordManager(self): return getUtility(IPasswordManager, self.__pwManagerName) def getLogin(self): return self.__login def validate(self, pw): pwManager = self.__getPasswordManager() return pwManager.checkPassword(self.__pw, pw) class UnauthenticatedPrincipal(PrincipalBase): implements(IUnauthenticatedPrincipal) fallback_unauthenticated_principal = ( UnauthenticatedPrincipal( __name__+'.fallback_unauthenticated_principal', 'Fallback unauthenticated principal', 'The default unauthenticated principal. Used as a fallback to ' 'allow challenging for a user even if the IAuthentication returned ' 'None as the unauthenticated principal.')) class UnauthenticatedGroup(Group): implements(IUnauthenticatedGroup) class AuthenticatedGroup(Group): implements(IAuthenticatedGroup) class EverybodyGroup(Group): implements(IEveryoneGroup) zope.principalregistry-3.7.1/src/zope/principalregistry/tests/000755 000766 000024 00000000000 11447366250 024644 5ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/principalregistry/tests/__init__.py000644 000766 000024 00000000020 11447366233 026746 0ustar00macstaff000000 000000 # i am a packagezope.principalregistry-3.7.1/src/zope/principalregistry/tests/principal.zcml000644 000766 000024 00000000777 11447366233 027530 0ustar00macstaff000000 000000 zope.principalregistry-3.7.1/src/zope/principalregistry/tests/test_doc.py000644 000766 000024 00000002627 11447366233 027032 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Tests for the principal registry ZCML directives """ from zope.component.testing import setUp as setUpComponent from zope.component.testing import tearDown as tearDownComponent from zope.configuration import xmlconfig from zope.password.testing import setUpPasswordManagers import doctest import unittest def setUp(test=None): setUpComponent() setUpPasswordManagers() def tearDown(test=None): tearDownComponent() def zcml(s): import zope.principalregistry context = xmlconfig.file('meta.zcml', zope.principalregistry) xmlconfig.string(s, context) def reset(): tearDown() setUp() def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite('../README.txt', setUp=setUp, globs={'zcml': zcml, 'reset': reset}), )) zope.principalregistry-3.7.1/src/zope/principalregistry/tests/test_principalregistry.py000644 000766 000024 00000012704 11447366233 032034 0ustar00macstaff000000 000000 ############################################################################## # # Copyright (c) 2001-2009 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. # ############################################################################## """Tests for the principal registry """ import unittest from zope.authentication.interfaces import PrincipalLookupError from zope.authentication.loginpassword import LoginPassword from zope.component import provideAdapter from zope.interface import implements from zope.password.testing import setUpPasswordManagers from zope.principalregistry.principalregistry import PrincipalRegistry from zope.principalregistry.principalregistry import DuplicateLogin, DuplicateId class Request(LoginPassword): challenge = None def __init__(self, lpw): if lpw is not None: l, p = lpw else: l = p = None super(Request, self).__init__(l, p) def needLogin(self, realm): self.challenge = 'basic realm="%s"' % realm class Test(unittest.TestCase): def setUp(self): setUpPasswordManagers() 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), ))