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


Python FreeNAS_ActiveDirectory.validate_credentials方法代码示例

本文整理汇总了Python中freenasUI.common.freenasldap.FreeNAS_ActiveDirectory.validate_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python FreeNAS_ActiveDirectory.validate_credentials方法的具体用法?Python FreeNAS_ActiveDirectory.validate_credentials怎么用?Python FreeNAS_ActiveDirectory.validate_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freenasUI.common.freenasldap.FreeNAS_ActiveDirectory的用法示例。


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

示例1: clean

# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import validate_credentials [as 别名]
    def clean(self):
        cdata = self.cleaned_data
        domain = cdata.get("ad_domainname")
        bindname = cdata.get("ad_bindname")
        bindpw = cdata.get("ad_bindpw")
        site = cdata.get("ad_site")
        netbiosname = cdata.get("ad_netbiosname")
        netbiosname_b = cdata.get("ad_netbiosname_b")
        ssl = cdata.get("ad_ssl")
        certificate = cdata["ad_certificate"]
        ad_kerberos_principal = cdata["ad_kerberos_principal"]
        workgroup = None

        if certificate:
            certificate = certificate.get_certificate_path()

        args = {
            'domain': domain,
            'site': site,
            'ssl': ssl,
            'certfile': certificate
        }

        if not ad_kerberos_principal:
            if not cdata.get("ad_bindpw"):
                cdata['ad_bindpw'] = self.instance.ad_bindpw

            if not bindname:
                raise forms.ValidationError("No domain account name specified")
            if not bindpw:
                raise forms.ValidationError(
                    "No domain account password specified")

            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            try:
                ret = FreeNAS_ActiveDirectory.validate_credentials(
                    domain,
                    site=site,
                    ssl=ssl,
                    certfile=certificate,
                    binddn=binddn,
                    bindpw=bindpw,
                    errors=errors)
                if ret is False:
                    raise forms.ValidationError("%s." % errors[0])
            except FreeNAS_ActiveDirectory_Exception, e:
                raise forms.ValidationError('%s.' % e)

            args['binddn'] = binddn
            args['bindpw'] = bindpw
开发者ID:vanloswang,项目名称:freenas,代码行数:54,代码来源:forms.py

示例2: clean

# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import validate_credentials [as 别名]
    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if self.instance.ad_use_keytab is False:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            ret = FreeNAS_ActiveDirectory.validate_credentials(
                domain, binddn=binddn, bindpw=bindpw, errors=errors
            )
            if ret is False:
                raise forms.ValidationError("%s." % errors[0])

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

示例3: clean

# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import validate_credentials [as 别名]
    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if self.instance.ad_use_keytab == False:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)

            ret = FreeNAS_ActiveDirectory.validate_credentials(
                domain, binddn=binddn, bindpw=bindpw
            )
            if ret == False:
                raise forms.ValidationError(
                    _("Incorrect password.")
                )

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

示例4: clean

# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import validate_credentials [as 别名]
    def clean(self):
        cdata = self.cleaned_data
        if not cdata.get("ad_bindpw"):
            cdata['ad_bindpw'] = self.instance.ad_bindpw

        if not self.instance.ad_kerberos_keytab:
            bindname = cdata.get("ad_bindname")
            bindpw = cdata.get("ad_bindpw")
            domain = cdata.get("ad_domainname")
            binddn = "%[email protected]%s" % (bindname, domain)
            errors = []

            try:
                ret = FreeNAS_ActiveDirectory.validate_credentials(
                    domain, binddn=binddn, bindpw=bindpw, errors=errors
                )
                if ret is False:
                    raise forms.ValidationError("%s." % errors[0])
            except FreeNAS_ActiveDirectory_Exception, e:
                raise forms.ValidationError('%s.' % e)
开发者ID:anilh889,项目名称:freenas,代码行数:22,代码来源:forms.py

示例5: clean

# 需要导入模块: from freenasUI.common.freenasldap import FreeNAS_ActiveDirectory [as 别名]
# 或者: from freenasUI.common.freenasldap.FreeNAS_ActiveDirectory import validate_credentials [as 别名]
    def clean(self):
        cdata = self.cleaned_data
        domain = cdata.get("ad_domainname")
        bindname = cdata.get("ad_bindname")
        binddn = "%[email protected]%s" % (bindname, domain)
        bindpw = cdata.get("ad_bindpw")
        site = cdata.get("ad_site")
        netbiosname = cdata.get("ad_netbiosname_a")
        netbiosname_b = cdata.get("ad_netbiosname_b")
        ssl = cdata.get("ad_ssl")
        certificate = cdata["ad_certificate"]
        ad_kerberos_principal = cdata["ad_kerberos_principal"]
        workgroup = None

        if certificate:
            certificate = certificate.get_certificate_path()

        args = {
            'domain': domain,
            'site': site,
            'ssl': ssl,
            'certfile': certificate
        }

        if not cdata.get("ad_bindpw"):
            bindpw = self.instance.ad_bindpw
            cdata['ad_bindpw'] = bindpw

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

        if not ad_kerberos_principal:
            if not bindname:
                raise forms.ValidationError("No domain account name specified")
            if not bindpw:
                raise forms.ValidationError("No domain account password specified")

            try:
                FreeNAS_ActiveDirectory.validate_credentials(
                    domain,
                    site=site,
                    ssl=ssl,
                    certfile=certificate,
                    binddn=binddn,
                    bindpw=bindpw
                )
            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)))

            args['binddn'] = binddn
            args['bindpw'] = bindpw

        else:
            args['keytab_principal'] = ad_kerberos_principal.principal_name
            args['keytab_file'] = '/etc/krb5.keytab'

        try:
            workgroup = FreeNAS_ActiveDirectory.get_workgroup_name(**args)
        except Exception as e:
            raise forms.ValidationError(e)

        if workgroup:
            if compare_netbios_names(netbiosname, workgroup, None):
                raise forms.ValidationError(_(
                    "The NetBIOS name cannot be the same as the workgroup name!"
                ))
            if netbiosname_b:
                if compare_netbios_names(netbiosname_b, workgroup, None):
                    raise forms.ValidationError(_(
                        "The NetBIOS name cannot be the same as the workgroup "
                        "name!"
                    ))

        else:
            log.warn("Unable to determine workgroup name")

        if ssl in ("off", None):
            return cdata

        if not certificate:
            raise forms.ValidationError(
                "SSL/TLS specified without certificate")

#.........这里部分代码省略.........
开发者ID:GitVendor,项目名称:freenas,代码行数:103,代码来源:forms.py


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