Initial commit
This commit is contained in:
parent
dae29ac175
commit
9f57379f16
52
octoprint_auth_ldap/__init__.py
Normal file
52
octoprint_auth_ldap/__init__.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
# coding=utf-8
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from octoprint.users import FilebasedUserManager
|
||||||
|
from octoprint.settings import settings
|
||||||
|
import ldap
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
class LDAPUserManager(FilebasedUserManager):
|
||||||
|
def checkPassword(self, username, password):
|
||||||
|
ldap_server = settings().get(["accessControl", "ldap_uri"])
|
||||||
|
ldap_search_base = settings().get(["accessControl", "ldap_search_base"])
|
||||||
|
if ldap_server is None or ldap_search_base is None:
|
||||||
|
self._logger.debug("LDAP conf error")
|
||||||
|
return False
|
||||||
|
dn = "uid=" + username + ",ou=users," + ldap_search_base
|
||||||
|
try:
|
||||||
|
connection = ldap.initialize(ldap_server)
|
||||||
|
connection.start_tls_s()
|
||||||
|
connection.bind_s(dn, password)
|
||||||
|
|
||||||
|
user = self.findUser(username)
|
||||||
|
if not user:
|
||||||
|
self.addUser(username, uuid.uuid4(), True)
|
||||||
|
return True
|
||||||
|
except ldap.INVALID_CREDENTIALS:
|
||||||
|
self._logger.debug("LDAP : Your username or password is incorrect.")
|
||||||
|
return FilebasedUserManager.checkPassword(self, username, password)
|
||||||
|
except ldap.LDAPError, e:
|
||||||
|
if type(e.message) == dict:
|
||||||
|
for (k, v) in e.message.iteritems():
|
||||||
|
self._logger.debug("%s: %sn" % (k, v))
|
||||||
|
else:
|
||||||
|
self._logger.debug(e.message)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def changeUserPassword(self, username, password):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def ldap_user_factory(components, settings, *args, **kwargs):
|
||||||
|
return LDAPUserManager();
|
||||||
|
|
||||||
|
__plugin_name__ = "Auth LDAP"
|
||||||
|
__plugin_version__ = "1.0.0"
|
||||||
|
__plugin_description__ = "LDAP authentication"
|
||||||
|
|
||||||
|
def __plugin_load__():
|
||||||
|
global __plugin_hooks__
|
||||||
|
__plugin_hooks__ = {
|
||||||
|
"octoprint.users.factory": ldap_user_factory
|
||||||
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
# coding=utf-8
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
### (Don't forget to remove me)
|
|
||||||
# This is a basic skeleton for your plugin's __init__.py. You probably want to adjust the class name of your plugin
|
|
||||||
# as well as the plugin mixins it's subclassing from. This is really just a basic skeleton to get you started.
|
|
||||||
|
|
||||||
import octoprint.plugin
|
|
||||||
|
|
||||||
class SkeletonPlugin(octoprint.plugin.TemplatePlugin):
|
|
||||||
# TODO Implement me!
|
|
||||||
pass
|
|
||||||
|
|
||||||
# If you want your plugin to be registered within OctoPrint under a different name than what you defined in setup.py
|
|
||||||
# ("OctoPrint-PluginSkeleton"), you may define that here. Same goes for the other metadata derived from setup.py that
|
|
||||||
# can be overwritten via __plugin_xyz__ control properties. See the documentation for that.
|
|
||||||
__plugin_name__ = "Plugin Skeleton"
|
|
||||||
__plugin_implementation__ = SkeletonPlugin()
|
|
10
setup.py
10
setup.py
|
@ -4,14 +4,14 @@
|
||||||
### Do not forget to adjust the following variables to your own plugin.
|
### Do not forget to adjust the following variables to your own plugin.
|
||||||
|
|
||||||
# The plugin's identifier, has to be unique
|
# The plugin's identifier, has to be unique
|
||||||
plugin_identifier = "skeleton"
|
plugin_identifier = "auth_ldap"
|
||||||
|
|
||||||
# The plugin's python package, should be "octoprint_<plugin identifier>", has to be unique
|
# The plugin's python package, should be "octoprint_<plugin identifier>", has to be unique
|
||||||
plugin_package = "octoprint_%s" % plugin_identifier
|
plugin_package = "octoprint_%s" % plugin_identifier
|
||||||
|
|
||||||
# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
|
# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
|
||||||
# plugin module
|
# plugin module
|
||||||
plugin_name = "OctoPrint-PluginSkeleton"
|
plugin_name = "OctoPrint-LDAP"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.1"
|
plugin_version = "0.1"
|
||||||
|
@ -21,10 +21,10 @@ plugin_version = "0.1"
|
||||||
plugin_description = "TODO"
|
plugin_description = "TODO"
|
||||||
|
|
||||||
# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
|
# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
|
||||||
plugin_author = "TODO"
|
plugin_author = "Guillaume GILL"
|
||||||
|
|
||||||
# The plugin's author's mail address.
|
# The plugin's author's mail address.
|
||||||
plugin_author_email = "todo@example.com"
|
plugin_author_email = "guillaume.gill@petitchinois.net"
|
||||||
|
|
||||||
# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
|
# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
|
||||||
plugin_url = "TODO"
|
plugin_url = "TODO"
|
||||||
|
@ -33,7 +33,7 @@ plugin_url = "TODO"
|
||||||
plugin_license = "AGPLv3"
|
plugin_license = "AGPLv3"
|
||||||
|
|
||||||
# Any additional requirements besides OctoPrint should be listed here
|
# Any additional requirements besides OctoPrint should be listed here
|
||||||
plugin_requires = []
|
plugin_requires = ["ldap","uuid"]
|
||||||
|
|
||||||
# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will
|
# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will
|
||||||
# already be installed automatically if they exist.
|
# already be installed automatically if they exist.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user