当前位置: 首页>>代码示例>>Python>>正文


Python freenasldap.FreeNAS_LDAP类代码示例

本文整理汇总了Python中freenasUI.common.freenasldap.FreeNAS_LDAP的典型用法代码示例。如果您正苦于以下问题:Python FreeNAS_LDAP类的具体用法?Python FreeNAS_LDAP怎么用?Python FreeNAS_LDAP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FreeNAS_LDAP类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LDAP

class LDAP(TestObject):
    def __init__(self, handler=None):
        super(self.__class__, self).__init__(handler)
        self._name = "LDAP"
        self.freenas_ldap = FreeNAS_LDAP(flags=FLAGS_DBINIT)

    def Enabled(self):
        return ldap_enabled()

    def Test(self):
        try:
            self.freenas_ldap.open()

            if self.freenas_ldap._handle.whoami_s():
                return self._handler.Pass("LDAP")
            else:
                return self._handler.Fail("LDAP", "Unable to query the server.")
        except LDAPError as e:
            # LDAPError is dumb, it returns a list with one element for goodness knows what reason
            e = e[0]
            error = "" 
            if 'desc' in e:
                error = e['desc']
                if 'info' in e:
                    error = "{0}, {1}".format(error, e['info'])
            else:
                # LDAPError may have desc and info or just info so making a case that handles just info
                if 'info' in e:
                    error = e['info']
                else:
                    error = str(e)
            return self._handler.Fail("LDAP", error)
        except Exception as e:
            return self._handler.Fail("LDAP", str(e))
开发者ID:toastcomputer,项目名称:freenas,代码行数:34,代码来源:LDAP.py

示例2: check_for_samba_schema

    def check_for_samba_schema(self):
        self.clean_bindpw()

        cdata = self.cleaned_data
        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        basedn = cdata.get("ldap_basedn")
        hostname = cdata.get("ldap_hostname")

        certfile = None
        ssl = cdata.get("ldap_ssl")
        if ssl in ('start_tls', 'on'):
            certificate = cdata["ldap_certificate"]
            certfile = get_certificateauthority_path(certificate)

        fl = FreeNAS_LDAP(
            host=hostname,
            binddn=binddn,
            bindpw=bindpw,
            basedn=basedn,
            certfile=certfile,
            ssl=ssl)

        if fl.has_samba_schema():
            self.instance.ldap_has_samba_schema = True
        else:
            self.instance.ldap_has_samba_schema = False
开发者ID:vanloswang,项目名称:freenas,代码行数:27,代码来源:forms.py

示例3: clean_ldap_bindpw

    def clean_ldap_bindpw(self):
        cdata = self.cleaned_data
        if not cdata.get("ldap_bindpw"):
            cdata["ldap_bindpw"] = self.instance.ldap_bindpw

        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        basedn = cdata.get("ldap_basedn")
        hostname = cdata.get("ldap_hostname")
        ssl = cdata.get("ldap_ssl")
        port = 389
        if ssl == "on":
            port = 636
        if hostname:
            parts = hostname.split(':')
            hostname = parts[0]
            if len(parts) > 1:
                port = int(parts[1])

        certfile = None

        if ssl in ('start_tls', 'on'):
            certificate = cdata["ldap_certificate"]
            certfile = get_certificateauthority_path(certificate)

        try:
            FreeNAS_LDAP.validate_credentials(
                hostname,
                binddn=binddn,
                bindpw=bindpw,
                basedn=basedn,
                port=port,
                certfile=certfile,
                ssl=ssl
            )
        except LDAPError as e:
            # LDAPError is dumb, it returns a list with one element for goodness knows what reason
            e = e[0]
            error = []
            desc = e.get('desc')
            info = e.get('info')
            if desc:
                error.append(desc)
            if info:
                error.append(info)

            if error:
                error = ', '.join(error)
            else:
                error = str(e)

            raise forms.ValidationError("{0}".format(error))
        except Exception as e:
            raise forms.ValidationError("{0}".format(str(e)))

        return bindpw
开发者ID:josonchen,项目名称:freenas,代码行数:56,代码来源:forms.py

示例4: clean_bindpw

    def clean_bindpw(self):
        cdata = self.cleaned_data
        if not cdata.get("ldap_bindpw"):
            cdata["ldap_bindpw"] = self.instance.ldap_bindpw

        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        basedn = cdata.get("ldap_basedn")
        hostname = cdata.get("ldap_hostname")
        errors = []

        certfile = None
        ssl = cdata.get("ldap_ssl")
        if ssl in ('start_tls', 'on'):
            certificate = cdata["ldap_certificate"]
            certfile = get_certificateauthority_path(certificate)

        ret = FreeNAS_LDAP.validate_credentials(
            hostname,
            binddn=binddn,
            bindpw=bindpw,
            basedn=basedn,
            certfile=certfile,
            ssl=ssl,
            errors=errors)
        if ret is False:
            raise forms.ValidationError("%s." % errors[0])
开发者ID:vanloswang,项目名称:freenas,代码行数:27,代码来源:forms.py

示例5: clean_ldap_bindpw

    def clean_ldap_bindpw(self):
        cdata = self.cleaned_data
        if not cdata.get("ldap_bindpw"):
            cdata["ldap_bindpw"] = self.instance.ldap_bindpw

        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        basedn = cdata.get("ldap_basedn")
        hostname = cdata.get("ldap_hostname")
        ssl = cdata.get("ldap_ssl")
        port = 389
        if ssl == "on":
            port = 636
        if hostname:
            parts = hostname.split(':')
            hostname = parts[0]
            if len(parts) > 1:
                port = int(parts[1]) 
        errors = []

        certfile = None

        if ssl in ('start_tls', 'on'):
            certificate = cdata["ldap_certificate"]
            certfile = get_certificateauthority_path(certificate)

        ret = FreeNAS_LDAP.validate_credentials(
            hostname, binddn=binddn, bindpw=bindpw, basedn=basedn,
            port=port, certfile=certfile, ssl=ssl, errors=errors
        )
        if ret is False:
            raise forms.ValidationError("%s." % errors[0])

        return bindpw
开发者ID:Cbrdiv,项目名称:freenas,代码行数:34,代码来源:forms.py

示例6: LDAP

class LDAP(TestObject):
    def __init__(self, handler=None):
        super(self.__class__, self).__init__(handler)
        self._name = "LDAP"
        self.freenas_ldap = FreeNAS_LDAP(flags=FLAGS_DBINIT)

    def Enabled(self):
        return ldap_enabled()

    def Test(self):
        try:
            self.freenas_ldap.open()

            if self.freenas_ldap._handle.whoami_s():
                return self._handler.Pass("LDAP")
            else:
                return self._handler.Fail("LDAP", "Unable to query the server.")
        except Exception as e:
            return self._handler.Fail("LDAP", str(e))
开发者ID:elovelan,项目名称:freenas,代码行数:19,代码来源:LDAP.py

示例7: clean_bindpw

    def clean_bindpw(self):
        cdata = self.cleaned_data
        if not cdata.get("ldap_bindpw"):
            cdata["ldap_bindpw"] = self.instance.ldap_bindpw

        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        hostname = cdata.get("ldap_hostname")
        errors = []

        ret = FreeNAS_LDAP.validate_credentials(
            hostname, binddn=binddn, bindpw=bindpw, errors=errors
        )
        if ret is False:
            raise forms.ValidationError("%s." % errors[0])
开发者ID:dlrik,项目名称:freenas,代码行数:15,代码来源:forms.py

示例8: LDAP

class LDAP(TestObject):
    def __init__(self, handler=None):
        super(self.__class__, self).__init__(handler)
        self._name = "LDAP"
        self.freenas_ldap = FreeNAS_LDAP(flags=FLAGS_DBINIT)

    def Enabled(self):
        return ldap_enabled()

    def Test(self):
        try:
            self.freenas_ldap.open()

            if self.freenas_ldap._handle.whoami_s():
                return self._handler.Pass("LDAP")
            else:
                return self._handler.Fail("LDAP", "Unable to query the server.")
        except LDAPError as e:
            # LDAPError is dumb, it returns a list with one element for goodness knows what reason
            e = e[0]
            error = []
            desc = e.get('desc')
            info = e.get('info')
            if desc:
                error.append(desc)
            if info:
                error.append(info)

            if error:
                error = ', '.join(error)
            else:
                error = str(e)

            return self._handler.Fail("LDAP", error)
        except Exception as e:
            return self._handler.Fail("LDAP", str(e))
开发者ID:GitVendor,项目名称:freenas,代码行数:36,代码来源:LDAP.py

示例9: ldap_status

    def ldap_status(self):
        ret = False
        try:
            f = FreeNAS_LDAP(flags=FLAGS_DBINIT)
            f.open()
            if f.isOpen():
                ret = True
            f.close()
        except:
            pass

        return ret
开发者ID:binzyw,项目名称:freenas,代码行数:12,代码来源:notifier.py

示例10: __init__

 def __init__(self, handler=None):
     super(self.__class__, self).__init__(handler)
     self._name = "LDAP"
     self.freenas_ldap = FreeNAS_LDAP(flags=FLAGS_DBINIT)
开发者ID:elovelan,项目名称:freenas,代码行数:4,代码来源:LDAP.py

示例11: clean

    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ldap_bindpw"):
            cdata["ldap_bindpw"] = self.instance.ldap_bindpw

        binddn = cdata.get("ldap_binddn")
        bindpw = cdata.get("ldap_bindpw")
        basedn = cdata.get("ldap_basedn")
        hostname = cdata.get("ldap_hostname")
        ssl = cdata.get("ldap_ssl")

        certfile = None
        if ssl in ('start_tls', 'on'):
            certificate = cdata["ldap_certificate"]
            if not certificate:
                raise forms.ValidationError(
                    "SSL/TLS specified without certificate")
            else:
                certfile = get_certificateauthority_path(certificate)

        port = 389
        if ssl == "on":
            port = 636
        if hostname:
            parts = hostname.split(':')
            hostname = parts[0]
            if len(parts) > 1:
                port = int(parts[1])

        if cdata.get("ldap_enable") is False:
            return cdata

        # self.check_for_samba_schema()
        try:
            FreeNAS_LDAP.validate_credentials(
                hostname,
                binddn=binddn,
                bindpw=bindpw,
                basedn=basedn,
                port=port,
                certfile=certfile,
                ssl=ssl
            )
        except LDAPError as e:
            log.debug("LDAPError: type = %s", type(e))

            error = []
            try:
                error.append(e.args[0]['info'])
                error.append(e.args[0]['desc'])
                error = ', '.join(error)

            except:
                error = str(e)

            raise forms.ValidationError("{0}".format(error))

        except Exception as e:
            log.debug("LDAPError: type = %s", type(e))
            raise forms.ValidationError("{0}".format(str(e)))

        return cdata
开发者ID:binzyw,项目名称:freenas,代码行数:62,代码来源:forms.py


注:本文中的freenasUI.common.freenasldap.FreeNAS_LDAP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。