[Zope3-checkins]
SVN: Zope3/branches/hdima-password-managers/src/zope/app/
Password managers support added to PrincipalFolder
Dmitry Vasiliev
dima at hlabs.spb.ru
Sat Oct 22 12:23:04 EDT 2005
Log message for revision 39561:
Password managers support added to PrincipalFolder
Changed:
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/groupfolder.txt
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/pau_prefix_and_searching.txt
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.txt
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.zcml
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/special-groups.txt
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/principalfolder.py
UU Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/__init__.py
UU Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve1.py
A Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve2.py
-=-
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/groupfolder.txt
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/groupfolder.txt 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/groupfolder.txt 2005-10-22 16:23:03 UTC (rev 39561)
@@ -15,6 +15,12 @@
First, We need to create and register a pluggable authentication utility.
+ >>> from zope.app.testing import ztapi
+ >>> from zope.app.authentication.interfaces import IPasswordManager
+ >>> from zope.app.authentication.password import PlainTextPasswordManager
+ >>> manager = PlainTextPasswordManager()
+ >>> ztapi.provideUtility(IPasswordManager, manager, "Plain Text")
+
>>> print http(r"""
... POST /++etc++site/default/@@contents.html HTTP/1.1
... Authorization: Basic bWdyOm1ncnB3
@@ -153,6 +159,10 @@
...
... bob
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -192,6 +202,10 @@
...
... bill
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -231,6 +245,10 @@
...
... betty
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -270,6 +288,10 @@
...
... sally
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -308,6 +330,10 @@
...
... george
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -346,6 +372,10 @@
...
... mike
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
@@ -384,6 +414,10 @@
...
... mary
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... 123
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/pau_prefix_and_searching.txt
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/pau_prefix_and_searching.txt 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/pau_prefix_and_searching.txt 2005-10-22 16:23:03 UTC (rev 39561)
@@ -7,6 +7,12 @@
First we'll create a PAU with a prefix of 'pau1_' and and register:
+ >>> from zope.app.testing import ztapi
+ >>> from zope.app.authentication.interfaces import IPasswordManager
+ >>> from zope.app.authentication.password import PlainTextPasswordManager
+ >>> manager = PlainTextPasswordManager()
+ >>> ztapi.provideUtility(IPasswordManager, manager, "Plain Text")
+
>>> print http(r"""
... POST /++etc++site/default/+/AddPluggableAuthentication.html%3D HTTP/1.1
... Authorization: Basic bWdyOm1ncnB3
@@ -134,6 +140,10 @@
...
... bob
... -----------------------------300171485226567
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------300171485226567
... Content-Disposition: form-data; name="field.password"
...
... bob
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.txt
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.txt 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.txt 2005-10-22 16:23:03 UTC (rev 39561)
@@ -18,6 +18,14 @@
To allow Bob to log in, we'll start by adding a principal folder to PAU:
+First we need create a password manager:
+
+ >>> from zope.app.testing import ztapi
+ >>> from zope.app.authentication.interfaces import IPasswordManager
+ >>> from zope.app.authentication.password import PlainTextPasswordManager
+ >>> manager = PlainTextPasswordManager()
+ >>> ztapi.provideUtility(IPasswordManager, manager, "Plain Text")
+
We need to create and register a pluggable authentication utility.
>>> print http(r"""
@@ -176,6 +184,10 @@
...
... bob
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... bob
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.zcml
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.zcml 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/principalfolder.zcml 2005-10-22 16:23:03 UTC (rev 39561)
@@ -24,7 +24,8 @@
label="Add Principal Information"
content_factory="..principalfolder.InternalPrincipal"
arguments="login password title"
- keyword_arguments="description"
+ keyword_arguments="passwordManagerName description"
+ fields="login passwordManagerName password title description"
name="AddPrincipalInformation.html"
permission="zope.ManageServices"
/>
@@ -40,7 +41,7 @@
schema="..principalfolder.IInternalPrincipal"
label="Change Internal Principal"
name="edit.html"
- fields="login password title description"
+ fields="login passwordManagerName password title description"
permission="zope.ManageServices"
menu="zmi_views" title="Edit" />
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/special-groups.txt
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/special-groups.txt 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/browser/special-groups.txt 2005-10-22 16:23:03 UTC (rev 39561)
@@ -18,6 +18,12 @@
Create pluggable authentication utility and register it.
+ >>> from zope.app.testing import ztapi
+ >>> from zope.app.authentication.interfaces import IPasswordManager
+ >>> from zope.app.authentication.password import PlainTextPasswordManager
+ >>> manager = PlainTextPasswordManager()
+ >>> ztapi.provideUtility(IPasswordManager, manager, "Plain Text")
+
>>> print http(r"""
... POST /++etc++site/default/@@contents.html HTTP/1.1
... Authorization: Basic bWdyOm1ncnB3
@@ -145,6 +151,10 @@
...
... bob
... -----------------------------5110544421083023415453147877
+ ... Content-Disposition: form-data; name="field.passwordManagerName"
+ ...
+ ... Plain Text
+ ... -----------------------------5110544421083023415453147877
... Content-Disposition: form-data; name="field.password"
...
... bob
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml 2005-10-22 16:23:03 UTC (rev 39561)
@@ -5,7 +5,7 @@
<vocabulary
name="Password Manager Names"
factory="zope.app.component.vocabulary.UtilityVocabulary"
- interface=".interfaces.IPasswordManager"
+ interface="zope.app.authentication.interfaces.IPasswordManager"
nameOnly="True"
/>
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/principalfolder.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/principalfolder.py 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/principalfolder.py 2005-10-22 16:23:03 UTC (rev 39561)
@@ -21,10 +21,11 @@
from zope import interface
from zope import component
from zope.event import notify
-from zope.schema import Text, TextLine, Password
+from zope.schema import Text, TextLine, Password, Choice
from zope.publisher.interfaces import IRequest
from zope.security.interfaces import IGroupAwarePrincipal
+from zope.app import zapi
from zope.app.container.interfaces import DuplicateIDError
from zope.app.container.contained import Contained
from zope.app.container.constraints import contains, containers
@@ -42,10 +43,24 @@
description=_("The Login/Username of the principal. "
"This value can change."))
+ def setPassword(password, passwordManagerName=None):
+ pass
+
password = Password(
- title=_(u"Password"),
+ title=_("Password"),
description=_("The password for the principal."))
+ passwordManagerName = Choice(
+ title=_("Password Manager"),
+ vocabulary="Password Manager Names",
+ description=_("The password manager will be used"
+ " for encode/decode the password"),
+ default="Plain Text",
+ # TODO: The password manager name may be changed only
+ # if the password changed
+ readonly=True
+ )
+
title = TextLine(
title=_("Title"),
description=_("Provides a title for the principal."))
@@ -95,12 +110,41 @@
interface.implements(IInternalPrincipal, IInternalPrincipalContained)
- def __init__(self, login, password, title, description=u''):
+ def __init__(self, login, password, title, description=u'',
+ passwordManagerName="Plain Text"):
self._login = login
- self.password = password
+ self._password = password
+ self._passwordManagerName = passwordManagerName
self.title = title
self.description = description
+ def getPasswordManagerName(self):
+ return self._passwordManagerName
+
+ passwordManagerName = property(getPasswordManagerName)
+
+ def _getPasswordManager(self):
+ return zapi.getUtility(
+ interfaces.IPasswordManager, self.passwordManagerName)
+
+ def getPassword(self):
+ return self._password
+
+ def setPassword(self, password, passwordManagerName=None):
+ if passwordManagerName is not None:
+ self._passwordManagerName = passwordManagerName
+ passwordManager = self._getPasswordManager()
+ self._password = passwordManager.encodePassword(password)
+
+ password = property(getPassword, setPassword)
+
+ def checkPassword(self, password):
+ passwordManager = self._getPasswordManager()
+ return passwordManager.checkPassword(self.password, password)
+
+ def getPassword(self):
+ return self._password
+
def getLogin(self):
return self._login
@@ -226,7 +270,7 @@
if id is None:
return None
internal = self[id]
- if internal.password != credentials['password']:
+ if not internal.checkPassword(credentials["password"]):
return None
return PrincipalInfo(self.prefix + id, internal.login, internal.title,
internal.description)
Modified: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/__init__.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/__init__.py 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/__init__.py 2005-10-22 16:23:03 UTC (rev 39561)
@@ -24,7 +24,7 @@
ZopeAppSchemaManager = SchemaManager(
minimum_generation=0,
- generation=1,
+ generation=2,
package_name=key)
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve1.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve1.py 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve1.py 2005-10-22 16:23:03 UTC (rev 39561)
@@ -55,7 +55,7 @@
the component's path. Now it stores the component directly. All
registrations are updated to this new format.
- - Conerts all service registrations to utility registrations providing
+ - Converts all service registrations to utility registrations providing
IService, which is the method used to simulate the old service API.
- Remove 'RegistrationManager' object from all site management folders.
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve1.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve2.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve2.py 2005-10-22 15:32:19 UTC (rev 39560)
+++ Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve2.py 2005-10-22 16:23:03 UTC (rev 39561)
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Evolve the ZODB from Zope 3.1 to a Zope 3.2 compatible format.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.app.authentication.principalfolder import IInternalPrincipal
+from zope.app.component.interfaces import ISite
+from zope.app.zopeappgenerations import getRootFolder
+
+from zope.app.generations.utility import findObjectsProviding
+
+
+generation = 2
+
+def evolve(context):
+ """Evolve the ZODB from a Zope 3.1 to a 3.2 compatible format.
+
+ - Converts all internal principals to use new password managers.
+ """
+ root = getRootFolder(context)
+
+ for site in findObjectsProviding(root, ISite):
+ sm = site.getSiteManager()
+ for principal in findObjectsProviding(sm, IInternalPrincipal):
+ if not hasattr(principal, "passwordManagerName"):
+ principal.passwordManagerName = "Plain Text"
+ if not hasattr(principal, "_password"):
+ principal._password = principal.__dict__["password"]
+ del principal.__dict__["password"]
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/zopeappgenerations/evolve2.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Zope3-Checkins
mailing list