1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-29 12:44:31 +01:00

implementing ppolicy handling and a simple ppolicy module

This commit is contained in:
kakwa 2015-07-02 07:42:38 +02:00
parent e964c5151e
commit 0d045576b2
3 changed files with 16 additions and 10 deletions

View File

@ -171,6 +171,14 @@ class LdapCherry(object):
except: except:
raise BackendModuleInitFail(module) raise BackendModuleInitFail(module)
def _init_ppolicy(self, config):
module = self._get_param('ppolicy', 'ppolicy.module', config, 'ldapcherry.ppolicy')
try:
pp = __import__(module, globals(), locals(), ['PPolicy'], -1)
except:
raise BackendModuleLoadingFail(module)
self.ppolicy = pp.PPolicy(config['ppolicy'], cherrypy.log)
def _init_auth(self, config): def _init_auth(self, config):
""" Init authentication """ Init authentication
@dict: configuration of ldapcherry @dict: configuration of ldapcherry
@ -378,7 +386,8 @@ class LdapCherry(object):
severity = logging.INFO severity = logging.INFO
) )
self.ppolicy = None # loading the ppolicy
self._init_ppolicy(config)
except Exception as e: except Exception as e:
self._handle_exception(e) self._handle_exception(e)
@ -683,9 +692,6 @@ class LdapCherry(object):
) )
def _checkppolicy(self, password): def _checkppolicy(self, password):
if self.ppolicy is None:
ret = { 'match': True, 'reason': 'No password Policy'}
else:
ret = self.ppolicy.check(password) ret = self.ppolicy.check(password)
return ret return ret

View File

@ -12,9 +12,9 @@ class PPolicy(ldapcherry.ppolicy.PPolicy):
def __init__(self, config, logger): def __init__(self, config, logger):
self.config = config self.config = config
self.min_length = get_param('min_length') self.min_length = self.get_param('min_length')
self.min_upper = get_param('min_upper') self.min_upper = self.get_param('min_upper')
self.min_digit = get_param('min_digit') self.min_digit = self.get_param('min_digit')
def check(self, password): def check(self, password):
if len(password) < self.min_length: if len(password) < self.min_length:
@ -31,6 +31,6 @@ class PPolicy(ldapcherry.ppolicy.PPolicy):
* Minimum number of uppercase characters: %(upper)n\n\ * Minimum number of uppercase characters: %(upper)n\n\
* Minimum number of digits: %(digit)n" % { 'upper': self.min_upper, * Minimum number of digits: %(digit)n" % { 'upper': self.min_upper,
'len': self.min_length, 'len': self.min_length,
'digit' self.min_digit, 'digit': self.min_digit,
} }

View File

@ -90,7 +90,7 @@ setup(
version = '0.0.1', version = '0.0.1',
author = 'Pierre-Francois Carpentier', author = 'Pierre-Francois Carpentier',
author_email = 'carpentier.pf@gmail.com', author_email = 'carpentier.pf@gmail.com',
packages = ['ldapcherry', 'ldapcherry.backend'], packages = ['ldapcherry', 'ldapcherry.backend', 'ldapcherry.ppolicy'],
data_files = resources_files, data_files = resources_files,
scripts = ['scripts/ldapcherryd'], scripts = ['scripts/ldapcherryd'],
url = 'https://github.com/kakwa/ldapcherry', url = 'https://github.com/kakwa/ldapcherry',