Author: tmckay
Date: 2012-05-02 12:50:21 +0000 (Wed, 02 May 2012)
New Revision: 5353
Modified:
trunk/cumin/python/cumin/authenticator.py
Log:
Improve log messages related to LDAP
Modified: trunk/cumin/python/cumin/authenticator.py
===================================================================
--- trunk/cumin/python/cumin/authenticator.py 2012-05-01 15:57:45 UTC (rev 5352)
+++ trunk/cumin/python/cumin/authenticator.py 2012-05-02 12:50:21 UTC (rev 5353)
@@ -27,6 +27,7 @@
class CuminAuthenticatorLDAP(object):
def __init__(self, url):
+ self.valid = False
log.info("Initializing %s", self)
myurl = url.split("=",1)[1]
try:
@@ -34,6 +35,7 @@
scope=ldapurl.LDAP_SCOPE_SUBTREE,
filterstr="uid=%s")
log.info("Authenticator: parsed LDAP url successfully.")
+ self.valid = True
except Exception,e:
log.error("Authenticator: cannot parse LDAP url %s", e)
@@ -136,12 +138,11 @@
except Exception, e:
log.info("Authenticator: LDAP authentication "\
"returned exception %s" % e)
- _syslog.log("cumin: authentication via LDAP failed "\
- "for user %s" % dn)
return False
class CuminAuthenticatorScript(object):
def __init__(self, commandline):
+ self.valid = False
self.params = {}
self.cap = []
me = self.__class__.__name__
@@ -168,7 +169,8 @@
for cap in ("auth", "change", "list",
"find"):
if self.params.has_key(cap):
log.debug(msg % (cap, me))
- self.cap.append(cap[0])
+ self.cap.append(cap[0])
+ self.valid = True
else:
log.error('Authenticator: script parameter missing or target file '\
'not executable in %s', me)
@@ -190,7 +192,6 @@
if res.returncode == 0:
_syslog.log("cumin: authenticated user %s via script" %
username)
return True
- _syslog.log("cumin: authentication via script failed for user %s" %
username)
return False
def find_user(self, username):
@@ -277,14 +278,17 @@
authmech = "ldap=" + authmech
else:
mechname = authmech.split('=',1)[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))
+ c = classname(authmech)
+ if c.valid:
+ log.info("Authenticator: adding auth mechanism %s",
mechname)
+ self.authenticators.append(c)
+
def batch_import(self, backend, output_on=False):
numusers = 0
numconflicts = 0
@@ -336,23 +340,30 @@
return numusers, numconflicts, errors
def authenticate(self, username, password):
- log.debug("Authenticator: calling authenticate")
cursor = self.app.database.get_read_cursor()
cls = self.app.model.com_redhat_cumin.User
user = cls.get_object(cursor, name=username)
if user is None or len(user.password) == 0:
res = False
log.debug("Authenticator: authenticating external user")
+ if len(self.authenticators) == 0:
+ log.debug("Authenticator: no external mechanisms available")
for authenticator in self.authenticators:
log.debug("Authenticator: authenticate, try %s",
authenticator)
res = authenticator.authenticate(username, password)
if res:
break
+ log.debug("Authenticator: authentication %s for external user" \
+ % (res and "succeeded" or "failed"))
+ msg = "cumin: authentication %s for external user %s" \
+ % (res and "succeeded" or "failed", username)
else:
res = crypt(password, user.password) == user.password
+ log.debug("Authenticator: authentication %s for user" \
+ % (res and "succeeded" or "failed"))
msg = "cumin: authentication %s for user %s" \
% (res and "succeeded" or "failed", username)
- _syslog.log(msg)
+ _syslog.log(msg)
return user, res
def find_user(self, username):