comparison rhodecode/lib/auth_ldap.py @ 3632:1ec67ddcaffe beta

ldap: handle more elegantly that python-ldap isn't installed when trying to use ldap Don't fail with AttributeError: 'NoneType' object has no attribute 'SCOPE_SUBTREE' in the log.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 28 Mar 2013 01:15:56 +0100
parents 8464d0e96e97
children 3563bb7b4b82
comparison
equal deleted inserted replaced
3631:10b4e34841a4 3632:1ec67ddcaffe
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 import logging 26 import logging
27 27
28 from rhodecode.lib.exceptions import LdapConnectionError, LdapUsernameError, \ 28 from rhodecode.lib.exceptions import LdapConnectionError, LdapUsernameError, \
29 LdapPasswordError 29 LdapPasswordError, LdapImportError
30 from rhodecode.lib.utils2 import safe_str 30 from rhodecode.lib.utils2 import safe_str
31 31
32 log = logging.getLogger(__name__) 32 log = logging.getLogger(__name__)
33 33
34 34
35 try: 35 try:
36 import ldap 36 import ldap
37 except ImportError: 37 except ImportError:
38 # means that python-ldap is not installed 38 # means that python-ldap is not installed
39 pass 39 ldap = None
40 40
41 41
42 class AuthLdap(object): 42 class AuthLdap(object):
43 43
44 def __init__(self, server, base_dn, port=389, bind_dn='', bind_pass='', 44 def __init__(self, server, base_dn, port=389, bind_dn='', bind_pass='',
45 tls_kind='PLAIN', tls_reqcert='DEMAND', ldap_version=3, 45 tls_kind='PLAIN', tls_reqcert='DEMAND', ldap_version=3,
46 ldap_filter='(&(objectClass=user)(!(objectClass=computer)))', 46 ldap_filter='(&(objectClass=user)(!(objectClass=computer)))',
47 search_scope='SUBTREE', attr_login='uid'): 47 search_scope='SUBTREE', attr_login='uid'):
48 if ldap is None:
49 raise LdapImportError
50
48 self.ldap_version = ldap_version 51 self.ldap_version = ldap_version
49 ldap_server_type = 'ldap' 52 ldap_server_type = 'ldap'
50 53
51 self.TLS_KIND = tls_kind 54 self.TLS_KIND = tls_kind
52 55