This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2019-10-07 14:33:48 +00:00
|
|
|
"""sso models"""
|
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
|
|
from passbook.core.models import Policy
|
|
|
|
from passbook.policies.struct import PolicyRequest, PolicyResult
|
|
|
|
|
|
|
|
|
|
|
|
class SSOLoginPolicy(Policy):
|
|
|
|
"""Policy that applies to users that have authenticated themselves through SSO"""
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
form = "passbook.policies.sso.forms.SSOLoginPolicyForm"
|
2019-10-07 14:33:48 +00:00
|
|
|
|
|
|
|
def passes(self, request: PolicyRequest) -> PolicyResult:
|
|
|
|
"""Check if user instance passes this policy"""
|
|
|
|
from passbook.factors.view import AuthenticationView
|
2019-12-31 11:51:16 +00:00
|
|
|
|
|
|
|
is_sso_login = request.user.session.get(
|
|
|
|
AuthenticationView.SESSION_IS_SSO_LOGIN, False
|
|
|
|
)
|
2019-10-07 14:33:48 +00:00
|
|
|
return PolicyResult(is_sso_login)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
2019-12-31 11:51:16 +00:00
|
|
|
verbose_name = _("SSO Login Policy")
|
|
|
|
verbose_name_plural = _("SSO Login Policies")
|