[Erp5-report] r27234 - in /erp5/trunk/products/ERP5Security: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu May 28 16:27:49 CEST 2009
Author: jerome
Date: Thu May 28 16:27:46 2009
New Revision: 27234
URL: http://svn.erp5.org?rev=27234&view=rev
Log:
only fill the cache if authentication is successful
Modified:
erp5/trunk/products/ERP5Security/ERP5UserManager.py
erp5/trunk/products/ERP5Security/tests/testERP5Security.py
Modified: erp5/trunk/products/ERP5Security/ERP5UserManager.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Security/ERP5UserManager.py?rev=27234&r1=27233&r2=27234&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Security/ERP5UserManager.py [utf8] (original)
+++ erp5/trunk/products/ERP5Security/ERP5UserManager.py [utf8] Thu May 28 16:27:46 2009
@@ -57,6 +57,14 @@
'ERP5UserManager+added.'
% dispatcher.absolute_url())
+class _AuthenticationFailure(Exception):
+ """Raised when authentication failed, to prevent caching the fact that a user
+ does not exist (yet), which happens when someone try to login before the user
+ account is ready (like when the indexing not finished, an assignment not open
+ etc...)
+ """
+
+
class ERP5UserManager(BasePlugin):
""" PAS plugin for managing users in ERP5
"""
@@ -91,7 +99,7 @@
user_list = self.getUserByLogin(login)
if not user_list:
- return None
+ raise _AuthenticationFailure()
user = user_list[0]
@@ -118,16 +126,18 @@
return login, login # use same for user_id and login
finally:
setSecurityManager(sm)
-
- return None
+ raise _AuthenticationFailure()
_authenticateCredentials = CachingMethod(_authenticateCredentials,
id='ERP5UserManager_authenticateCredentials',
cache_factory='erp5_content_short')
- return _authenticateCredentials(
+ try:
+ return _authenticateCredentials(
login=credentials.get('login'),
password=credentials.get('password'),
path=self.getPhysicalPath())
+ except _AuthenticationFailure:
+ return None
#
# IUserEnumerationPlugin implementation
@@ -163,6 +173,7 @@
return tuple(user_info)
+ # XXX is this cache usefull ???
_enumerateUsers = CachingMethod(_enumerateUsers,
id='ERP5UserManager_enumerateUsers',
cache_factory='erp5_content_short')
@@ -249,12 +260,20 @@
# LIMIT 1000
# "bar OR foo" because of ZSQLCatalog tokenizing searched sgtrings
# by default (feature).
- return [x.path for x in result if (not exact_match) or x['reference'] in login]
+ result = [x.path for x in result if (not exact_match)
+ or x['reference'] in login]
+ if not result:
+ raise _AuthenticationFailure()
+ return result
+
_getUserByLogin = CachingMethod(_getUserByLogin,
id='ERP5UserManager_getUserByLogin',
cache_factory='erp5_content_short')
- result = _getUserByLogin(login, exact_match)
- return [portal.unrestrictedTraverse(x) for x in result]
+ try:
+ return [portal.unrestrictedTraverse(x) for x in
+ _getUserByLogin(login, exact_match)]
+ except _AuthenticationFailure:
+ return []
classImplements( ERP5UserManager
, IAuthenticationPlugin
Modified: erp5/trunk/products/ERP5Security/tests/testERP5Security.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Security/tests/testERP5Security.py?rev=27234&r1=27233&r2=27234&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Security/tests/testERP5Security.py [utf8] (original)
+++ erp5/trunk/products/ERP5Security/tests/testERP5Security.py [utf8] Thu May 28 16:27:46 2009
@@ -285,6 +285,23 @@
assi.close()
self._assertUserDoesNotExists('the_user', 'secret')
+ def test_PersonNotIndexedNotCached(self):
+ pers = self._makePerson(password='secret',)
+ pers.setReference('the_user')
+ # not indexed yet
+ self._assertUserDoesNotExists('the_user', 'secret')
+
+ transaction.commit()
+ self.tic()
+
+ self._assertUserExists('the_user', 'secret')
+
+ def test_PersonNotValidNotCached(self):
+ pers = self._makePerson(reference='the_user', password='other',)
+ self._assertUserDoesNotExists('the_user', 'secret')
+ pers.setPassword('secret')
+ self._assertUserExists('the_user', 'secret')
+
def test_AssignmentWithDate(self):
"""Tests a person with an assignment with correct date is a valid user."""
More information about the Erp5-report
mailing list