2015-04-15 21:13:14 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim:set expandtab tabstop=4 shiftwidth=4:
|
|
|
|
#
|
|
|
|
# The MIT License (MIT)
|
|
|
|
# LdapCherry
|
|
|
|
# Copyright (c) 2014 Carpentier Pierre-Francois
|
|
|
|
|
2015-05-21 19:54:38 +02:00
|
|
|
from ldapcherry.exceptions import MissingParameter
|
|
|
|
|
2015-07-10 21:06:28 +02:00
|
|
|
|
2015-04-15 21:13:14 +02:00
|
|
|
class Backend:
|
|
|
|
|
2015-06-17 19:48:57 +02:00
|
|
|
def __init__(self, config, logger, name, attrslist, key):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Initialize the backend
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param config: the configuration of the backend
|
|
|
|
:type config: dict {'config key': 'value'}
|
|
|
|
:param logger: the cherrypy error logger object
|
|
|
|
:type logger: python logger
|
|
|
|
:param name: id of the backend
|
|
|
|
:type name: string
|
|
|
|
:param attrslist: list of the backend attributes
|
|
|
|
:type attrslist: list of strings
|
|
|
|
:param key: the key attribute
|
|
|
|
:type key: string
|
|
|
|
"""
|
2015-06-17 19:57:41 +02:00
|
|
|
raise Exception()
|
2015-04-15 21:13:14 +02:00
|
|
|
|
2015-06-06 22:23:21 +02:00
|
|
|
def auth(self, username, password):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Check authentication against the backend
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:param password: password of the user
|
|
|
|
:type password: string
|
|
|
|
:rtype: boolean (True is authentication success, False otherwise)
|
|
|
|
"""
|
2015-05-28 09:44:21 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def add_user(self, attrs):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Add a user to the backend
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param attrs: attributes of the user
|
|
|
|
:type attrs: dict ({<attr>: <value>})
|
2015-07-21 00:53:07 +02:00
|
|
|
|
|
|
|
.. warning:: raise UserAlreadyExists if user already exists
|
2015-07-21 00:29:37 +02:00
|
|
|
"""
|
2015-05-28 09:44:21 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def del_user(self, username):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Delete a user from the backend
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
"""
|
2015-05-20 17:13:18 +02:00
|
|
|
pass
|
|
|
|
|
2015-06-17 19:48:57 +02:00
|
|
|
def set_attrs(self, username, attrs):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Set a list of attributes for a given user
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:param attrs: attributes of the user
|
|
|
|
:type attrs: dict ({<attr>: <value>})
|
|
|
|
"""
|
2015-04-15 21:13:14 +02:00
|
|
|
pass
|
|
|
|
|
2015-06-17 19:48:57 +02:00
|
|
|
def add_to_groups(self, username, groups):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Add a user to a list of groups
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:param groups: list of groups
|
|
|
|
:type groups: list of strings
|
|
|
|
"""
|
2015-04-15 21:13:14 +02:00
|
|
|
pass
|
|
|
|
|
2015-06-17 19:48:57 +02:00
|
|
|
def del_from_groups(self, username, groups):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Delete a user from a list of groups
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:param groups: list of groups
|
|
|
|
:type groups: list of strings
|
2015-07-21 00:53:07 +02:00
|
|
|
|
|
|
|
.. warning:: raise GroupDoesntExist if group doesn't exist
|
2015-07-21 00:29:37 +02:00
|
|
|
"""
|
2015-04-15 21:13:14 +02:00
|
|
|
pass
|
2015-05-21 19:54:38 +02:00
|
|
|
|
2015-05-28 09:44:21 +02:00
|
|
|
def search(self, searchstring):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Search backend for users
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param searchstring: the search string
|
|
|
|
:type searchstring: string
|
|
|
|
:rtype: dict of dict ( {<user attr key>: {<attr>: <value>}} )
|
|
|
|
"""
|
2015-06-17 19:48:57 +02:00
|
|
|
return {}
|
2015-05-28 09:44:21 +02:00
|
|
|
|
|
|
|
def get_user(self, username):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Get a user's attributes
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:rtype: dict ( {<attr>: <value>} )
|
2015-07-21 00:53:07 +02:00
|
|
|
|
|
|
|
.. warning:: raise UserDoesntExist if user doesn't exist
|
2015-07-21 00:29:37 +02:00
|
|
|
"""
|
2015-06-17 19:48:57 +02:00
|
|
|
return {}
|
2015-05-28 09:44:21 +02:00
|
|
|
|
|
|
|
def get_groups(self, username):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Get a user's groups
|
2015-07-21 00:53:07 +02:00
|
|
|
|
2015-07-21 00:29:37 +02:00
|
|
|
:param username: 'key' attribute of the user
|
|
|
|
:type username: string
|
|
|
|
:rtype: list of groups
|
|
|
|
"""
|
2015-05-28 09:44:21 +02:00
|
|
|
return []
|
|
|
|
|
2015-05-21 21:40:13 +02:00
|
|
|
def get_param(self, param, default=None):
|
2015-07-21 00:29:37 +02:00
|
|
|
""" Get a parameter in config (handle default value)
|
|
|
|
|
|
|
|
:param param: name of the parameter to recover
|
|
|
|
:type param: string
|
|
|
|
:param default: the default value, raises an exception
|
|
|
|
if param is not in configuration and default
|
|
|
|
is None (which is the default value).
|
|
|
|
:type default: string or None
|
|
|
|
:rtype: the value of the parameter or the default value if
|
|
|
|
not set in configuration
|
|
|
|
"""
|
2015-05-21 19:54:38 +02:00
|
|
|
if param in self.config:
|
|
|
|
return self.config[param]
|
2015-07-11 22:05:33 +02:00
|
|
|
elif default is not None:
|
2015-05-21 19:54:38 +02:00
|
|
|
return default
|
2015-06-06 22:23:21 +02:00
|
|
|
else:
|
2015-07-10 21:06:28 +02:00
|
|
|
raise MissingParameter('backends', self.backend_name + '.' + param)
|