[Zope3-checkins] CVS: Products3/demo/passwdauth - README.txt:1.1 USAGE.txt:1.1 VERSION.txt:1.1 ZopePublicLicense.txt:1.1 __init__.py:1.1 configure.zcml:1.1 interfaces.py:1.1
Stephan Richter
srichter@cosmos.phy.tufts.edu
Thu, 17 Jul 2003 10:58:19 -0400
Update of /cvs-repository/Products3/demo/passwdauth
In directory cvs.zope.org:/tmp/cvs-serv3769
Added Files:
README.txt USAGE.txt VERSION.txt ZopePublicLicense.txt
__init__.py configure.zcml interfaces.py
Log Message:
Ahh, I totally forgot to check this in. It is the code that comes with this
recipe: http://dev.zope.org/Zope3/NewPrincipalSourcePlugins
=== Added File Products3/demo/passwdauth/README.txt ===
Passwd Principal Authentication Source Demo Product
This product is developed as an example for the Zope 3 Cookbook. You can
find the text at http://dev.zope.org/Zope3/DevelCookbook. Therefore the
product will never be considered feature complete and look like a very crude
product. However, it demonstrates nicely the necessary steps that have to be
taken to create a principal authentication source.
IMPORTANT: Please do not edit any of the steps (except adding comments)
unless you are willing to make the correct modifications in the
corresponding recipe as well!
Feel free to send comments to srichter@cosmos.phy.tufts.edu.
=== Added File Products3/demo/passwdauth/USAGE.txt ===
This product is meant to be installed in 'ZOPE3/src/zopeproducts' and not from
the 'demo' directory. I placed the product in here, since it is not feature
complete and never will, since it is a demo for the Developer's Cookbook.
=== Added File Products3/demo/passwdauth/VERSION.txt ===
0.1
=== Added File Products3/demo/passwdauth/ZopePublicLicense.txt ===
Zope Public License (ZPL) Version 2.0
-----------------------------------------------
This software is Copyright (c) Zope Corporation (tm) and
Contributors. All rights reserved.
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 above
copyright notice, this list of conditions, and the following
disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions, and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
3. The name Zope Corporation (tm) must not be used to
endorse or promote products derived from this software
without prior written permission from Zope Corporation.
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 Zope Corporation. Use of them is
covered in a separate agreement (see
http://www.zope.com/Marks).
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 ZOPE CORPORATION ``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 ZOPE CORPORATION OR ITS CONTRIBUTORS 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.
This software consists of contributions made by Zope
Corporation and many individuals on behalf of Zope
Corporation. Specific attributions are listed in the
accompanying credits file.
=== Added File Products3/demo/passwdauth/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""/etc/passwd Authentication Plugin
This package defines a new authentication plugin, which can use textfiles to
authenticate users.
$Id: __init__.py,v 1.1 2003/07/17 14:58:11 srichter Exp $
"""
from zope.app.interfaces.services.pluggableauth import \
ILoginPasswordPrincipalSource
from interfaces import IFileBasedPrincipalSource
import os
from persistence import Persistent
from zope.interface import implements
from zope.app.services.pluggableauth import SimplePrincipal
from zope.exceptions import NotFoundError
class PasswdPrincipalSource(Persistent):
"""A Principal Source for /etc/passwd-like files."""
implements(ILoginPasswordPrincipalSource, IFileBasedPrincipalSource)
def __init__(self, filename=''):
self.filename = filename
def readPrincipals(self):
if not os.path.exists(self.filename):
return []
file = open(self.filename, 'r')
principals = []
for line in file.readlines():
if line.strip() != '':
user_info = line.strip().split(':', 3)
p = SimplePrincipal(*user_info)
p.id = p.login
principals.append(p)
return principals
def getPrincipal(self, id):
"""See IPrincipalSource.
In this case the login equals the id.
"""
for p in self.readPrincipals():
if p.id == id:
return p
raise NotFoundError, id
def getPrincipals(self, name):
"""See IPrincipalSource."""
return filter(lambda p: p.login.find(name) != -1,
self.readPrincipals())
def authenticate(self, login, password):
"""See ILoginPasswordPrincipalSource. """
for user in self.readPrincipals():
if user.login == login and user.password == password:
return user
=== Added File Products3/demo/passwdauth/configure.zcml ===
<zopeConfigure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<content class=".PasswdPrincipalSource">
<factory
id="zope.app.principalsources.PasswdPrincipalSource"
permission="zope.ManageServices"/>
<allow interface=".interfaces.IFileBasedPrincipalSource"/>
<require
permission="zope.ManageContent"
set_schema=".interfaces.IFileBasedPrincipalSource"/>
</content>
<browser:addform
schema=".interfaces.IFileBasedPrincipalSource"
label="Add file-based Principal Source in /etc/passwd style"
content_factory=".PasswdPrincipalSource"
arguments="filename"
name="AddPasswdPrincipalSourceForm"
menu="add_principal_source" title="/etc/passwd Principal Source"
permission="zope.ManageContent" />
<browser:editform
schema=".interfaces.IFileBasedPrincipalSource"
label="Add file-based Principal Source"
name="edit.html"
menu="zmi_views" title="Edit"
permission="zope.ManageContent" />
</zopeConfigure>
=== Added File Products3/demo/passwdauth/interfaces.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""/etc/passwd Authentication Plugin interfaces
$Id: interfaces.py,v 1.1 2003/07/17 14:58:11 srichter Exp $
"""
from zope.schema import TextLine
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.interfaces.services.pluggableauth import IPrincipalSource
class IFileBasedPrincipalSource(IPrincipalSource):
"""Describes file-based principal sources."""
filename = TextLine(
title = _(u'File Name'),
description=_(u'File name of the data file.'),
default = u'/etc/passwd',
)