parent
dae29ac175
commit
9f57379f16
@ -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() |
|
Loading…
Reference in new issue