summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-09-23 12:08:57 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-09-23 12:08:57 +0200
commit88b6a39dd180968e5fc4fde1184d200db7fab1a0 (patch)
tree7c97055ba94b2c208636940d14cf10f2cddb8ded
parent4b484dcee75a368508d8c2c69274fe0d3457a9f4 (diff)
parentd49a1c3983e7b0e0f99a093fe6bfc2dd63f1ab36 (diff)
downloadpykolab-88b6a39dd180968e5fc4fde1184d200db7fab1a0.tar.gz
Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab
-rw-r--r--pykolab/auth/ldap/__init__.py12
-rw-r--r--pykolab/auth/ldap/auth_cache.py13
2 files changed, 18 insertions, 7 deletions
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(
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