1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-06-09 12:27:50 +02:00
ldapcherry/ldapcherry/ppolicy/__init__.py

60 lines
1.8 KiB
Python
Raw Normal View History

2015-07-01 08:58:23 +02:00
# -*- coding: utf-8 -*-
# vim:set expandtab tabstop=4 shiftwidth=4:
#
# The MIT License (MIT)
# LdapCherry
# Copyright (c) 2014 Carpentier Pierre-Francois
2015-07-01 23:00:42 +02:00
from ldapcherry.exceptions import MissingParameter
2015-07-10 21:01:39 +02:00
2015-07-01 23:00:42 +02:00
class PPolicy:
2015-07-01 08:58:23 +02:00
def __init__(self, config, logger):
2015-07-17 08:28:39 +02:00
""" Password policy constructor
2015-07-20 00:41:29 +02:00
:param config: the configuration of the ppolicy
2015-07-21 00:28:38 +02:00
:type config: dict {'config key': 'value'}
2015-07-20 00:41:29 +02:00
:param logger: the cherrypy error logger object
2015-07-20 00:44:14 +02:00
:type logger: python logger
2015-07-10 21:01:39 +02:00
"""
2015-07-01 08:58:23 +02:00
pass
def check(self, password):
2015-07-17 08:28:39 +02:00
""" Check if a password match the ppolicy
2015-07-20 00:41:29 +02:00
:param password: the password to check
:type password: string
2015-07-17 08:28:39 +02:00
:rtype: dict with keys 'match' a boolean
2015-07-10 21:01:39 +02:00
(True if ppolicy matches, False otherwise)
and 'reason', an explaination string
"""
2015-07-01 08:58:23 +02:00
ret = {'match': True, 'reason': 'no password policy'}
2015-07-14 14:03:05 +02:00
return ret
2015-07-01 08:58:23 +02:00
def info(self):
2015-07-20 00:46:48 +02:00
""" Give information about the ppolicy
2015-07-17 08:28:39 +02:00
:rtype: a string describing the ppolicy
2015-07-10 21:01:39 +02:00
"""
2015-07-01 08:58:23 +02:00
ret = "There is no password policy configured"
2015-07-01 23:00:42 +02:00
def get_param(self, param, default=None):
2015-07-17 08:28:39 +02:00
""" Get a parameter in config (handle default value)
2015-07-20 00:41:29 +02:00
:param param: name of the parameter to recover
:type param: string
:param default: the default value, raises an exception
2015-07-10 21:01:39 +02:00
if param is not in configuration and default
is None (which is the default value).
2015-07-20 00:41:29 +02:00
:type default: string or None
2015-07-20 00:44:14 +02:00
:rtype: the value of the parameter or the default value if
not set in configuration
2015-07-10 21:01:39 +02:00
"""
2015-07-01 23:00:42 +02:00
if param in self.config:
return self.config[param]
2015-07-10 21:01:39 +02:00
elif default is not None:
2015-07-01 23:00:42 +02:00
return default
else:
2015-07-10 21:01:39 +02:00
raise MissingParameter('ppolicy', param)