[bin] backup.py: remove Data.fs.old before packing the ZODB to avoid disk space problems; [checkldap] added a param to define the scope of the LDAP query (base, onelevel or subtree); [shared] xml_parser: convert nbsp entity to the equivalent utf-8 char.

This commit is contained in:
Gaetan Delannay 2013-09-05 10:42:19 +02:00
parent 528cca9aa0
commit 1be7d9f0ab
8 changed files with 83 additions and 22 deletions

View file

@ -369,15 +369,22 @@ class User(Model):
# ------------------------------------------------------------------------------
class LdapConfig:
'''Parameters for authenticating users to an external LDAP.'''
server = '' # Name of the LDAP server
port = None # Port for this server.
# Login and password of the technical power user that the Appy application
# will use to connect to the LDAP.
adminLogin = ''
adminPassword = ''
# LDAP attribute to use as login for authenticating users.
loginAttribute = 'dn' # Can also be "mail", "sAMAccountName", "cn"
baseDn = '' # Base distinguished name where to find users in the LDAP.
def __init__(self):
self.server = '' # Name of the LDAP server
self.port = None # Port for this server.
# Login and password of the technical power user that the Appy
# application will use to connect to the LDAP.
self.adminLogin = ''
self.adminPassword = ''
# LDAP attribute to use as login for authenticating users.
self.loginAttribute = 'dn' # Can also be "mail", "sAMAccountName", "cn"
self.baseDn = '' # Base distinguished name where to find users.
def getServerUri(self):
'''Returns the complete URI for accessing the LDAP, ie
"ldap://some.ldap.server:389".'''
port = self.port or 389
return 'ldap://%s:%d' % (self.server, port)
# ------------------------------------------------------------------------------
class Config:

View file

@ -25,12 +25,11 @@ def traverseWrapper(self, path, response=None, validated_hook=None):
'''This function is called every time a users gets a URL, this is used for
tracking user activity. self is a BaseRequest'''
res = originalTraverse(self, path, response, validated_hook)
t = time.time()
if os.path.splitext(path)[-1].lower() not in doNotTrack:
# Do nothing when the user gets non-pages
# Do nothing when the user gets non-pages.
userId, dummy = gutils.readCookie(self)
if userId:
loggedUsers[userId] = t
loggedUsers[userId] = time.time()
# "Touch" the SESSION object. Else, expiration won't occur.
session = self.SESSION
return res

View file

@ -1,5 +1,34 @@
# ------------------------------------------------------------------------------
try:
import ldap
except ImportError:
# For people that do not care about ldap.
ldap = None
# ------------------------------------------------------------------------------
def connect(serverUri, login, password):
'''Tries to connect to some LDAP server whose UIR is p_serverUri, using
p_login and p_password as credentials.'''
try:
server = ldap.initialize(serverUri)
server.simple_bind(login, password)
return True, server, None
except ldap.LDAPError, le:
return False, None, str(le)
# ------------------------------------------------------------------------------
def authenticate(login, password, ldapConfig, tool):
'''Tries to authenticate user p_login in the LDAP.'''
return
'''Tries to authenticate user p_login in the LDAP.'''
# Connect to the ldap server.
serverUri = cfg.getServerUri()
success, server, msg = connect(serverUri, cfg.adminLogin, cfg.adminPassword)
# Manage a connection error.
if not success:
tool.log('%s: connect error (%s).' % (serverUri, msg))
return
# Do p_login and p_password correspond to a user in the LDAP?
try:
pass
except:
pass
# ------------------------------------------------------------------------------

View file

@ -1051,6 +1051,7 @@ class ToolMixin(BaseMixin):
# a is the object the object was accessed through
# c is the physical container of the object
a, c, n, v = self._getobcontext(v, request)
print c
# Try to get user name and password from basic authentication
login, password = self.identify(auth)
if not login: