當前位置: 首頁>>代碼示例>>Python>>正文


Python FreeNAS_LDAP.validate_credentials方法代碼示例

本文整理匯總了Python中freenasUI.common.freenasldap.FreeNAS_LDAP.validate_credentials方法的典型用法代碼示例。如果您正苦於以下問題:Python FreeNAS_LDAP.validate_credentials方法的具體用法?Python FreeNAS_LDAP.validate_credentials怎麽用?Python FreeNAS_LDAP.validate_credentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freenasUI.common.freenasldap.FreeNAS_LDAP的用法示例。


在下文中一共展示了FreeNAS_LDAP.validate_credentials方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: clean_ldap_bindpw

# 需要導入模塊: from freenasUI.common.freenasldap import FreeNAS_LDAP [as 別名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_LDAP import validate_credentials [as 別名]
    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,代碼行數:58,代碼來源:forms.py

示例2: clean_bindpw

# 需要導入模塊: from freenasUI.common.freenasldap import FreeNAS_LDAP [as 別名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_LDAP import validate_credentials [as 別名]
    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,代碼行數:29,代碼來源:forms.py

示例3: clean_ldap_bindpw

# 需要導入模塊: from freenasUI.common.freenasldap import FreeNAS_LDAP [as 別名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_LDAP import validate_credentials [as 別名]
    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,代碼行數:36,代碼來源:forms.py

示例4: clean_bindpw

# 需要導入模塊: from freenasUI.common.freenasldap import FreeNAS_LDAP [as 別名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_LDAP import validate_credentials [as 別名]
    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,代碼行數:17,代碼來源:forms.py

示例5: clean

# 需要導入模塊: from freenasUI.common.freenasldap import FreeNAS_LDAP [as 別名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_LDAP import validate_credentials [as 別名]
    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,代碼行數:64,代碼來源:forms.py


注:本文中的freenasUI.common.freenasldap.FreeNAS_LDAP.validate_credentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。