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


Python auth.get_backends方法代码示例

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


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

示例1: _authorized_approvals

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def _authorized_approvals(self, as_user):
        group_q = Q()
        for g in as_user.groups.all():
            group_q = group_q | Q(groups__in=[g])

        permissions = []
        for backend in auth.get_backends():
            permissions.extend(backend.get_all_permissions(as_user))

        permission_q = Q()
        for p in permissions:
            label, codename = p.split('.')
            permission_q = permission_q | Q(permissions__content_type__app_label=label,
                                            permissions__codename=codename)

        return TransitionApproval.objects.filter(
            Q(workflow=self.workflow, status=PENDING) &
            (
                    (Q(transactioner__isnull=True) | Q(transactioner=as_user)) &
                    (Q(permissions__isnull=True) | permission_q) &
                    (Q(groups__isnull=True) | group_q)
            )
        ) 
开发者ID:javrasya,项目名称:django-river,代码行数:25,代码来源:orm_driver.py

示例2: query_ldap

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def query_ldap(email: str) -> List[str]:
    values = []
    backend = next((backend for backend in get_backends() if isinstance(backend, LDAPBackend)), None)
    if backend is not None:
        try:
            ldap_username = backend.django_to_ldap_username(email)
        except ZulipLDAPExceptionNoMatchingLDAPUser as e:
            values.append(f"No such user found: {e}")
            return values

        ldap_attrs = _LDAPUser(backend, ldap_username).attrs

        for django_field, ldap_field in settings.AUTH_LDAP_USER_ATTR_MAP.items():
            value = ldap_attrs.get(ldap_field, ["LDAP field not present"])[0]
            if django_field == "avatar":
                if isinstance(value, bytes):
                    value = "(An avatar image file)"
            values.append(f"{django_field}: {value}")
        if settings.LDAP_EMAIL_ATTR is not None:
            values.append("{}: {}".format('email', ldap_attrs[settings.LDAP_EMAIL_ATTR][0]))
    else:
        values.append("LDAP backend not configured on this server.")
    return values 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:backends.py

示例3: has_module_perms

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def has_module_perms(self, app_label):
        """
        Returns True if the user has any permissions in the given app label.
        Uses pretty much the same logic as has_perm, above.
        """
        if self.is_active and self.is_superuser:
            return True

        for backend in auth.get_backends():
            if not hasattr(backend, 'has_module_perms'):
                continue
            try:
                if backend.has_module_perms(self, app_label):
                    return True
            except PermissionDenied:
                return False
        return False 
开发者ID:grey0ne,项目名称:django-protector,代码行数:19,代码来源:models.py

示例4: has_perm

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def has_perm(self, perm, obj=None):
        """
        Logic from django.contrib.auth.models._user_has_perm
        :param perm:
        :param obj:
        :return:
        """
        for backend in auth.get_backends():
            if not hasattr(backend, 'has_perm') \
                    or backend.__module__.startswith('django.contrib.auth'):
                continue
            try:
                if backend.has_perm(self, perm, obj):
                    return True
            except PermissionDenied:
                return False
        return False 
开发者ID:Peter-Slump,项目名称:django-keycloak,代码行数:19,代码来源:remote_user.py

示例5: _user_get_all_permissions

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def _user_get_all_permissions(user, obj):
    permissions = set()
    for backend in auth.get_backends():
        if hasattr(backend, "get_all_permissions"):
            permissions.update(backend.get_all_permissions(user, obj))
    return permissions 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:models.py

示例6: _user_has_perm

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def _user_has_perm(user, perm, obj):
    """
    A backend can raise `PermissionDenied` to short-circuit permission checking.
    """
    for backend in auth.get_backends():
        if not hasattr(backend, 'has_perm'):
            continue
        try:
            if backend.has_perm(user, perm, obj):
                return True
        except PermissionDenied:
            return False
    return False 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:15,代码来源:models.py

示例7: _user_has_module_perms

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def _user_has_module_perms(user, app_label):
    """
    A backend can raise `PermissionDenied` to short-circuit permission checking.
    """
    for backend in auth.get_backends():
        if not hasattr(backend, 'has_module_perms'):
            continue
        try:
            if backend.has_module_perms(user, app_label):
                return True
        except PermissionDenied:
            return False
    return False 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:15,代码来源:models.py

示例8: get_group_permissions

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def get_group_permissions(self, obj=None):
        """
        Returns a list of permission strings that this user has through their
        groups. This method queries all available auth backends. If an object
        is passed in, only permissions matching this object are returned.
        """
        permissions = set()
        for backend in auth.get_backends():
            if hasattr(backend, "get_group_permissions"):
                permissions.update(backend.get_group_permissions(self, obj))
        return permissions 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:models.py

示例9: get_backend

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def get_backend():
    backends = get_backends()
    return backends[0] 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:5,代码来源:tests.py

示例10: get_group_permissions

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def get_group_permissions(self, obj=None):
        """
        Return a list of permission strings that this user has through their
        groups. Query all available auth backends. If an object is passed in,
        return only permissions matching this object.
        """
        permissions = set()
        for backend in auth.get_backends():
            if hasattr(backend, "get_group_permissions"):
                permissions.update(backend.get_group_permissions(self, obj))
        return permissions 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:models.py

示例11: is_supervisor_of

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def is_supervisor_of(user_or_profile, profile_or_countries):
    user = _convert_profile_to_user(user_or_profile)
    if auth_log.getEffectiveLevel() == logging.DEBUG:
        auth_log.debug(
            "* checking if object is supervised... [ %s %s] [ %s ]",
            user, "<~ '%s' " % user_or_profile if user != user_or_profile else "",
            repr(profile_or_countries))
    if isinstance(profile_or_countries, int):
        try:
            profile_or_countries = Profile.objects.get(pk=profile_or_countries)
        except Profile.DoesNotExist:
            return False
    elif isinstance(profile_or_countries, str):
        profile_or_countries = profile_or_countries.split(" ")

    # supervisor = False
    # for backend in auth.get_backends():
    #     try:
    #         supervisor = backend.is_user_supervisor_of(user, profile_or_countries)
    #     except AttributeError as e:
    #         pass
    #     except:
    #         supervisor = False
    #     else:
    #         break
    # return supervisor
    return user.has_perm(PERM_SUPERVISOR, profile_or_countries) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:29,代码来源:profile.py

示例12: supervisor_of

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def supervisor_of(user_or_profile):
    user = _convert_profile_to_user(user_or_profile)
    if auth_log.getEffectiveLevel() == logging.DEBUG:
        auth_log.debug(
            "* searching supervised objects... [ %s %s]",
            user, "<~ '%s' " % user_or_profile if user != user_or_profile else "")
    for backend in auth.get_backends():
        try:
            return sorted(backend.get_user_supervisor_of(user))
        except Exception:
            pass
    return ("",) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:14,代码来源:profile.py

示例13: get_oidc_backend

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def get_oidc_backend():
    """
    Get the Django auth backend that uses OIDC.
    """

    # allow the user to force which back backend to use. this is mostly
    # convenient if you want to use OIDC with DRF but don't want to configure
    # OIDC for the "normal" Django auth.
    backend_setting = import_from_settings('OIDC_DRF_AUTH_BACKEND', None)
    if backend_setting:
        backend = import_string(backend_setting)()
        if not isinstance(backend, OIDCAuthenticationBackend):
            msg = 'Class configured in OIDC_DRF_AUTH_BACKEND ' \
                  'does not extend OIDCAuthenticationBackend!'
            raise ImproperlyConfigured(msg)
        return backend

    # if the backend setting is not set, look through the list of configured
    # backends for one that is an OIDCAuthenticationBackend.
    backends = [b for b in get_backends() if isinstance(b, OIDCAuthenticationBackend)]

    if not backends:
        msg = 'No backends extending OIDCAuthenticationBackend found - ' \
              'add one to AUTHENTICATION_BACKENDS or set OIDC_DRF_AUTH_BACKEND!'
        raise ImproperlyConfigured(msg)
    if len(backends) > 1:
        raise ImproperlyConfigured('More than one OIDCAuthenticationBackend found!')
    return backends[0] 
开发者ID:mozilla,项目名称:mozilla-django-oidc,代码行数:30,代码来源:drf.py

示例14: has_perm

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def has_perm(self, perm, obj=None):
        if self.is_active and self.is_superuser:
            return True

        for backend in auth.get_backends():
            if not hasattr(backend, 'has_perm'):
                continue
            try:
                if backend.has_perm(self, perm, obj):
                    return True
            except PermissionDenied:
                return False
        return False 
开发者ID:grey0ne,项目名称:django-protector,代码行数:15,代码来源:models.py

示例15: get_all_permissions

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_backends [as 别名]
def get_all_permissions(self, obj=None):
        """
        Logic from django.contrib.auth.models._user_get_all_permissions
        :param perm:
        :param obj:
        :return:
        """
        permissions = set()
        for backend in auth.get_backends():
            # Excluding Django.contrib.auth backends since they are not
            # compatible with non-db-backed permissions.
            if hasattr(backend, "get_all_permissions") \
                    and not backend.__module__.startswith('django.'):
                permissions.update(backend.get_all_permissions(self, obj))
        return permissions 
开发者ID:Peter-Slump,项目名称:django-keycloak,代码行数:17,代码来源:remote_user.py


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