2022-06-07 11:26:07 +00:00
|
|
|
from django.db.models import TextChoices
|
|
|
|
|
2022-07-04 03:29:39 +00:00
|
|
|
from authentication.confirm import CONFIRM_BACKENDS
|
|
|
|
from .confirm import ConfirmMFA, ConfirmPassword, ConfirmReLogin
|
|
|
|
from .mfa import MFAOtp, MFASms, MFARadius
|
|
|
|
|
2020-08-12 07:54:06 +00:00
|
|
|
RSA_PRIVATE_KEY = 'rsa_private_key'
|
|
|
|
RSA_PUBLIC_KEY = 'rsa_public_key'
|
2022-06-07 11:26:07 +00:00
|
|
|
|
2022-07-04 03:29:39 +00:00
|
|
|
CONFIRM_BACKEND_MAP = {backend.name: backend for backend in CONFIRM_BACKENDS}
|
|
|
|
|
2022-06-07 11:26:07 +00:00
|
|
|
|
|
|
|
class ConfirmType(TextChoices):
|
2022-07-04 03:29:39 +00:00
|
|
|
ReLogin = ConfirmReLogin.name, ConfirmReLogin.display_name
|
|
|
|
PASSWORD = ConfirmPassword.name, ConfirmPassword.display_name
|
|
|
|
MFA = ConfirmMFA.name, ConfirmMFA.display_name
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_can_confirm_types(cls, confirm_type):
|
|
|
|
start = cls.values.index(confirm_type)
|
2022-07-07 09:07:57 +00:00
|
|
|
types = cls.values[start:]
|
|
|
|
types.reverse()
|
|
|
|
return types
|
2022-07-04 03:29:39 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_can_confirm_backend_classes(cls, confirm_type):
|
|
|
|
types = cls.get_can_confirm_types(confirm_type)
|
|
|
|
backend_classes = [
|
|
|
|
CONFIRM_BACKEND_MAP[tp] for tp in types if tp in CONFIRM_BACKEND_MAP
|
|
|
|
]
|
|
|
|
return backend_classes
|
|
|
|
|
|
|
|
|
|
|
|
class MFAType(TextChoices):
|
|
|
|
OTP = MFAOtp.name, MFAOtp.display_name
|
|
|
|
SMS = MFASms.name, MFASms.display_name
|
|
|
|
Radius = MFARadius.name, MFARadius.display_name
|