2 commits - pykolab/auth
Jeroen van Meeuwen
vanmeeuwen at kolabsys.com
Fri Sep 20 17:52:55 CEST 2013
pykolab/auth/ldap/__init__.py | 12 ++++++++++--
pykolab/auth/ldap/auth_cache.py | 13 ++++++++-----
2 files changed, 18 insertions(+), 7 deletions(-)
New commits:
commit d49a1c3983e7b0e0f99a093fe6bfc2dd63f1ab36
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Sep 20 17:46:13 2013 +0200
Make sure entries are purged, and that the key is long enough
diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
index 12f362c..ba14262 100644
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -71,7 +71,7 @@ entry_table = Table(
'entries', metadata,
Column('id', Integer, primary_key=True),
Column('domain', String(128), index=True, nullable=True),
- Column('key', String(128), index=True, nullable=False),
+ Column('key', String(512), index=True, nullable=False),
Column('value', String(128), nullable=False),
Column('last_change', DateTime, nullable=False, default=datetime.datetime.now())
)
@@ -114,9 +114,8 @@ def set_entry(key, value):
db.commit()
-#def purge_entries():
- #db = init_db()
- #db.query(Entry).filter(Entry.last_change <= datetime.datetime.now()).delete()
+def purge_entries(db):
+ db.query(Entry).filter(Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))).delete()
def init_db():
"""
@@ -127,12 +126,16 @@ def init_db():
if not db == None:
return db
- db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
+ db_uri = conf.get('ldap', 'auth_cache_uri')
+ if db_uri == None:
+ db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
+
echo = conf.debuglevel > 8
engine = create_engine(db_uri, echo=echo)
metadata.create_all(engine)
Session = sessionmaker(bind=engine)
db = Session()
+ purge_entries(db)
return db
commit 7d1e0aae9bbd1599968cf1ddd7a1b7ac04a7c9fa
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date: Fri Sep 20 17:45:29 2013 +0200
Do not fail authentication should the authentication cache fail
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 042592b..1078525 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -169,7 +169,11 @@ class LDAP(pykolab.base.Base):
else:
base_dn = config_base_dn
- auth_cache.set_entry(self.domain, base_dn)
+ try:
+ auth_cache.set_entry(self.domain, base_dn)
+ except Exception, errmsg:
+ log.error(_("Authentication cache failed: %r") % (errmsg))
+ pass
user_filter = self.config_get_raw('user_filter') % ({'base_dn':base_dn})
@@ -216,7 +220,11 @@ class LDAP(pykolab.base.Base):
# to True!!
self.ldap.simple_bind_s(entry_dn, login[1])
retval = True
- auth_cache.set_entry(_filter, entry_dn)
+ try:
+ auth_cache.set_entry(_filter, entry_dn)
+ except Exception, errmsg:
+ log.error(_("Authentication cache failed: %r") % (errmsg))
+ pass
except:
try:
log.debug(
More information about the commits
mailing list