Author: tmckay
Date: 2011-09-28 17:22:06 +0000 (Wed, 28 Sep 2011)
New Revision: 5024
Modified:
trunk/cumin/python/cumin/authenticator.py
Log:
Make failed import of ldap modules non-fatal, add log message
that ldap authentication mechanism is not available if imports fail
Modified: trunk/cumin/python/cumin/authenticator.py
===================================================================
--- trunk/cumin/python/cumin/authenticator.py 2011-09-28 14:52:08 UTC (rev 5023)
+++ trunk/cumin/python/cumin/authenticator.py 2011-09-28 17:22:06 UTC (rev 5024)
@@ -1,6 +1,11 @@
from util import *
-import ldap
-import ldapurl
+try:
+ import ldap
+ import ldapurl
+ have_ldap = True
+except:
+ have_ldap = False
+
import subprocess
from subprocess import PIPE
from psycopg2 import IntegrityError
@@ -208,8 +213,11 @@
return True
return False
-authen_map = { 'ldap': CuminAuthenticatorLDAP,
- 'script': CuminAuthenticatorScript }
+if have_ldap:
+ authen_map = {'ldap': CuminAuthenticatorLDAP,
+ 'script': CuminAuthenticatorScript}
+else:
+ authen_map = {'script': CuminAuthenticatorScript}
class CuminAuthenticator(object):
def __init__(self, app, log_authentication=True):
@@ -217,16 +225,20 @@
self.app = app
_syslog.log_auth = log_authentication
log.info("Initializing %s", self)
+ if not have_ldap:
+ log.info("Authenticator: import of ldap modules failed, "\
+ "ldap mechanism not available")
for authmech in app.authmech:
- try:
- mechname = authmech.split('=')[0]
- log.info("Authenticator: adding auth mechanism %s", mechname)
- classname = authen_map[mechname]
- except KeyError:
- log.error("Authenticator: unsupported authenticator type %s",
- mechname)
- continue
- self.authenticators.append(classname(authmech))
+ if authmech != "internal":
+ try:
+ mechname = authmech.split('=')[0]
+ log.info("Authenticator: adding auth mechanism %s",
mechname)
+ classname = authen_map[mechname]
+ except KeyError:
+ log.error("Authenticator: unsupported authenticator type
%s",
+ mechname)
+ continue
+ self.authenticators.append(classname(authmech))
def batch_import(self, backend, output_on=False):
numusers = 0
Show replies by date