[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/Authentication - DictionaryAuthentication.py:1.1.2.1 IAuthentication.py:1.1.2.1 IUser.py:1.1.2.1 SimpleUser.py:1.1.2.1 __init__.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Tue, 2 Apr 2002 10:35:23 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/Authentication
In directory cvs.zope.org:/tmp/cvs-serv15879/Authentication

Added Files:
      Tag: Zope3-Server-Branch
	DictionaryAuthentication.py IAuthentication.py IUser.py 
	SimpleUser.py __init__.py 
Log Message:
Added a most trivial Authentication mechanism for two reasons:

1. Allow us easy testing of the server framework.
2. Support for non-Zope authentication, so that the servers can be used
   independently of Zope.


=== Added File Zope3/lib/python/Zope/Server/Authentication/DictionaryAuthentication.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
# 
##############################################################################
"""

$Id: DictionaryAuthentication.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""

from IAuthentication import IAuthentication
from SimpleUser import SimpleUser, AnonymousUser

class DictionaryAuthentication:
    """ """

    __implements__ = IAuthentication

    # See Zope.Server.Authentication.IAuthentication.IAuthentication
    user_class = SimpleUser
    anonymous_user = AnonymousUser

    def __init__(self, user_dict):
        self.user_dict = user_dict

    ############################################################
    # Implementation methods for interface
    # Zope.Server.Authentication.IAuthentication.

    def authenticate(self, username, password):
        'See Zope.Server.Authentication.IAuthentication.IAuthentication'

        if ( username in self.user_dict.keys() and
             password == self.user_dict[username]):
            return self.user_class(username)
        else:
            return self.anonymous_user

    #
    ############################################################


=== Added File Zope3/lib/python/Zope/Server/Authentication/IAuthentication.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
# 
##############################################################################
"""

$Id: IAuthentication.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""


from Interface import Interface
from Interface.Attribute import Attribute

class IAuthentication(Interface):
    """Authentica
    """

    user_class = Attribute("""
                     This attribute contains the user factory that is used
                     once the user is authenticated.
                     """)

    anonymous_user = Attribute("""The instance of the anonymous user.""")

    
    def authenticate(username, password):
        """
        """

        return IUser


=== Added File Zope3/lib/python/Zope/Server/Authentication/IUser.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
# 
##############################################################################
"""

$Id: IUser.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""


from Interface import Interface
from Interface.Attribute import Attribute

class IUser(Interface):
    """In order to have a uniform return type in the authentication model,
       a simple user is defined.

       Note: This user can become very complex, supporting groups, permissions,
       a personal data storage and so on.
    """

    username = Attribute("The username of the user")


=== Added File Zope3/lib/python/Zope/Server/Authentication/SimpleUser.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
# 
##############################################################################
"""

$Id: SimpleUser.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""

from IUser import IUser


class SimpleUser:
    """A simple user implementation."""

    __implements__ = IUser

    username = None

    def __init__(self, username):

        self.username = username



AnonymousUser = SimpleUser('anonymous')


=== Added File Zope3/lib/python/Zope/Server/Authentication/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.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.
# 
##############################################################################
"""

$Id: __init__.py,v 1.1.2.1 2002/04/02 15:35:22 srichter Exp $
"""