authentik.flows.exceptions

flow exceptions

 1"""flow exceptions"""
 2
 3from django.utils.translation import gettext_lazy as _
 4
 5from authentik.lib.sentry import SentryIgnoredException
 6from authentik.policies.types import PolicyResult
 7
 8
 9class FlowNonApplicableException(SentryIgnoredException):
10    """Flow does not apply to current user (denied by policy, or otherwise)."""
11
12    policy_result: PolicyResult | None = None
13
14    def __init__(self, policy_result: PolicyResult | None = None, *args):
15        super().__init__(*args)
16        self.policy_result = policy_result
17
18    @property
19    def messages(self) -> str:
20        """Get messages from policy result, fallback to generic reason"""
21        if not self.policy_result or len(self.policy_result.messages) < 1:
22            return _("Flow does not apply to current user.")
23        return "\n".join(self.policy_result.messages)
24
25
26class EmptyFlowException(SentryIgnoredException):
27    """Flow has no stages."""
28
29
30class FlowSkipStageException(SentryIgnoredException):
31    """Exception to skip a stage"""
32
33
34class StageInvalidException(SentryIgnoredException):
35    """Exception can be thrown in a `Challenge` or `ChallengeResponse` serializer's
36    validation to trigger a `executor.stage_invalid()` response"""
class FlowNonApplicableException(authentik.lib.sentry.SentryIgnoredException):
10class FlowNonApplicableException(SentryIgnoredException):
11    """Flow does not apply to current user (denied by policy, or otherwise)."""
12
13    policy_result: PolicyResult | None = None
14
15    def __init__(self, policy_result: PolicyResult | None = None, *args):
16        super().__init__(*args)
17        self.policy_result = policy_result
18
19    @property
20    def messages(self) -> str:
21        """Get messages from policy result, fallback to generic reason"""
22        if not self.policy_result or len(self.policy_result.messages) < 1:
23            return _("Flow does not apply to current user.")
24        return "\n".join(self.policy_result.messages)

Flow does not apply to current user (denied by policy, or otherwise).

FlowNonApplicableException( policy_result: authentik.policies.types.PolicyResult | None = None, *args)
15    def __init__(self, policy_result: PolicyResult | None = None, *args):
16        super().__init__(*args)
17        self.policy_result = policy_result
policy_result: authentik.policies.types.PolicyResult | None = None
messages: str
19    @property
20    def messages(self) -> str:
21        """Get messages from policy result, fallback to generic reason"""
22        if not self.policy_result or len(self.policy_result.messages) < 1:
23            return _("Flow does not apply to current user.")
24        return "\n".join(self.policy_result.messages)

Get messages from policy result, fallback to generic reason

class EmptyFlowException(authentik.lib.sentry.SentryIgnoredException):
27class EmptyFlowException(SentryIgnoredException):
28    """Flow has no stages."""

Flow has no stages.

class FlowSkipStageException(authentik.lib.sentry.SentryIgnoredException):
31class FlowSkipStageException(SentryIgnoredException):
32    """Exception to skip a stage"""

Exception to skip a stage

class StageInvalidException(authentik.lib.sentry.SentryIgnoredException):
35class StageInvalidException(SentryIgnoredException):
36    """Exception can be thrown in a `Challenge` or `ChallengeResponse` serializer's
37    validation to trigger a `executor.stage_invalid()` response"""

Exception can be thrown in a Challenge or ChallengeResponse serializer's validation to trigger a executor.stage_invalid() response